Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

WvString Class Reference

#include <wvstring.h>

Inheritance diagram for WvString:

Inheritance graph
[legend]
List of all members.

Detailed Description

WvString is an implementation of a simple and efficient printable-string class.

It leaves out many of the notational conveniences provided by other string classes, because they waste too much CPU time and space.

It does the one thing really missing from char* strings, that is, dynamic buffer management.

When you copy one WvString to another, it does _not_ duplicate the buffer; it just creates another pointer to it. To really duplicate the buffer, call the unique() member function.

To change the contents of a WvString, you need to run its edit() member function, which executes unique() and then returns a char* pointer to the WvString contents.

The most annoying side-effect of this implementation is that if you construct a WvString from a char* buffer or static string, WvString won't duplicate it. Usually this is okay and much faster (for example, if you just want to print a static string). However, if you construct a WvString from a dynamic variable, changing the dynamic variable will change the WvString unless you run unique() or edit(). Worse still, deleting the dynamic variable will make WvString act unpredictably.

But it does cut out extra dynamic memory allocation for the most common cases, and it almost always avoids manual 'new' and 'delete' of string objects.


Public Member Functions

 WvString (short i)
 WvString (unsigned short i)
 WvString (int i)
 WvString (unsigned int i)
 WvString (long i)
 WvString (unsigned long i)
 WvString (long long i)
 WvString (unsigned long long i)
 WvString (double i)
 WvString (const WvString &s)
 Magic copy constructor for "fast" char* strings.
 WvString (const WvFastString &s)
 WvString (const char *_str)
 Create a WvString out of a char* string.
 WvString (const QString &)
 Create a WvString out of a Qt library QString.
 WvString (const QCString &)
 WvString (WVSTRING_FORMAT_DECL)
WvStringappend (WvStringParm s)
WvStringappend (WVSTRING_FORMAT_DECL)
WvStringoperator= (int i)
WvStringoperator= (const WvFastString &s2)
WvStringoperator= (const char *s2)
WvStringunique ()
 make the buf and str pointers owned only by this WvString.
char * edit ()
 make the string editable, and return a non-const (char*)
void setsize (size_t i)
size_t len () const
bool operator== (WvStringParm s2) const
bool operator== (const char *s2) const
bool operator!= (WvStringParm s2) const
bool operator!= (const char *s2) const
bool operator< (WvStringParm 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
const WvFastStringifnull (WvStringParm defval) const
 returns either this string, or, if isnull(), the given string.

Static Public Member Functions

static 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

static const WvString empty
static const WvFastString null

Protected Member Functions

void copy_constructor (const WvFastString &s)
void link (WvStringBuf *_buf, const char *_str)
void unlink ()
WvStringBuf * alloc (size_t size)
void newbuf (size_t size)

Protected Attributes

WvStringBuf * buf
char * str

Static Protected Attributes

static WvStringBuf nullbuf = { 0, 1 }


Constructor & Destructor Documentation

WvString::WvString const WvString s  )  [inline]
 

Magic copy constructor for "fast" char* strings.

When we copy from a "fast" string to a real WvString, we might need to allocate memory (equivalent to unique()) so the original char* can be safely changed or destroyed.

WvString::WvString const char *  _str  ) 
 

Create a WvString out of a char* string.

We always allocate memory and make a copy here. To avoid memory copies, you can (carefully) use a WvFastString. To just have quick parameter passing, use a WvStringParm instead.

WvString::WvString const QString &   ) 
 

Create a WvString out of a Qt library QString.

You have to link with libwvqt.so if you want to use this.


Member Function Documentation

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

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

For example: WvString x[] = {"foo", "blue", 1234}; WvString ret = WvString::do_format("%s%10.2s%-10s", x);

The 'ret' string will be: "foo bl1234 " Note that only '%s' is supported, though integers can be rendered automatically into WvStrings. d, f, etc are not allowed!

This function is usually called from some other function which allocates the array automatically.

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

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.

WvFastString::operator QString  )  const [inherited]
 

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

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

int WvFastString::num  )  const [inline, inherited]
 

used to convert WvString to int, when needed.

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


The documentation for this class was generated from the following files:
Generated on Sun Jul 10 15:31:27 2005 for WvStreams by  doxygen 1.4.0