@ -30,8 +30,7 @@
namespace Jupiter
namespace Jupiter
{
{
/**
/**
* @ brief Provides the basis for CString classes by providing the implementations for many abstract methods in String_Type .
* @ brief Provides the basis for CString classes by providing a minimalist implementation ( i . e : no extra variables ) .
* Note : This is an abstract type .
*
*
* @ param T Element type which the CString will store . Defaults to char .
* @ param T Element type which the CString will store . Defaults to char .
*/
*/
@ -62,24 +61,6 @@ namespace Jupiter
*/
*/
bool remove ( const T & value ) ;
bool remove ( const T & value ) ;
/** Assignment Operators */
inline CString_Type < T > & operator = ( const CString_Type < T > & right ) { this - > set ( right ) ; return * this ; } ;
inline CString_Type < T > & operator = ( const String_Type < T > & right ) { this - > set ( right ) ; return * this ; } ;
inline CString_Type < T > & operator = ( const std : : basic_string < T > & right ) { this - > set ( right ) ; return * this ; } ;
inline CString_Type < T > & operator = ( const T * right ) { this - > set ( right ) ; return * this ; } ;
inline CString_Type < T > & operator = ( const T right ) { this - > set ( right ) ; return * this ; } ;
} ;
/**
* @ brief Provides a " strict " CString implementation that ' s more optimized for minimal memory usage .
* Note : This recreates the underlying C - style string with every concatenation .
*
* @ param T Element type which the CString will store . Defaults to char .
*/
template < typename T = char > class CString_Strict : public CString_Type < T >
{
public :
/**
/**
* @ brief Sets the CString ' s contents based on the format string and input variables .
* @ brief Sets the CString ' s contents based on the format string and input variables .
* Note : Format specifiers similar to printf . Returns 0 for any type other than char and wchar_t .
* Note : Format specifiers similar to printf . Returns 0 for any type other than char and wchar_t .
@ -108,7 +89,7 @@ namespace Jupiter
* @ param . . . Inputs to match the format specifiers .
* @ param . . . Inputs to match the format specifiers .
* @ return String containing the new format .
* @ return String containing the new format .
*/
*/
static CString_Strict Format ( const T * format , . . . ) ;
static CString_Type Format ( const T * format , . . . ) ;
/**
/**
* @ brief Creates a partial copy of the string .
* @ brief Creates a partial copy of the string .
@ -116,7 +97,7 @@ namespace Jupiter
* @ param pos Position in the string to start copying from .
* @ param pos Position in the string to start copying from .
* @ return String containing a partial copy of the original string .
* @ return String containing a partial copy of the original string .
*/
*/
CString_Strict < T > substring ( size_t pos ) const ;
CString_Type < T > substring ( size_t pos ) const ;
/**
/**
* @ brief Creates a partial copy of the string .
* @ brief Creates a partial copy of the string .
@ -125,7 +106,7 @@ namespace Jupiter
* @ param length Number of characters to copy .
* @ param length Number of characters to copy .
* @ return String containing a partial copy of the original string .
* @ return String containing a partial copy of the original string .
*/
*/
CString_Strict < T > substring ( size_t pos , size_t length ) const ;
CString_Type < T > substring ( size_t pos , size_t length ) const ;
/**
/**
* @ brief Creates a partial copy of the string .
* @ brief Creates a partial copy of the string .
@ -134,7 +115,8 @@ namespace Jupiter
* @ param pos Position in the string to start copying from .
* @ param pos Position in the string to start copying from .
* @ return String containing a partial copy of the original string .
* @ return String containing a partial copy of the original string .
*/
*/
static CString_Strict < T > substring ( const Jupiter : : String_Type < T > & in , size_t pos ) ;
static CString_Type < T > substring ( const Jupiter : : String_Type < T > & in , size_t pos ) ;
static CString_Type < T > substring ( const T * in , size_t pos ) ;
/**
/**
* @ brief Creates a partial copy of the string .
* @ brief Creates a partial copy of the string .
@ -144,7 +126,8 @@ namespace Jupiter
* @ param length Number of characters to copy .
* @ param length Number of characters to copy .
* @ return String containing a partial copy of the original string .
* @ return String containing a partial copy of the original string .
*/
*/
static CString_Strict < T > substring ( const Jupiter : : String_Type < T > & in , size_t pos , size_t length ) ;
static CString_Type < T > substring ( const Jupiter : : String_Type < T > & in , size_t pos , size_t length ) ;
static CString_Type < T > substring ( const T * in , size_t pos , size_t length ) ;
/**
/**
* @ brief Creates a partial copy of the string , based on a set of tokens .
* @ brief Creates a partial copy of the string , based on a set of tokens .
@ -153,7 +136,7 @@ namespace Jupiter
* @ param whitespace A string of tokens used to deliminate words .
* @ param whitespace A string of tokens used to deliminate words .
* @ return String containing a partial copy of the original string .
* @ return String containing a partial copy of the original string .
*/
*/
CString_Strict < T > getWord ( size_t pos , const T * whitespace ) const ;
CString_Type < T > getWord ( size_t pos , const T * whitespace ) const ;
/**
/**
* @ brief Creates a partial copy of an input string , based on a set of tokens .
* @ brief Creates a partial copy of an input string , based on a set of tokens .
@ -163,7 +146,7 @@ namespace Jupiter
* @ param whitespace A string of tokens used to deliminate words .
* @ param whitespace A string of tokens used to deliminate words .
* @ return String containing a partial copy of the original string .
* @ return String containing a partial copy of the original string .
*/
*/
static CString_Strict < T > getWord ( const Jupiter : : String_Type < T > & in , size_t pos , const T * whitespace ) ;
static CString_Type < T > getWord ( const Jupiter : : String_Type < T > & in , size_t pos , const T * whitespace ) ;
/**
/**
* @ brief Creates a partial copy of an input string , based on a set of tokens .
* @ brief Creates a partial copy of an input string , based on a set of tokens .
@ -173,7 +156,7 @@ namespace Jupiter
* @ param whitespace A string of tokens used to deliminate words .
* @ param whitespace A string of tokens used to deliminate words .
* @ return String containing a partial copy of the original string .
* @ return String containing a partial copy of the original string .
*/
*/
static CString_Strict < T > getWord ( const T * in , size_t pos , const T * whitespace ) ;
static CString_Type < T > getWord ( const T * in , size_t pos , const T * whitespace ) ;
/**
/**
* @ brief Creates a partial copy of the string , based on a set of tokens .
* @ brief Creates a partial copy of the string , based on a set of tokens .
@ -182,7 +165,7 @@ namespace Jupiter
* @ param whitespace A string of tokens used to deliminate words .
* @ param whitespace A string of tokens used to deliminate words .
* @ return String containing a partial copy of the original string .
* @ return String containing a partial copy of the original string .
*/
*/
CString_Strict < T > gotoWord ( size_t pos , const T * whitespace ) const ;
CString_Type < T > gotoWord ( size_t pos , const T * whitespace ) const ;
/**
/**
* @ brief Creates a partial copy of the string , based on a set of tokens .
* @ brief Creates a partial copy of the string , based on a set of tokens .
@ -192,7 +175,7 @@ namespace Jupiter
* @ param whitespace A string of tokens used to deliminate words .
* @ param whitespace A string of tokens used to deliminate words .
* @ return String containing a partial copy of the original string .
* @ return String containing a partial copy of the original string .
*/
*/
static CString_Strict < T > gotoWord ( const Jupiter : : String_Type < T > & in , size_t pos , const T * whitespace ) ;
static CString_Type < T > gotoWord ( const Jupiter : : String_Type < T > & in , size_t pos , const T * whitespace ) ;
/**
/**
* @ brief Copies the data from the input string to the CString .
* @ brief Copies the data from the input string to the CString .
@ -205,26 +188,6 @@ namespace Jupiter
size_t set ( const T * in ) ;
size_t set ( const T * in ) ;
size_t set ( const T in ) ;
size_t set ( const T in ) ;
/**
* @ brief Sets the string buffer .
* Note : This class will free the buffer for you when it ' s done .
*
* @ param in New buffer to be used .
* @ return The length of the string .
*/
size_t setString ( T * in ) ;
/**
* @ brief Sets the string buffer .
* Note : This class will free the buffer for you when it ' s done . DO NOT DELETE THE INPUT BUFFER .
* Note : This method is unique to the CString_Strict template class , and does not appear in CString_Loose .
*
* @ param in New buffer to be used .
* @ param size At least the number of characters in the buffer , not including the null - terminator .
* @ return The length of the string .
*/
size_t setString ( T * in , size_t size ) ;
/**
/**
* @ brief Copies the data from the input string and concatenates it to the end of CString .
* @ brief Copies the data from the input string and concatenates it to the end of CString .
*
*
@ -236,56 +199,68 @@ namespace Jupiter
size_t concat ( const T * in ) ;
size_t concat ( const T * in ) ;
size_t concat ( const T in ) ;
size_t concat ( const T in ) ;
/** Assignment Operators */
inline CString_Type < T > & operator = ( const CString_Type < T > & right ) { this - > set ( right ) ; return * this ; } ;
inline CString_Type < T > & operator = ( const String_Type < T > & right ) { this - > set ( right ) ; return * this ; } ;
inline CString_Type < T > & operator = ( const std : : basic_string < T > & right ) { this - > set ( right ) ; return * this ; } ;
inline CString_Type < T > & operator = ( const T * right ) { this - > set ( right ) ; return * this ; } ;
inline CString_Type < T > & operator = ( const T right ) { this - > set ( right ) ; return * this ; } ;
static const Jupiter : : CString_Type < T > empty ; /** Empty instantation of CString_Type */
/** Default Constructor */
/** Default Constructor */
CString_Strict ( ) ;
CString_Type ( ) ;
/** Copy Constructors */
/**
CString_Strict ( const String_Type < T > & in ) ;
* @ brief Size hint constructor .
CString_Strict ( const std : : basic_string < T > & in ) ;
* Note : For the CString_Type base class , this is only truly useful internally .
CString_Strict ( const T * in ) ;
*
CString_Strict ( size_t size ) ;
* @ param size Minimum number of elements the string must be able to hold .
*/
CString_Type ( size_t size ) ;
/** Destructor */
/** Move Con structor */
virtual ~ CString_Strict ( ) ;
CString_Type ( CString_Type < T > & & source ) ;
/** Assignment Operators */
/** Copy Constructors */
inline CString_Strict < T > & operator = ( const CString_Strict < T > & right ) { this - > set ( right ) ; return * this ; } ;
CString_Type ( const String_Type < T > & in ) ;
inline CString_Strict < T > & operator = ( const CString_Type < T > & right ) { this - > set ( right ) ; return * this ; } ;
CString_Type ( const std : : basic_string < T > & in ) ;
inline CString_Strict < T > & operator = ( const String_Type < T > & right ) { this - > set ( right ) ; return * this ; } ;
CString_Type ( const T * in ) ;
inline CString_Strict < T > & operator = ( const std : : basic_string < T > & right ) { this - > set ( right ) ; return * this ; } ;
inline CString_Strict < T > & operator = ( const T * right ) { this - > set ( right ) ; return * this ; } ;
protected :
inline CString_Strict < T > & operator = ( const T right ) { this - > set ( right ) ; return * this ; } ;
} ;
/**
/**
* @ brief Provides a " loose " CString implementation that ' s more optimized for repeated concatenation s.
* @ brief Sets the internal buffer to be at least large enough to old a specified number of element s.
* Note : The underlying C - style string will always have a size which is a power of 2 , but no fewer than 8 elements .
* Note : This does nothing if len is less than the string ' s current length .
*
*
* @ param T Element type which the CString will store . Defaults to char .
* @ param len Minimum number of elements the string buffer must be able to hold .
* @ return True if a new buffer was allocated , false otherwise .
*/
*/
template < typename T = char > class CString_Loose : public CString_Type < T >
virtual bool setBufferSize ( size_t len ) ;
{
public :
/**
/**
* @ brief Sets the CString ' s contents based on the format string and input variable s.
* @ brief Empties the string , and sets the internal buffer to be at least large enough to old a specified number of element s.
* Note : Format specifiers similar to printf . Returns 0 for any type other than char and wchar_t .
* Note : This does nothing if len is less than the string ' s current length .
*
*
* @ param format Format that the string is compared against .
* @ param len Minimum number of elements the string buffer must be able to hold .
* @ param . . . Inputs to match the format specifiers .
* @ return True if a new buffer was allocated , false otherwise .
* @ return Number of characters written .
*/
*/
size_t vformat ( const T * format , va_list args ) ;
virtual bool setBufferSizeNoCopy ( size_t len ) ;
/** Dummy constructor to prevent string initialization */
CString_Type ( Jupiter : : String_Constructor_Base & ) { } ;
} ;
template < typename T = char > using CString_Strict = CString_Type < T > ;
/**
/**
* @ brief Appends to a CString ' s contents based on the format string and input variables .
* @ brief Provides a " loose " CString implementation that ' s more optimized for repeated concatenation s.
* Note : Format specifiers similar to printf . Returns 0 for any type other than char and wchar_t .
* Note : The underlying C - style string will always have a size which is a power of 2 , but no fewer than 8 elements .
*
*
* @ param format Format that the string is compared against .
* @ param T Element type which the CString will store . Defaults to char .
* @ param . . . Inputs to match the format specifiers .
* @ return Number of characters written .
*/
*/
size_t avformat ( const T * format , va_list args ) ;
template < typename T = char > class CString_Loose : public CString_Type < T >
{
public :
/**
/**
* @ brief Sets the CString ' s contents based on the format string and input variables .
* @ brief Sets the CString ' s contents based on the format string and input variables .
@ -322,6 +297,7 @@ namespace Jupiter
* @ return String containing a partial copy of the original string .
* @ return String containing a partial copy of the original string .
*/
*/
static CString_Loose < T > substring ( const Jupiter : : String_Type < T > & in , size_t pos ) ;
static CString_Loose < T > substring ( const Jupiter : : String_Type < T > & in , size_t pos ) ;
static CString_Loose < T > substring ( const T * in , size_t pos ) ;
/**
/**
* @ brief Creates a partial copy of the string .
* @ brief Creates a partial copy of the string .
@ -332,6 +308,7 @@ namespace Jupiter
* @ return String containing a partial copy of the original string .
* @ return String containing a partial copy of the original string .
*/
*/
static CString_Loose < T > substring ( const Jupiter : : String_Type < T > & in , size_t pos , size_t length ) ;
static CString_Loose < T > substring ( const Jupiter : : String_Type < T > & in , size_t pos , size_t length ) ;
static CString_Loose < T > substring ( const T * in , size_t pos , size_t length ) ;
/**
/**
* @ brief Creates a partial copy of the string , based on a set of tokens .
* @ brief Creates a partial copy of the string , based on a set of tokens .
@ -383,48 +360,26 @@ namespace Jupiter
*/
*/
static CString_Loose < T > gotoWord ( const Jupiter : : String_Type < T > & in , size_t pos , const T * whitespace ) ;
static CString_Loose < T > gotoWord ( const Jupiter : : String_Type < T > & in , size_t pos , const T * whitespace ) ;
/**
* @ brief Copies the data from the input string to the CString .
*
* @ param in String containing the data to be copied .
* @ return New size of the CString .
*/
size_t set ( const CString_Loose & in ) ;
size_t set ( const String_Type < T > & in ) ;
size_t set ( const std : : basic_string < T > & in ) ;
size_t set ( const T * in ) ;
size_t set ( const T in ) ;
/**
* @ brief Copies the data from the input string and concatenats it to the end of CString .
*
* @ param in String containing the data to be concatenated .
* @ return New size of the CString .
*/
size_t concat ( const String_Type < T > & in ) ;
size_t concat ( const std : : basic_string < T > & in ) ;
size_t concat ( const T * in ) ;
size_t concat ( const T in ) ;
/** Default constructor */
/** Default constructor */
CString_Loose ( ) ;
CString_Loose ( ) ;
/**
/**
* @ brief Size hint constructor .
* @ brief Size hint constructor .
*
*
* @ param size Minimum size of new string ' s buffer .
* @ param size Minimum number of elements the string must be able to hold .
*/
*/
CString_Loose ( size_t size ) ;
CString_Loose ( size_t size ) ;
/** Move Constructor */
CString_Loose ( CString_Loose < T > & & source ) ;
/** Copy Constructors */
/** Copy Constructors */
CString_Loose ( const CString_Loose & in ) ;
CString_Loose ( const CString_Loose & in ) ;
CString_Loose ( const String_Type < T > & in ) ;
CString_Loose ( const String_Type < T > & in ) ;
CString_Loose ( const std : : basic_string < T > & in ) ;
CString_Loose ( const std : : basic_string < T > & in ) ;
CString_Loose ( const T * in ) ;
CString_Loose ( const T * in ) ;
/** Destructor */
static const Jupiter : : CString_Loose < T > empty ; /** Empty instantation of CString_Loose */
virtual ~ CString_Loose ( ) ;
static const size_t start_size = 8 ; /** Starting size for loose CStrings. */
static const size_t start_size = 8 ; /** Starting size for loose CStrings. */
/** Assignment Operators */
/** Assignment Operators */
@ -436,6 +391,28 @@ namespace Jupiter
inline CString_Loose < T > & operator = ( const T right ) { this - > set ( right ) ; return * this ; } ;
inline CString_Loose < T > & operator = ( const T right ) { this - > set ( right ) ; return * this ; } ;
protected :
protected :
/**
* @ brief Sets the internal buffer to be at least large enough to old a specified number of elements .
* Note : This does nothing if len is less than the string ' s current length .
*
* @ param len Minimum number of elements the string buffer must be able to hold .
* @ return True if a new buffer was allocated , false otherwise .
*/
virtual bool setBufferSize ( size_t len ) ;
/**
* @ brief Empties the string , and sets the internal buffer to be at least large enough to old a specified number of elements .
* Note : This does nothing if len is less than the string ' s current length .
*
* @ param len Minimum number of elements the string buffer must be able to hold .
* @ return True if a new buffer was allocated , false otherwise .
*/
virtual bool setBufferSizeNoCopy ( size_t len ) ;
/** Dummy constructor to prevent string initialization */
CString_Loose ( Jupiter : : String_Constructor_Base & ) { } ;
size_t strSize ; /** Size of underlying C-string buffer */
size_t strSize ; /** Size of underlying C-string buffer */
} ;
} ;
@ -445,12 +422,6 @@ namespace Jupiter
/** Definition of a Loose Wide CString */
/** Definition of a Loose Wide CString */
typedef CString_Loose < wchar_t > WCStringL ;
typedef CString_Loose < wchar_t > WCStringL ;
/** Definition of a Strict CString. */
typedef CString_Strict < char > CStringS ;
/** Definition of a Strict Wide CString */
typedef CString_Strict < wchar_t > WCStringS ;
/** Definition of a CString. */
/** Definition of a CString. */
typedef CStringL CString ;
typedef CStringL CString ;
@ -463,14 +434,20 @@ namespace Jupiter
/** Generic Wide CString Type */
/** Generic Wide CString Type */
typedef CString_Type < wchar_t > WCStringType ;
typedef CString_Type < wchar_t > WCStringType ;
/** Definition of a Strict CString. */
typedef CStringType CStringS ;
/** Definition of a Strict Wide CString */
typedef WCStringType WCStringS ;
/** Empty String constants */
/** Empty String constants */
static const Jupiter : : CStringS emptyCStringS ;
static const Jupiter : : CStringS & emptyCStringS = Jupiter : : CStringS : : empty ;
static const Jupiter : : CStringL emptyCStringL ;
static const Jupiter : : CStringL & emptyCStringL = Jupiter : : CStringL : : empty ;
static const Jupiter : : CStringType & emptyCString = emptyCStringS ;
static const Jupiter : : CStringType & emptyCString = emptyCStringS ;
static const Jupiter : : StringType & emptyString = emptyCString ;
static const Jupiter : : StringType & emptyString = emptyCString ;
}
}
/** Implementation for CString_Type, CString_Strict, and CString_Loose. Very scary. */
/** Implementation for CString_Type and CString_Loose. Very scary. */
# include "CString_Imp.h"
# include "CString_Imp.h"
# endif // _CSTRING_H_HEADER
# endif // _CSTRING_H_HEADER