Browse Source

Added Reference_String class.

release/0.19
JustinAJ 11 years ago
parent
commit
b47fedda1c
  1. 2
      Jupiter/Jupiter.vcxproj
  2. 6
      Jupiter/Jupiter.vcxproj.filters
  3. 211
      Jupiter/Reference_String.h
  4. 146
      Jupiter/Reference_String_Imp.h
  5. BIN
      Release/Jupiter.lib

2
Jupiter/Jupiter.vcxproj

@ -134,6 +134,8 @@
<ClInclude Include="Queue.h" /> <ClInclude Include="Queue.h" />
<ClInclude Include="Readable_String.h" /> <ClInclude Include="Readable_String.h" />
<ClInclude Include="Readable_String_Imp.h" /> <ClInclude Include="Readable_String_Imp.h" />
<ClInclude Include="Reference_String.h" />
<ClInclude Include="Reference_String_Imp.h" />
<ClInclude Include="Rehash.h" /> <ClInclude Include="Rehash.h" />
<ClInclude Include="resource.h" /> <ClInclude Include="resource.h" />
<ClInclude Include="SecureSocket.h" /> <ClInclude Include="SecureSocket.h" />

6
Jupiter/Jupiter.vcxproj.filters

@ -209,6 +209,12 @@
<ClInclude Include="Readable_String_Imp.h"> <ClInclude Include="Readable_String_Imp.h">
<Filter>Header Files\Strings</Filter> <Filter>Header Files\Strings</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Reference_String.h">
<Filter>Header Files\Strings</Filter>
</ClInclude>
<ClInclude Include="Reference_String_Imp.h">
<Filter>Header Files\Strings</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ResourceCompile Include="Jupiter.rc"> <ResourceCompile Include="Jupiter.rc">

211
Jupiter/Reference_String.h

