Browse Source

String_Type:

* setBufferSize() and setBufferSizeNoCopy() moved from protected to public.
* Added capacity()
release/0.19
JustinAJ 9 years ago
parent
commit
7ef60a0d2f
  1. 83
      Jupiter/CString.h
  2. 5
      Jupiter/CString_Imp.h
  3. 37
      Jupiter/Shift_String.h
  4. 46
      Jupiter/String.h
  5. 5
      Jupiter/String_Imp.h
  6. 46
      Jupiter/String_Type.h
  7. 5
      Jupiter/String_Type_Imp.h
  8. BIN
      Release/Jupiter.lib

83
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<T> 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<Jupiter::CString_Loose> tokenize(const Jupiter::Readable_String<T> &in, const Jupiter::Readable_String<T> &separator);
static TokenizeResult<Jupiter::CString_Loose> tokenize(const Jupiter::Readable_String<T> &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 &) {};

5
Jupiter/CString_Imp.h

@ -618,6 +618,11 @@ template<typename T> bool Jupiter::CString_Loose<T>::setBufferSizeNoCopy(size_t
return false;
}
template<typename T> size_t Jupiter::CString_Loose<T>::capacity() const
{
return Jupiter::CString_Loose<T>::strSize - 1;
}
template<typename T> Jupiter::CString_Loose<T> Jupiter::CString_Loose<T>::Format(const T *format, ...)
{
CString_Loose<T> r;

37
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<T> &&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<T> &&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 */
};
}

46
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<Jupiter::String_Loose> tokenize(const Jupiter::Readable_String<T> &in, const Jupiter::Readable_String<T> &separator);
static TokenizeResult<Jupiter::String_Loose> tokenize(const Jupiter::Readable_String<T> &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 &) {};

5
Jupiter/String_Imp.h

@ -536,6 +536,11 @@ template<> size_t inline Jupiter::String_Loose<wchar_t>::vformat(const wchar_t *
return Jupiter::String_Type<wchar_t>::length = minLen;
}
template<typename T> size_t Jupiter::String_Loose<T>::capacity() const
{
return Jupiter::String_Loose<T>::strSize;
}
template<typename T> size_t Jupiter::String_Loose<T>::vformat(const T *format, va_list args)
{
return 0;

46
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<template<typename> class R> static R<T> substring(const Jupiter::Readable_String<T> &in, size_t pos, size_t len);
template<template<typename> class R> static R<T> 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<T> &operator+=(const Readable_String<T> &right) { this->concat(right); return *this; };
inline String_Type<T> &operator+=(const String_Type<T> &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 */
};

5
Jupiter/String_Type_Imp.h

@ -50,6 +50,11 @@ template<typename T> size_t Jupiter::String_Type<T>::size() const
return Jupiter::String_Type<T>::length;
}
template<typename T> size_t Jupiter::String_Type<T>::capacity() const
{
return this->size();
}
template<typename T> const T *Jupiter::String_Type<T>::ptr() const
{
return Jupiter::String_Type<T>::str;

BIN
Release/Jupiter.lib

Binary file not shown.
Loading…
Cancel
Save