Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

WvFastString Class Reference

#include <wvstring.h>

Inherited by WvString.

Collaboration diagram for WvFastString:

[legend]
List of all members.

Detailed Description

A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to allocate any memory, thus making it faster.

When we copy to a normal WvString object, _then_ we allocate the memory. If that never happens, we never need to allocate.

DON'T CREATE INSTANCES OF THIS! It's mostly useful for parameter passing, and for that you should use WvStringParm. You can get yourself into _big_ trouble if you have an instance of a WvFastString created from a (char *) object and then you modify the original (char *).

For almost all purposes, use WvString instead. At worst, it's a bit slower.

Definition at line 85 of file wvstring.h.

Public Member Functions

 WvFastString ()
 Create an empty, NULL string.

void setsize (size_t i)
 WvFastString (const WvFastString &s)
 Copy constructor.

 WvFastString (const WvString &s)
 WvFastString (const char *_str)
 Create a string out of a (char *)-style string _without_ copying any memory.

 WvFastString (const QString &s)
 Create a string out of a Qt library QString.

 WvFastString (const QCString &s)
 WvFastString (short i)
 NOTE: make sure that 32 bytes is big enough for your longest int.

 WvFastString (unsigned short i)
 WvFastString (int i)
 WvFastString (unsigned int i)
 WvFastString (long i)
 WvFastString (unsigned long i)
 WvFastString (long long i)
 WvFastString (unsigned long long i)
 WvFastString (double i)
 WvFastString (WVSTRING_FORMAT_DECL)
 Now, you're probably thinking to yourself: Boy, does this ever look ridiculous.

 ~WvFastString ()
size_t len () const
bool operator== (WvStringParm s2) const
bool operator!= (WvStringParm s2) const
bool operator< (WvStringParm s2) const
bool operator== (const char *s2) const
bool operator!= (const char *s2) const
bool operator< (const char *s2) const
bool operator! () const
 the not operator is 'true' if string is empty

const char * operator+ (int i) const
const char * operator- (int i) const
 operator const char * () const
 auto-convert WvString to (const char *), when needed.

const char * cstr () const
 return a (const char *) for this string.

 operator QString () const
 return a Qt library QString containing the contents of this string.

int num () const
 used to convert WvString to int, when needed.

bool isnull () const
 returns true if this string is null


Static Public Member Functions

void do_format (WvFastString &output, const char *format, const WvFastString *const *a)
 when this is called, we assume output.str == NULL; it will be filled.


Static Public Attributes

const WvFastString null

Protected Member Functions

WvFastStringoperator= (const WvFastString &s2)
void link (WvStringBuf *_buf, const char *_str)
void unlink ()
WvStringBufalloc (size_t size)
void newbuf (size_t size)

Protected Attributes

WvStringBufbuf
char * str

Static Protected Attributes

WvStringBuf nullbuf = { 0, 1 }


Constructor & Destructor Documentation

WvFastString::WvFastString  ) 
 

Create an empty, NULL string.

In the past, these were dangerous and could only be filled with operator= or setsize(); nowadays, NULL strings are explicitly allowed, since it's useful to express the difference between a zero-length string and a NULL result.

Definition at line 33 of file wvstring.cc.

References link(), and nullbuf.

Referenced by WvString::operator=().

WvFastString::WvFastString const WvFastString s  ) 
 

Copy constructor.

We can safely copy from a normal WvString like this too, since no special behaviour is required in this direction. (Note that copying from a WvFastString to a WvString _does_ require special care!)

Definition at line 39 of file wvstring.cc.

References buf, link(), and str.

WvFastString::WvFastString const WvString s  ) 
 

Definition at line 45 of file wvstring.cc.

References buf, link(), and str.

WvFastString::WvFastString const char *  _str  ) 
 

Create a string out of a (char *)-style string _without_ copying any memory.

It's fast, but we have to trust that the _str won't change for the lifetime of our WvFastString. That's usually safe, if you didn't use WvFastString where you should have used a WvString.

Definition at line 51 of file wvstring.cc.

References str.

WvFastString::WvFastString const QString &  s  ) 
 

Create a string out of a Qt library QString.

If you use this, you need to link with libwvqt.so.

Definition at line 12 of file wvqtstring.cc.

References link(), nullbuf, and str.

WvFastString::WvFastString const QCString &  s  ) 
 

Definition at line 27 of file wvqtstring.cc.

References link(), nullbuf, and str.

WvFastString::WvFastString short  i  ) 
 

NOTE: make sure that 32 bytes is big enough for your longest int.

This is true up to at least 64 bits.

Definition at line 84 of file wvstring.cc.

References newbuf(), and str.