@ -0,0 +1,211 @@
/**
* Copyright (C) 2013-2014 Justin James.
*
* This license must be preserved.
* Any applications, libraries, or code which make any use of any
* component of this program must not be commercial, unless explicit
* permission is granted from the original author. The use of this
* program for non-profit purposes is permitted.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* In the event that this license restricts you from making desired use of this program, contact the original author.
* Written by Justin James <justin.aj@hotmail.com>
*/
#if !defined _REFERENCE_STRING_H_HEADER
#define _REFERENCE_STRING_H_HEADER
/**
* @file Reference_String.h
* @brief Provides the basis for String types, of any implementation.
* Note: Some methods are commented out. This means that they should be implemented, but could not be put declared in this template (return of abstract type).
*/
#include "Readable_String.h"
namespace Jupiter
{
/**
* @brief Provides the basis for String classes by providing implementations for operators, comparative operations, and defining abstract functions.
* Note: This is an abstract type.
*
* @param T Element type which the String will store. Defaults to char.
*/
template<typename T = char> class Reference_String : public Jupiter::Readable_String<T>
{
public:
/**
* @brief Fetches an element from the string.
*
* @param index Index of the element to return.
* @return The element located at the specified index.
*/
const T &get(size_t index) const;
/**
* @brief Returns the number of elements in the String.
*
* @return Number of elements in the string.
*/
size_t size() const;
/**
* @brief Returns a pointer to the underlying string of elements.
*
* @return Pointer to the underlying string of elements.
*/
const T *ptr() const;
/**
* @brief Creates a partial copy of the string.
*
* @param pos Position in the string to start copying from.
* @return String containing a partial copy of the original string.
*/
Reference_String<T> substring(size_t pos) const;
/**
* @brief Creates a partial copy of the string.
*
* @param pos Position in the string to start copying from.
* @param length Number of characters to copy.
* @return String containing a partial copy of the original string.
*/
Reference_String<T> substring(size_t pos, size_t length) const;
/**
* @brief Creates a partial copy of the string.
*
* @param in String to get a partial copy of.
* @param pos Position in the string to start copying from.
* @return String containing a partial copy of the original string.
*/
static Reference_String<T> substring(const Jupiter::Readable_String<T> &in, size_t pos);
static Reference_String<T> substring(const T *in, size_t pos);
/**
* @brief Creates a partial copy of the string.
*
* @param in String to get a partial copy of.
* @param pos Position in the string to start copying from.
* @param length Number of characters to copy.
* @return String containing a partial copy of the original string.
*/
static Reference_String<T> substring(const Jupiter::Readable_String<T> &in, size_t pos, size_t length);
static Reference_String<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.
*
* @param pos Position of word in the string to start copying from.
* @param whitespace A string of tokens used to deliminate words.
* @return String containing a partial copy of the original string.
*/
Reference_String<T> getWord(size_t pos, const T *whitespace) const;
/**
* @brief Creates a partial copy of an input string, based on a set of tokens.
*
* @param in String to get a partial copy of.
* @param pos Position of word in the string to start copying from.
* @param whitespace A string of tokens used to deliminate words.
* @return String containing a partial copy of the original string.
*/
static Reference_String<T> getWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace);
/**
* @brief Creates a partial copy of an input string, based on a set of tokens.
*
* @param in C-Style string to get a partial copy of.
* @param pos Position of word in the string to start copying from.
* @param whitespace A string of tokens used to deliminate words.
* @return String containing a partial copy of the original string.
*/
static Reference_String<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.
*
* @param pos Position in the string to start copying from.
* @param whitespace A string of tokens used to deliminate words.
* @return String containing a partial copy of the original string.
*/
Reference_String<T> gotoWord(size_t pos, const T *whitespace) const;
/**
* @brief Creates a partial copy of the string, based on a set of tokens.
*
* @param in String to get a partial copy of.
* @param pos Position in the string to start copying from.
* @param whitespace A string of tokens used to deliminate words.
* @return String containing a partial copy of the original string.
*/
static Reference_String<T> gotoWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace);
/**
* @brief Creates a partial copy of the string, based on a set of tokens.
*
* @param in C-Style string to get a partial copy of.
* @param pos Position in the string to start copying from.
* @param whitespace A string of tokens used to deliminate words.
* @return String containing a partial copy of the original string.
*/
static Reference_String<T> gotoWord(const T *in, size_t pos, const T *whitespace);
/**
* @brief Default constructor for the Reference_String class.
*/
Reference_String();
/**
* @brief Creates a reference to a C-Style string.
*
* @param in String to get a reference of.
*/
Reference_String(const T *in);
/**
* @brief Creates a reference to a string.
*
* @param in String to get a reference of.
* @param len Length of the string to track.
*/
Reference_String(const T *in, size_t len);
/**
* @brief Move constructor for the Reference_String class.
*/
Reference_String(Jupiter::Reference_String<T> &&source);
/**
* @brief Constructor for the Refererence_String class to create a reference to an existing string.
*/
Reference_String(const Jupiter::Readable_String<T> &in);
/**
* @brief Copy constructor for the Reference_String class.
*/
Reference_String(const Jupiter::Reference_String<T> &in);
protected:
const T *str; /** Pointer for the underlying string of elements */
size_t length; /** Number of representable elements in the string */
};
/** Generic Reference String Type */
typedef Reference_String<char> ReferenceString;
/** Generic Wide Reference String Type */
typedef Reference_String<wchar_t> ReferenceWString;
}
#include "Reference_String_Imp.h"
#endif // _REFERENCE_STRING_H_HEADER

146
Jupiter/Reference_String_Imp.h

