Browse Source

Moved string shifting to its own class.

release/0.19
JustinAJ 10 years ago
parent
commit
3475b398fc
  1. 64
      Jupiter/Shift_String.h
  2. 44
      Jupiter/Shift_String_Imp.h

64
Jupiter/Shift_String.h

@ -0,0 +1,64 @@
/**
* 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 _SHIFT_STRING_H_HEADER
#define _SHIFT_STRING_H_HEADER
/**
* @file Shift_String.h
* @brief Allows for separation of a string's representation from its memory base.
*/
#include "String_Type.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 Shift_String_Type : public Jupiter::String_Type<T>
{
public:
/**
* @brief Shifts the string pointer to the left.
*
* @param length Number of elements to shift
* @return Number of elements shifted to the left.
*/
size_t shiftLeft(size_t length);
/**
* @brief Shifts the string pointer to the right.
*
* @param length Number of elements to shift
* @return Number of elements shifted.
*/
size_t shiftRight(size_t length);
protected:
T *base; /** Base pointer for the underlying String's memory allocation */
};
}
#include "Shift_String_Imp.h"
#endif // _SHIFT_STRING_H_HEADER

44
Jupiter/Shift_String_Imp.h

@ -0,0 +1,44 @@
/**
* 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 _SHIFT_STRING_IMP_H_HEADER
#define _SHIFT_STRING_IMP_H_HEADER
/**
* @file Shift_String_Imp.h
* @brief Provides the implementations for Shift_String_Type functions.
* Note: Modification of this file is not supported in any way.
*/
template<typename T> size_t Jupiter::Shift_String_Type<T>::shiftLeft(size_t length)
{
size_t offset = Jupiter::String_Type<T>::str - Jupiter::Shift_String_Type<T>::base;
if (length > offset) length = offset;
Jupiter::String_Type<T>::str -= length;
Jupiter::String_Type<T>::length += length;
return length;
}
template<typename T> size_t Jupiter::Shift_String_Type<T>::shiftRight(size_t length)
{
if (length > Jupiter::String_Type<T>::length) length = Jupiter::String_Type<T>::length;
Jupiter::String_Type<T>::str += length;
Jupiter::String_Type<T>::length -= length;
return length;
}
#endif // _SHIFT_STRING_IMP_H_HEADER
Loading…
Cancel
Save