WvFastString::WvFastString unsigned short  i  ) 
 

Definition at line 91 of file wvstring.cc.

References newbuf(), and str.

WvFastString::WvFastString int  i  ) 
 

Definition at line 98 of file wvstring.cc.

References newbuf(), and str.

WvFastString::WvFastString unsigned int  i  ) 
 

Definition at line 105 of file wvstring.cc.

References newbuf(), and str.

WvFastString::WvFastString long  i  ) 
 

Definition at line 112 of file wvstring.cc.

References newbuf(), and str.

WvFastString::WvFastString unsigned long  i  ) 
 

Definition at line 119 of file wvstring.cc.

References newbuf(), and str.

WvFastString::WvFastString long long  i  ) 
 

Definition at line 126 of file wvstring.cc.

References newbuf(), and str.

WvFastString::WvFastString unsigned long long  i  ) 
 

Definition at line 133 of file wvstring.cc.

References newbuf(), and str.

WvFastString::WvFastString double  i  ) 
 

Definition at line 140 of file wvstring.cc.

References newbuf(), and str.

WvFastString::WvFastString WVSTRING_FORMAT_DECL   )  [inline]
 

Now, you're probably thinking to yourself: Boy, does this ever look ridiculous.

And indeed it does. However, it is completely type-safe and when functions are enabled, it reduces automatically to its minimum possible implementation. (ie. all extra comparisons with wv_null go away if the parameter really _is_ wv_null, and that is the default!)

I failed to find a way to optimize out the comparisons for parameters that _are_ provided, however.

There is a small problem, which is that only up to 20 (numbers 0 to 19) additional arguments are allowed. Luckily, no one has ever used that many on one "printf"-type line in the history of the world.

Definition at line 168 of file wvstring.h.

References do_format(), link(), null, and nullbuf.

WvFastString::~WvFastString  ) 
 

Definition at line 147 of file wvstring.cc.

References unlink().


Member Function Documentation

WvStringBuf * WvFastString::alloc size_t  size  )  [protected]
 

Definition at line 172 of file wvstring.cc.

References WvStringBuf::links, WvStringBuf::size, WVSTRING_EXTRA, and WVSTRINGBUF_SIZE.

Referenced by newbuf(), and WvString::unique().

const char* WvFastString::cstr  )  const [inline]
 

return a (const char *) for this string.

The typecast operator does this automatically when needed, but sometimes (especially with varargs like in printf()) that isn't convenient enough.

Definition at line 245 of file wvstring.h.

References str.

Referenced by WvBackslashEncoder::_encode(), WvOggVorbisEncoder::add_comment(), WvOggVorbisEncoder::add_tag(), ascending(), WvMonikerRegistry::create(), do_format(), WvConfEmu::get(), WvConfigSectionEmu::get(), UniRegistryGen::get(), UniPStoreGen::get(), main(), mkdirp(), WvBdbHashBase::opendb(), operator QString(), WvBufBase< unsigned char >::putstr(), UniClientConn::readcmd(), WvConstStringBuffer::reset(), UniRegistryGen::set(), UniPStoreGen::set(), UniConfGen::str2int(), UniConfGremlin::test(), WvX509Mgr::unhexify(), WvStream::write(), WvGdbmHashBase::WvGdbmHashBase(), WvPamStream::WvPamStream(), wvtcl_escape(), and WvTaskMan::yield().

void WvFastString::do_format WvFastString output,
const char *  format,
const WvFastString *const *  a
[static]
 

when this is called, we assume output.str == NULL; it will be filled.

Definition at line 365 of file wvstring.cc.

References _max(), cstr(), pparse(), setsize(), and str.

Referenced by WvFastString().

bool WvFastString::isnull  )  const [inline]
 

returns true if this string is null

Definition at line 262 of file wvstring.h.

References str.

Referenced by _wv_serialize(), UniClientGen::conncallback(), UniConfDaemonConn::deltacallback(), UniConfDaemonConn::do_get(), UniConfDaemonConn::execute(), UniConfGen::exists(), UniMountTreeGen::get(), UniPermGen::getgroup(), UniPermGen::getowner(), UniConfKey::init(), main(), UniClientConn::readcmd(), UniIniGen::refresh(), UniTempGen::set(), UniClientGen::set(), UniConfGen::str2int(), wvtcl_decode(), and WVTEST_MAIN().

size_t WvFastString::len  )  const
 

Definition at line 196 of file wvstring.cc.

References str.

Referenced by WvLogFileBase::_make_prefix(), WvLogRcv::_make_prefix(), backslash_escape(), WvX509Mgr::decode(), nice_hostname(), WvUrl::operator WvString(), WvBufBase< unsigned char >::putstr(), WvConstStringBuffer::reset(), WvString::unique(), url_encode(), WvStream::write(), WvPamStream::WvPamStream(), wvtcl_unescape(), and WVTEST_MAIN().