@ -0,0 +1,146 @@
/**
* Copyright (C) 2014 Justin James.
*
* This license must be preserved.
* Any applications, libraries, or code which make any use of any
* component of this program must not be commercial, unless explicit
* permission is granted from the original author. The use of this
* program for non-profit purposes is permitted.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* In the event that this license restricts you from making desired use of this program, contact the original author.
* Written by Justin James <justin.aj@hotmail.com>
*/
#if !defined _REFERENCE_STRING_IMP_H_HEADER
#define _REFERENCE_STRING_IMP_H_HEADER
/**
* @file Readable_String_Imp.h
* @brief Provides the implementations for Readable_String functions.
* Note: Modification of this file is not supported in any way.
*/
#include "Reference_String.h"
#include "Functions.h"
/**
* IMPLEMENTATION:
* Reference_String
*/
template<typename T> Jupiter::Reference_String<T>::Reference_String()
{
Jupiter::Reference_String<T>::str = "";
Jupiter::Reference_String<T>::length = 0;
}
template<typename T> Jupiter::Reference_String<T>::Reference_String(const T *in)
{
Jupiter::Reference_String<T>::str = in;
Jupiter::Reference_String<T>::length = Jupiter::strlen<T>(in);
}
template<typename T> Jupiter::Reference_String<T>::Reference_String(const T *in, size_t len)
{
Jupiter::Reference_String<T>::str = in;
Jupiter::Reference_String<T>::length = len;
}
template<typename T> Jupiter::Reference_String<T>::Reference_String(Jupiter::Reference_String<T> &&source)
{
Jupiter::Reference_String<T>::str = source.str;
Jupiter::Reference_String<T>::length = source.length;
source.length = 0;
source.str = "";
}
template<typename T> Jupiter::Reference_String<T>::Reference_String(const Jupiter::Readable_String<T> &in) : Reference_String(in.ptr(), in.size())
{
}
template<typename T> Jupiter::Reference_String<T>::Reference_String(const Jupiter::Reference_String<T> &in) : Reference_String(in.str, in.length)
{
}
template<typename T> const T &Jupiter::Reference_String<T>::get(size_t index) const
{
return Jupiter::Reference_String<T>::str[index];
}
template<typename T> size_t Jupiter::Reference_String<T>::size() const
{
return Jupiter::Reference_String<T>::length;
}
template<typename T> const T *Jupiter::Reference_String<T>::ptr() const
{
return Jupiter::Reference_String<T>::str;
}
template<typename T> Jupiter::Reference_String<T> Jupiter::Reference_String<T>::substring(size_t pos) const
{
return Jupiter::Reference_String<T>::substring(*this, pos);
}
template<typename T> Jupiter::Reference_String<T> Jupiter::Reference_String<T>::substring(size_t pos, size_t len) const
{
return Jupiter::Reference_String<T>::substring(*this, pos, len);
}
template<typename T> Jupiter::Reference_String<T> Jupiter::Reference_String<T>::substring(const Jupiter::Readable_String<T> &in, size_t pos)
{
if (pos > in.size()) pos = in.size();
return Jupiter::Reference_String<T>(in.ptr() + pos, in.size() - pos);
}
template<typename T> Jupiter::Reference_String<T> Jupiter::Reference_String<T>::substring(const T *in, size_t pos)
{
return Jupiter::Reference_String<T>(in + pos);
}
template<typename T> Jupiter::Reference_String<T> Jupiter::Reference_String<T>::substring(const Jupiter::Readable_String<T> &in, size_t pos, size_t len)
{
if (pos + len > in.size()) return Jupiter::Reference_String<T>::substring(in, pos);
return Jupiter::Reference_String<T>(in.ptr() + pos, len);
}
template<typename T> Jupiter::Reference_String<T> Jupiter::Reference_String<T>::substring(const T *in, size_t pos, size_t len)
{
return Jupiter::Reference_String<T>(in + pos, len);
}
template<typename T> Jupiter::Reference_String<T> Jupiter::Reference_String<T>::getWord(size_t pos, const T *whitespace) const
{
return Jupiter::Reference_String<T>::getWord(*this, pos, whitespace);
}
template<typename T> Jupiter::Reference_String<T> Jupiter::Reference_String<T>::getWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace)
{
return Jupiter::Readable_String<T>::getWord<Jupiter::Reference_String>(in, pos, whitespace);
}
template<typename T> Jupiter::Reference_String<T> Jupiter::Reference_String<T>::getWord(const T *in, size_t pos, const T *whitespace)
{
return Jupiter::Readable_String<T>::getWord<Jupiter::Reference_String>(in, pos, whitespace);
}
template<typename T> Jupiter::Reference_String<T> Jupiter::Reference_String<T>::gotoWord(size_t pos, const T *whitespace) const
{
return Jupiter::Reference_String<T>::gotoWord(*this, pos, whitespace);
}
template<typename T> Jupiter::Reference_String<T> Jupiter::Reference_String<T>::gotoWord(const Jupiter::Readable_String<T> &in, size_t pos, const T *whitespace)
{
return Jupiter::Readable_String<T>::gotoWord<Jupiter::Reference_String>(in, pos, whitespace);
}
template<typename T> Jupiter::Reference_String<T> Jupiter::Reference_String<T>::gotoWord(const T *in, size_t pos, const T *whitespace)
{
return Jupiter::Readable_String<T>::gotoWord<Jupiter::Reference_String>(in, pos, whitespace);
}
#endif // _REFERENCE_STRING_IMP

BIN
Release/Jupiter.lib

Binary file not shown.
Loading…
Cancel
Save