diff --git a/Jupiter/CString.h b/Jupiter/CString.h index 78f5d5a..1ccd787 100644 --- a/Jupiter/CString.h +++ b/Jupiter/CString.h @@ -228,6 +228,24 @@ namespace Jupiter size_t concat(const T *in) override; size_t concat(const T &in) override; + /** + * @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) override; + + /** + * @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) override; + /** Default Constructor */ CString_Type(); @@ -266,25 +284,6 @@ namespace Jupiter static const Jupiter::CString_Type empty; /** Empty instantiation of CString_Type */ 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_Type(Jupiter::String_Constructor_Base &) {}; }; @@ -305,6 +304,15 @@ namespace Jupiter { public: + /** + * @brief Returns the maximum number of elements the String can contain, + * without expanding the socket buffer. This is generally the size of the + * underlying memory buffer. + * + * @return Number of elements the string can contain without reallocation. + */ + virtual size_t capacity() const; + /** * @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. @@ -424,6 +432,24 @@ namespace Jupiter static TokenizeResult tokenize(const Jupiter::Readable_String &in, const Jupiter::Readable_String &separator); static TokenizeResult tokenize(const Jupiter::Readable_String &in, const T *separator, size_t separator_size); + /** + * @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) override; + + /** + * @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) override; + /** Default constructor */ CString_Loose(); @@ -463,25 +489,6 @@ namespace Jupiter static const size_t start_size = 8; /** Starting size for loose CStrings. */ 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 &) {}; diff --git a/Jupiter/CString_Imp.h b/Jupiter/CString_Imp.h index 36dfba2..9213aba 100644 --- a/Jupiter/CString_Imp.h +++ b/Jupiter/CString_Imp.h @@ -618,6 +618,11 @@ template bool Jupiter::CString_Loose::setBufferSizeNoCopy(size_t return false; } +template size_t Jupiter::CString_Loose::capacity() const +{ + return Jupiter::CString_Loose::strSize - 1; +} + template Jupiter::CString_Loose Jupiter::CString_Loose::Format(const T *format, ...) { CString_Loose r; diff --git a/Jupiter/Shift_String.h b/Jupiter/Shift_String.h index 13a9e95..ad42af6 100644 --- a/Jupiter/Shift_String.h +++ b/Jupiter/Shift_String.h @@ -81,23 +81,6 @@ namespace Jupiter */ virtual void erase(); - /** - * @brief Default constructor for the Shift_String_Type class. - */ - Shift_String_Type() {} - - /** - * @brief Move constructor for the Shift_String_Type class. - */ - Shift_String_Type(Jupiter::Shift_String_Type &&source); - - /** - * @brief Destructor for the Shift_String_Type class. - */ - virtual ~Shift_String_Type(); - - 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. @@ -105,7 +88,7 @@ namespace Jupiter * @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); + virtual bool setBufferSize(size_t len) override; /** * @brief Empties the string, and sets the internal buffer to be at least large enough to old a specified number of elements. @@ -114,8 +97,24 @@ namespace Jupiter * @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); + virtual bool setBufferSizeNoCopy(size_t len) override; + /** + * @brief Default constructor for the Shift_String_Type class. + */ + Shift_String_Type() {} + + /** + * @brief Move constructor for the Shift_String_Type class. + */ + Shift_String_Type(Jupiter::Shift_String_Type &&source); + + /** + * @brief Destructor for the Shift_String_Type class. + */ + virtual ~Shift_String_Type(); + + protected: T *base; /** Base pointer for the underlying String's memory allocation */ }; } diff --git a/Jupiter/String.h b/Jupiter/String.h index 655a38f..26c6650 100644 --- a/Jupiter/String.h +++ b/Jupiter/String.h @@ -283,6 +283,15 @@ namespace Jupiter { public: + /** + * @brief Returns the maximum number of elements the String can contain, + * without expanding the socket buffer. This is generally the size of the + * underlying memory buffer. + * + * @return Number of elements the string can contain without reallocation. + */ + virtual size_t capacity() const; + /** * @brief Sets the String'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. @@ -464,6 +473,24 @@ namespace Jupiter static TokenizeResult tokenize(const Jupiter::Readable_String &in, const Jupiter::Readable_String &separator); static TokenizeResult tokenize(const Jupiter::Readable_String &in, const T *separator, size_t separator_size); + /** + * @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) override; + + /** + * @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) override; + /** Default constructor */ String_Loose(); @@ -503,25 +530,6 @@ namespace Jupiter static const size_t start_size = 8; /** Starting size for loose Strings. */ 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 */ String_Loose(Jupiter::String_Constructor_Base &) {}; diff --git a/Jupiter/String_Imp.h b/Jupiter/String_Imp.h index fbd3d2e..bd45b86 100644 --- a/Jupiter/String_Imp.h +++ b/Jupiter/String_Imp.h @@ -536,6 +536,11 @@ template<> size_t inline Jupiter::String_Loose::vformat(const wchar_t * return Jupiter::String_Type::length = minLen; } +template size_t Jupiter::String_Loose::capacity() const +{ + return Jupiter::String_Loose::strSize; +} + template size_t Jupiter::String_Loose::vformat(const T *format, va_list args) { return 0; diff --git a/Jupiter/String_Type.h b/Jupiter/String_Type.h index 1634041..3cd343c 100644 --- a/Jupiter/String_Type.h +++ b/Jupiter/String_Type.h @@ -61,6 +61,15 @@ namespace Jupiter */ size_t size() const; + /** + * @brief Returns the maximum number of elements the String can contain, + * without expanding the socket buffer. This is generally the size of the + * underlying memory buffer. + * + * @return Number of elements the string can contain without reallocation. + */ + virtual size_t capacity() const; + /** * @brief Returns a pointer to the underlying string of elements. * @@ -230,6 +239,24 @@ namespace Jupiter template class R> static R substring(const Jupiter::Readable_String &in, size_t pos, size_t len); template class R> static R substring(const T *in, size_t pos, size_t len); + /** + * @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) = 0; + + /** + * @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) = 0; + /** Mutative operators */ inline String_Type &operator+=(const Readable_String &right) { this->concat(right); return *this; }; inline String_Type &operator+=(const String_Type &right) { this->concat(right); return *this; }; @@ -265,25 +292,6 @@ namespace Jupiter */ 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) = 0; - - /** - * @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) = 0; - T *str; /** Pointer for the underlying string of elements */ size_t length; /** Number of representable elements in the string */ }; diff --git a/Jupiter/String_Type_Imp.h b/Jupiter/String_Type_Imp.h index fe018f7..13efd55 100644 --- a/Jupiter/String_Type_Imp.h +++ b/Jupiter/String_Type_Imp.h @@ -50,6 +50,11 @@ template size_t Jupiter::String_Type::size() const return Jupiter::String_Type::length; } +template size_t Jupiter::String_Type::capacity() const +{ + return this->size(); +} + template const T *Jupiter::String_Type::ptr() const { return Jupiter::String_Type::str; diff --git a/Release/Jupiter.lib b/Release/Jupiter.lib index d01bfca..d09d6b2 100644 Binary files a/Release/Jupiter.lib and b/Release/Jupiter.lib differ