gpucalc::auxillary::StringUtil Class Reference

Simple wrapper for converting different vaules to its string representation. More...

#include <string_util.h>

List of all members.

Static Public Member Functions

static std::string concatenate (const StringList &sList, const std::string &Delimiter="\n")
 Concatenate strings into one string with given delimiter.
template<typename T>
static void fromString (const std::string &str, T &Value)
static std::string getFixedString (const std::string &String, unsigned int FixedStrLength, const std::string &Prefix="", const std::string &Suffix="")
static std::string getLine (const std::string &Source, size_t Line)
 Returns one line from string source.
static StringList split (const std::string &String, const std::string &Delimiter="\n")
 Split string with delimiter.
static std::string toLower (const std::string &Value)
 Transform string to lowercase.
static std::string toString (const Object &Value)
 Redefine base method for Object values.
static std::string toString (const ValueType &Value)
 Redefine base method for ValueType values.
static std::string toString (const bool &Value)
 Redefine base method for boolean values.
template<typename T>
static std::string toString (const T &Value)
 Base method for converting values to string.
static std::string toUpper (const std::string &Value)
 Transform string to uppercase.

Private Member Functions

 StringUtil ()
 ~StringUtil ()


Detailed Description

Simple wrapper for converting different vaules to its string representation.

Definition at line 54 of file string_util.h.


Constructor & Destructor Documentation

gpucalc::auxillary::StringUtil::StringUtil (  )  [private]

gpucalc::auxillary::StringUtil::~StringUtil (  )  [private]


Member Function Documentation

static std::string gpucalc::auxillary::StringUtil::concatenate ( const StringList sList,
const std::string &  Delimiter = "\n" 
) [inline, static]

Concatenate strings into one string with given delimiter.

Definition at line 223 of file string_util.h.

00224     {
00225      std::ostringstream s;
00226      std::copy(sList.begin(), sList.end(), std::ostream_iterator<std::string>(s, Delimiter.c_str()));
00227      return s.str();
00228     }

template<typename T>
static void gpucalc::auxillary::StringUtil::fromString ( const std::string &  str,
T &  Value 
) [inline, static]

Definition at line 96 of file string_util.h.

00097     {
00098      std::istringstream s(str);
00099      //s.get(str.c_str(), str.length());
00100      s >> Value;
00101     }

static std::string gpucalc::auxillary::StringUtil::getFixedString ( const std::string &  String,
unsigned int  FixedStrLength,
const std::string &  Prefix = "",
const std::string &  Suffix = "" 
) [inline, static]

Definition at line 231 of file string_util.h.

00232                 {
00233                     std::string result;
00234                     unsigned int length = String.length();
00235                     if (length < (FixedStrLength - 1))
00236                     {
00237                         result = String + std::string(FixedStrLength - length, ' ');
00238                     }
00239                     else
00240                     {
00241                         result = std::string(String, 0, FixedStrLength - 4) + "... ";
00242                     }
00243                     return Prefix + result + Suffix;
00244                 }

static std::string gpucalc::auxillary::StringUtil::getLine ( const std::string &  Source,
size_t  Line 
) [inline, static]

Returns one line from string source.

It is faster than StringUtil::split(Source)[Line], but if you need all strings, it is better to use StringUtil::split(Source)

Definition at line 178 of file string_util.h.

00179     {
00180      std::string::size_type i_old = 0;
00181      std::string::size_type i_new = Source.find("\n");
00182      unsigned int Counter = 0;
00183      while (i_new != std::string::npos)
00184      {
00185       if (Line == Counter)
00186       {
00187        return std::string(Source, i_old, i_new - i_old);
00188       }
00189       i_old = i_new + 1;
00190       i_new = Source.find("\n", i_old);
00191       ++Counter;
00192      }
00193      Except<ERR_ITEM_NOT_FOUND>(Object("StringUtil", "StringUtil"), "Line number is not correct",
00194       "StringUtil::getLineFromSource", __FILE__, __LINE__);
00195     }

static StringList gpucalc::auxillary::StringUtil::split ( const std::string &  String,
const std::string &  Delimiter = "\n" 
) [inline, static]

Split string with delimiter.

Definition at line 201 of file string_util.h.

00202     {
00203      StringList result;
00204      std::string::size_type i_old = 0;
00205      std::string::size_type i_new = String.find(Delimiter);
00206      while (i_new != std::string::npos)
00207      {
00208       std::string temp(String, i_old, i_new - i_old);
00209       result.push_back(temp);
00210       i_old = i_new + Delimiter.length();
00211       i_new = String.find(Delimiter, i_old);
00212      }
00213      std::string temp(String, i_old, i_new - i_old);
00214      result.push_back(temp);
00215 
00216      return result;
00217     }

static std::string gpucalc::auxillary::StringUtil::toLower ( const std::string &  Value  )  [inline, static]

Transform string to lowercase.

Definition at line 154 of file string_util.h.

00155     {
00156      std::string result(Value);
00157      std::transform(Value.begin(), Value.end(), result.begin(), tolower);
00158      return result;
00159     }

static std::string gpucalc::auxillary::StringUtil::toString ( const Object Value  )  [inline, static]

Redefine base method for Object values.

Definition at line 145 of file string_util.h.

00146     {
00147      return "Object with class name: \"" + Value.getClassName() + "\". And with object name: \"" + Value.getObjectName() + "\"";
00148     }

static std::string gpucalc::auxillary::StringUtil::toString ( const ValueType Value  )  [inline, static]

Redefine base method for ValueType values.

Definition at line 107 of file string_util.h.

00108     {
00109      switch (Value)
00110      {
00111       case FloatType:
00112        return "Single precision floating point type";
00113        break;
00114 
00115       case DoubleType:
00116        return "Double precision floating point type";
00117        break;
00118 
00119       case IntType:
00120        return "Signed integer type";
00121        break;
00122 
00123       case UnsignedIntType:
00124        return "Unsigned integer type";
00125        break;
00126 
00127       case CharType:
00128        return "Signed character type";
00129        break;
00130 
00131       case UnsignedCharType:
00132        return "Unsigned character type";
00133        break;
00134 
00135       default:
00136        return "Not correct type";
00137        break;
00138      }
00139     }

static std::string gpucalc::auxillary::StringUtil::toString ( const bool &  Value  )  [inline, static]

Redefine base method for boolean values.

Definition at line 83 of file string_util.h.

00084     {
00085      if (Value)
00086      {
00087       return std::string("true");
00088      }
00089      else
00090      {
00091       return std::string("false");
00092      }
00093     }

template<typename T>
static std::string gpucalc::auxillary::StringUtil::toString ( const T &  Value  )  [inline, static]

Base method for converting values to string.

Definition at line 72 of file string_util.h.

00073     {
00074      std::ostringstream s;
00075      s << Value;
00076      return s.str();
00077     }

static std::string gpucalc::auxillary::StringUtil::toUpper ( const std::string &  Value  )  [inline, static]

Transform string to uppercase.

Definition at line 165 of file string_util.h.

00166     {
00167      std::string result(Value);
00168      std::transform(Value.begin(), Value.end(), result.begin(), toupper);
00169      return result;
00170     }


The documentation for this class was generated from the following file:

Generated on Thu Mar 5 22:36:46 2009 for gpucalc by  doxygen 1.5.6