void WvFastString::link WvStringBuf _buf,
const char *  _str
[protected]
 

Definition at line 163 of file wvstring.cc.

References WvStringBuf::links, and str.

Referenced by WvString::copy_constructor(), WvString::operator=(), operator=(), WvString::unique(), WvFastString(), and WvString::WvString().

void WvFastString::newbuf size_t  size  )  [protected]
 

Definition at line 202 of file wvstring.cc.

References alloc(), WvStringBuf::data, WvStringBuf::links, and str.

Referenced by WvString::operator=(), setsize(), and WvFastString().

int WvFastString::num  )  const [inline]
 

used to convert WvString to int, when needed.

we no longer provide a typecast, because it causes annoyance.

Definition at line 258 of file wvstring.h.

References str.

Referenced by creator(), and WvIPRouteList::get_kernel().

WvFastString::operator const char *  )  const [inline]
 

auto-convert WvString to (const char *), when needed.

Definition at line 237 of file wvstring.h.

References str.

WvFastString::operator QString  )  const
 

return a Qt library QString containing the contents of this string.

You need to link to libwvqt.so if you use this.

Definition at line 42 of file wvqtstring.cc.

References cstr().

bool WvFastString::operator!  )  const
 

the not operator is 'true' if string is empty

Definition at line 313 of file wvstring.cc.

References str.

bool WvFastString::operator!= const char *  s2  )  const
 

Definition at line 297 of file wvstring.cc.

References str.

bool WvFastString::operator!= WvStringParm  s2  )  const
 

Definition at line 276 of file wvstring.cc.

References str, and WvStringParm.

const char* WvFastString::operator+ int  i  )  const [inline]
 

Definition at line 231 of file wvstring.h.

References str.

const char* WvFastString::operator- int  i  )  const [inline]
 

Definition at line 233 of file wvstring.h.

References str.

bool WvFastString::operator< const char *  s2  )  const
 

Definition at line 303 of file wvstring.cc.

References str.

bool WvFastString::operator< WvStringParm  s2  )  const
 

Definition at line 282 of file wvstring.cc.

References str, and WvStringParm.

WvFastString & WvFastString::operator= const WvFastString s2  )  [protected]
 

Reimplemented in WvString.

Definition at line 226 of file wvstring.cc.

References buf, link(), str, and unlink().

bool WvFastString::operator== const char *  s2  )  const
 

Definition at line 291 of file wvstring.cc.

References str.

bool WvFastString::operator== WvStringParm  s2  )  const
 

Definition at line 270 of file wvstring.cc.

References str, and WvStringParm.

void WvFastString::setsize size_t  i  ) 
 

Definition at line 25 of file wvstring.cc.

References newbuf(), and unlink().

Referenced by backslash_escape(), do_format(), WvProtoStream::Token::fill(), UniRegistryGen::get(), UniDefGen::get(), WvBufBase< unsigned char >::getstr(), hexdump_buffer(), WvX509Mgr::hexify(), UniConfKey::init(), metriculate(), nice_hostname(), UniConfKey::range(), rfc1123_date(), rfc822_date(), strcoll_join(), web_unescape(), and WvX509Mgr::WvX509Mgr().

void WvFastString::unlink  )  [protected]
 

Definition at line 153 of file wvstring.cc.

References WvStringBuf::links.

Referenced by WvString::operator=(), operator=(), setsize(), WvString::unique(), and ~WvFastString().


Member Data Documentation

WvStringBuf* WvFastString::buf [protected]
 

Definition at line 90 of file wvstring.h.

Referenced by WvString::copy_constructor(), WvString::operator=(), operator=(), and WvFastString().

const WvFastString WvFastString::null [static]
 

Definition at line 13 of file wvstring.cc.

Referenced by WvFastString().

WvStringBuf WvFastString::nullbuf = { 0, 1 } [static, protected]
 

Definition at line 12 of file wvstring.cc.

Referenced by WvFastString().

char* WvFastString::str [protected]
 

Definition at line 91 of file wvstring.h.

Referenced by WvString::copy_constructor(), cstr(), do_format(), WvString::edit(), isnull(), len(), link(), newbuf(), num(), operator const char *(), operator!(), operator!=(), operator+(), operator-(), operator<(), WvString::operator=(), operator=(), operator==(), and WvFastString().


The documentation for this class was generated from the following files:
Generated on Sat Mar 13 14:57:40 2004 for WvStreams by doxygen 1.3.6-20040222