#include <OTC/text/rstring.hh> class OTC_RString {
public:
~OTC_RString();
OTC_RString( u_int theLength, OTC_StringBuffering theType=OTCLIB_BUFFERED );
OTC_RString( u_int theLength, void const* theObject, OTC_StringBuffering theType=OTCLIB_BUFFERED );
OTC_RString(OTC_RString const& theString);
inline u_int length() const;
inline u_int capacity() const;
inline OTC_Boolean isShared() const;
inline OTC_Boolean isLocked() const;
inline OTC_Boolean isSymbol() const;
char const* string() const;
char* string();
inline char operator[](u_int theIndex) const;
inline char& operator[](u_int theIndex);
void reallocate(u_int theLength);
inline void sync();
void lock();
void unlock();
OTC_RString const& operator=(OTC_RString const& theString);
friend ostream& operator<<( ostream& outs, OTC_RString const& theString );
};
OTC_RString
class is a wrapper for OTC_StringData
. This
class implements the functionality for maintaining the string
memory and the delayed copy mechanism. The OTC_StringData
class
holds all the data required. This class ensures that the string is
null terminated on initial allocation and reallocation. If you
overwrite the null terminator it is your own problem.
OTC_RString(
u_int theLength,
OTC_StringBuffering theType=OTCLIB_BUFFERED
);
theLength
. If theType
is
OTCLIB_UNBUFFERED
, only enough memory
to hold the string and a null terminator
will initially be allocated. If theType
is OTCLIB_BUFFERED
, the default,
additional memory may be allocated to try
to reduce memory allocations on changes in
the length of the string.
OTC_RString(
u_int theLength,
void const* theObject,
OTC_StringBuffering theType=OTCLIB_BUFFERED
);
theLength
. If theType
is
OTCLIB_UNBUFFERED
, only enough memory
to hold the string and a null terminator
will initially be allocated. If theType
is OTCLIB_BUFFERED
, the default,
additional memory may be allocated to try
to reduce memory allocations on changes in
the length of the string. The additional
argument of theObject
indicates which
object internal memory should be allocated
with when ObjectStore is being used.
OTC_RString(OTC_RString const& theString);
theString
.
inline u_int length() const;
inline u_int capacity() const;
inline OTC_Boolean isShared() const;
OTCLIB_TRUE
if this class
references a chunk of memory which is also
being referenced by another instance of
the class.
inline OTC_Boolean isLocked() const;
OTCLIB_TRUE
if the memory is
currently locked for exclusive use.
inline OTC_Boolean isSymbol() const;
OTCLIB_TRUE
if the memory
represents a symbol. Only really useful to
OTC_Symbol
.
sync()
or reallocate()
should be invoked to force a separate
copy to be made.
If you overwrite the null terminator added by this class via
these functions, it is your problem.
char const* string() const;
char* string();
inline char operator[](u_int theIndex) const;
theIndex
into the string. No
bounds checking is performed.
inline char& operator[](u_int theIndex);
theIndex
into the string. No
bounds checking is performed.
void reallocate(u_int theLength);
realloc(3)
, this
function will result in a new string being
allocated with sufficient size to hold
theLength
characters. If theLength
is
less than or equal to the current capacity
of this string and the string is not also
being referenced by another instance of
this class, no reallocation will be
made, instead the same piece of memory
will be used, the length adjusted and a
new null terminator inserted. If a new
string is allocated, the contents of
the old string will be copied into the
new. In doing this, instances of this
class which previously shared the same
string as this class will no longer do so,
instead they will continue to reference
the old string.
inline void sync();
reallocate(length())
.
void lock();
void unlock();
OTC_RString const& operator=(OTC_RString const& theString);
theString
to be referenced instead. The old string
will only be deleted if no other instances
of the class reference it.
friend ostream& operator<<(
ostream& outs,
OTC_RString const& theString
);
theString
to the stream outs
.
Width and justification specifications
are honoured.