STK++ 1.0

Subproject STKernel::Base

In the Base subproject, we define. More...

Collaboration diagram for Subproject STKernel::Base:

Classes

struct  STK::IProxy
 The IProxy classes is an interface class for wrapping the fundamental types. More...
class  STK::ConstProxy< TYPE >
 The ConstProxy class allow to surdefine operators and methods for every kind of constant class and type without using dynamic_cast. More...
class  STK::Proxy< TYPE >
 The Proxy classe allow to surdefine operators and methods for every kind of class without using dynamic_cast. More...

Namespaces

namespace  STK::Chrono
 

The namespace Chrono is an utility namespace for computing elapsed time during the execution of a program.


Modules

 Arithmetic properties.
 

These classes extend the numeric_limits C++ struct.


 Runtime Type Identification.
 

These classes allow to handle the Runtime type identification (RTTI) problem and are useful when working with heterogeneous data.


 STKernel::Base I/O stream declarations
 

Nearly all of the I/O classes are parameterized on the type of characters they read and write (The major exception is ios_base at the top of the hierarchy).


Typedefs

typedef char STK::Char
 STK fundamental type of a Char.
typedef long STK::Integer
 STK fundamental type of discrete values.
typedef double STK::Real
 STK fundamental type of Real values.
typedef std::basic_string< Char > STK::String
 STK fundamental type of a String.

Enumerations

enum  STK::Binary { STK::zero = 0, STK::one = 1, STK::binaryNA }
 

STK fundamental type of a binary.

More...
enum  STK::NotAvailable { STK::missing }
 

STK fundamental type of a NA value.

More...
enum  STK::Sign { STK::negative = -1, STK::positive = 1, STK::SignNA }
 

STK fundamental type of a sign.

More...

Functions

void STK::Chrono::start ()
 Start the Chrono.
Real STK::Chrono::elapsed ()
 Compute the elapsed time (in second) since last start() call.
template<class TYPE >
TYPE STK::sign (TYPE const &x, TYPE const &y=1)
 templated sign value sign(x) * y: TYPE should be Integer , long, float or Real
template<class TYPE >
void STK::swap (TYPE &x, TYPE &y)
 templated swap method.
template<class TYPE >
TYPE const & STK::min (TYPE const &x, TYPE const &y)
 templated minimum for class having defined <.
template<class TYPE >
TYPE const & STK::max (TYPE const &x, TYPE const &y)
 templated maximum for class having defined <.
template<class TYPE >
TYPE STK::abs (TYPE const &x)
 templated absolute value: TYPE should be Integer , long, float or Real.
Real STK::frand ()
 frand() generate a Real uniform number.
bool STK::isOdd (Integer const &x)
 is x a odd number ?
bool STK::isEven (Integer const &x)
 is x an even number ?
Integer STK::round (Real const &x)
 Computation of round off : return an Integer value.
Real STK::norm (Real const &x, Real const &y)
 Computation of sqrt(x^2 + y^2) without underflow or overflow.
template<class TYPE >
bool STK::stringToType (TYPE &t, String const &s, std::ios_base &(*f)(std::ios_base &)=std::dec)
 convert a String to TYPE
template<class TYPE >
String STK::typeToString (TYPE const &t, std::ios_base &(*f)(std::ios_base &)=std::dec)
 convert a TYPE to String
template<class TYPE >
ostream & STK::operator<< (ostream &os, const ConstProxy< TYPE > &output)
 Overloading of the operator << for the type TYPE using a constant Proxy.
template<class TYPE >
istream & STK::operator>> (istream &is, Proxy< TYPE > &input)
 Overloading of the operator >> for the type TYPE using a Proxy.
istream & STK::operator>> (istream &is, Proxy< String > &input)
 Overloading of the istream >> for the type String.
String & STK::toUpperString (String &s)
 convert the characters of the String to upper case
String STK::toUpperString (String const &s)
 convert the characters of the String to upper case

Variables

static const String STK::STRING_NA = String(_T("."))
 Representation of a Not Available value.
static const int STK::STRING_NA_SIZE = 1
 Size (in number of Char) of a Not Available value.

Detailed Description

In the Base subproject, we define.


Typedef Documentation

typedef char STK::Char

STK fundamental type of a Char.

The type Char is defined for the internal representation of the characters. Note that if you change the representation, you don't have to modify the stream classes defined in the file STK_StreamBase.h, but you have to modify the global stream objects std::cout, std::cin, std::cerr, std::clog in order to access to the standard I/O channels.

Definition at line 81 of file STK_Char.h.

typedef long STK::Integer

STK fundamental type of discrete values.

The type Integer is defined for the numerical computation and the internal representation of the discrete variables.

Definition at line 50 of file STK_Integer.h.

typedef double STK::Real

STK fundamental type of Real values.

The type Real is defined for the numerical computation and the internal representation of the continuous variables.

Definition at line 51 of file STK_Real.h.

typedef std::basic_string<Char> STK::String

STK fundamental type of a String.

The type String is defined for the internal representation of the string variables (strings).

Definition at line 54 of file STK_String.h.


Enumeration Type Documentation

STK fundamental type of a binary.

The type Binary is a representation of dichotomic variables.

Enumerator:
zero 

zero value

one 

one value

binaryNA 

Not Available value.

Definition at line 52 of file STK_Binary.h.

 { zero =0, 
   one  =1, 
   binaryNA 
 };

STK fundamental type of a NA value.

The type NotAvailable is defined for the numerical computation and the internal representation of the not Available variables. It can be used for any unknown variable.

Enumerator:
missing 

Definition at line 54 of file STK_NotAvailable.h.

{ missing };
enum STK::Sign

STK fundamental type of a sign.

The type Signed is an other representation of dichotomic variables

Enumerator:
negative 

negative sign

positive 

positive sign

SignNA 

Not Available value.

Definition at line 51 of file STK_Sign.h.

 { negative =-1, 
   positive = 1, 
   SignNA     
 };

Function Documentation

void STK::Chrono::start ( )

Start the Chrono.

Definition at line 54 of file STK_Chrono.cpp.

{
Real STK::Chrono::elapsed ( )

Compute the elapsed time (in second) since last start() call.

Returns:
the elapsed time

Definition at line 57 of file STK_Chrono.cpp.

References STK::Chrono::t_end, and STK::Chrono::t_start.

  {
    t_end = clock();
    return Real((t_end - t_start)/CLOCKS_PER_SEC);
  }
} // namespace Chrono
template<class TYPE >
TYPE STK::sign ( TYPE const &  x,
TYPE const &  y = 1 
) [inline]

templated sign value sign(x) * y: TYPE should be Integer , long, float or Real

Parameters:
xthe sign value
ythe signed value to return

Definition at line 59 of file STK_Misc.h.

Referenced by STK::compGivens(), STK::Svd::diag(), STK::EigenvaluesSymmetric::diagonalize(), STK::house(), and STK::RandBase::randGauss().

{ return( (x<0) ? -y : y); }
template<class TYPE >
void STK::swap ( TYPE &  x,
TYPE &  y 
) [inline]

templated swap method.

Parameters:
xthe first value to swap
ythe second value to swap

Definition at line 69 of file STK_Misc.h.

{
  TYPE aux(x);
  x = y;
  y = aux;
}
Real STK::frand ( ) [inline]

frand() generate a Real uniform number.

This is a very basic method and should only be used when speed is necessary only.

Definition at line 111 of file STK_Misc.h.

{ return (Real)rand() / (RAND_MAX+1.0);}
bool STK::isOdd ( Integer const &  x) [inline]

is x a odd number ?

This method return true if the rest of the euclidian division of x by 2 is 0.

Parameters:
xthe value to test
Returns:
true if x is odd, false otherwise

Definition at line 122 of file STK_Misc.h.

Referenced by STK::dot(), and STK::weightedDot().

{ return( (x%2) == 1 ); }
bool STK::isEven ( Integer const &  x) [inline]

is x an even number ?

This method return true if the rest of the euclidian division of x by 2 is 1.

Parameters:
xthe value to test
Returns:
true if x is even, false otherwise

Definition at line 133 of file STK_Misc.h.

Referenced by STK::Funct::gamma().

{ return( (x%2) == 0 ); }
Integer STK::round ( Real const &  x) [inline]

Computation of round off : return an Integer value.

Parameters:
xthe value to round
Returns:
the rouded value of x

Definition at line 142 of file STK_Misc.h.

{ return( x < 0.0 ? Integer(x-0.5) : Integer(x+0.5));}
Real STK::norm ( Real const &  x,
Real const &  y 
) [inline]

Computation of sqrt(x^2 + y^2) without underflow or overflow.

Parameters:
xfirst value
ysecond value
Returns:
the value $ \sqrt(x^2 + y^2) $

Definition at line 152 of file STK_Misc.h.

References STK::abs().

Referenced by STK::Svd::bidiag(), STK::Svd::diag(), STK::EigenvaluesSymmetric::diagonalize(), STK::gramSchmidt(), STK::Svd::leftEliminate(), STK::normTwo(), STK::normTwo2(), STK::Svd::rightEliminate(), and STK::weightedNormTwo2().

{
  Real absx = abs(x), absy = abs(y);
  if (absx > absy)
  {
    return(absx * sqrt(double(1.0+(absy/absx)*(absy/absx))));
  }
  else
  {
    return(absy == 0.0 ? 0.0 : absy * sqrt(double(1.0+(absx/absy)*(absx/absy))));
  }
}
template<class TYPE >
bool STK::stringToType ( TYPE &  t,
String const &  s,
std::ios_base &(*)(std::ios_base &)  f = std::dec 
)

convert a String to TYPE

This method return true if the String s could be converted into a correct TYPE t. http://www.codeguru.com/forum/showpost.php?p=678440&postcount=1 http://c.developpez.com/faq/cpp/?page=strings#STRINGS_is_type

The conversion is successful if it does not remain Char inside the String. The operator >> have been overloaded for each base type in order to return a NA value if fail.

Parameters:
tThe value to get from the String
sthe String to convert
fflags
Returns:
true if the conversion succeed, false otherwise

Definition at line 82 of file STK_String_Util.h.

Referenced by STK::operator>>(), STK::DManager::readList(), and STK::Option::setValue().

{
  istringstream iss(s);
  Proxy<TYPE> wrapper_t(t);
  bool flag1 = (iss >> f >> wrapper_t).fail();
  iss >> std::ws;
  // ok if the conversion success and the String is exhausted
  return ( !flag1 && iss.eof() );
}
template<class TYPE >
String STK::typeToString ( TYPE const &  t,
std::ios_base &(*)(std::ios_base &)  f = std::dec 
)

convert a TYPE to String

This method return the TYPE t into a String s.

See also:
http://www.codeguru.com/forum/showpost.php?p=678440&postcount=1
http://c.developpez.com/faq/cpp/?page=strings#STRINGS_convertform
Parameters:
tThe value to convert to String
fflags

Definition at line 106 of file STK_String_Util.h.

Referenced by STK::ExportToCsv::setColumnsNames().

{
  ostringstream oss;
  oss << f << ConstProxy<TYPE>(t);
  return oss.str();
}
template<class TYPE >
ostream& STK::operator<< ( ostream &  os,
const ConstProxy< TYPE > &  output 
)

Overloading of the operator << for the type TYPE using a constant Proxy.

All output stream should use a ConstProxy in a STK application. For the enumerated types, we have also to define the standard output.

Parameters:
osthe output stream
outputthe value to send to the stream

Definition at line 124 of file STK_String_Util.h.

References STK::STRING_NA.

{ if (Arithmetic<TYPE>::isNA(output))
    return (os <<  STRING_NA);
  else
   return (os << static_cast<TYPE const &>(output));
}
template<class TYPE >
istream& STK::operator>> ( istream &  is,
Proxy< TYPE > &  input 
)

Overloading of the operator >> for the type TYPE using a Proxy.

All input stream should use a Proxy in a STK application. For the enumerated and String types, we have to overload the method. Due to the instruction

   is >> buff

this operator will only work for the fundamental C/C++ types. For the other types, the operator

  operator >> (istream& is, TYPE& input);

have to be implemented.

Parameters:
isthe input stream
inputthe value to get from the stream

Definition at line 150 of file STK_String_Util.h.

References STK::Arithmetic< TYPE >::NA(), STK::STRING_NA, and STK::STRING_NA_SIZE.

{
  TYPE buff;
  // get current position in the stream
  typename std::ios::pos_type pos = is.tellg();

  // If the standard Conversion failed
  if ((is >> buff).fail())
  {
    // clear failbit state
    is.clear(is.rdstate() & ~std::ios::failbit);
    // clear eofbit state if necessary and rewind position
    if (is.eof())
    {
      is.seekg(pos);
      is.clear(is.rdstate() & ~std::ios::eofbit);
    }
    // in all case input is a NA object
    input = Arithmetic<TYPE>::NA();

    // get current position in the stream
    pos = is.tellg();

    // Create a String buffer
    Char Lbuff[STRING_NA_SIZE+1];

    // try to read a NA String
    is.getline(Lbuff, STRING_NA_SIZE+1);

    // if we don't get a NA String, rewind stream
    if (!(STRING_NA.compare(Lbuff) == 0))
    { is.seekg(pos);}
  }
  else
  { input = buff;}
  // return the stream
  return is;
}
istream & STK::operator>> ( istream &  is,
Proxy< String > &  input 
)

Overloading of the istream >> for the type String.

Parameters:
isthe input stream
inputthe value to get from the stream

Definition at line 42 of file STK_String_Util.cpp.

References STK::Arithmetic< TYPE >::NA(), and STK::STRING_NA.

{
  String buff;
  is >> buff;
  if (buff  == STRING_NA)
    input = Arithmetic<String>::NA();
  else
    input = buff;
  return is;
}
String & STK::toUpperString ( String &  s)

convert the characters of the String to upper case

Parameters:
sThe String to convert
Returns:
the string converted to upper case

Definition at line 59 of file STK_String_Util.cpp.

Referenced by STK::DManager::checkStringToBoolean(), STK::IPage::findKeyword(), STK::IPage::IPage(), STK::Option::Option(), STK::IPage::option(), STK::ReadWritePages::p_page(), STK::IPage::processLine(), STK::DManager::StringToBoolean(), STK::StatModel::StringToTypeCriterion(), STK::Import::StringToTypeImport(), STK::Reduct::StringToTypeReduction(), STK::Regress::StringToTypeRegression(), and STK::toUpperString().

{
  // iterate along the String
  for (String::iterator it = s.begin(); it != s.end(); ++it)
  { *it = std::toupper(*it);}
  // return upper cased string
 return s;
}
String STK::toUpperString ( String const &  s)

convert the characters of the String to upper case

Parameters:
sThe String to convert
Returns:
a String in upper case

Definition at line 73 of file STK_String_Util.cpp.

References STK::toUpperString().

{
  String res(s);
  toUpperString(res);
  return res;
}

Variable Documentation

const String STK::STRING_NA = String(_T(".")) [static]

Representation of a Not Available value.

We represent a Not Available value of any type as a "." (like in (SAS(R))) for the end-user.

Definition at line 53 of file STK_String_Util.h.

Referenced by STK::operator<<(), STK::operator>>(), STK::Option::setDefaultValue(), and STK::ReadWriteCsv::writeSelection().

const int STK::STRING_NA_SIZE = 1 [static]

Size (in number of Char) of a Not Available value.

We represent a Not Available value of any type as a "." (like in (SAS(R))) for the end-user.

Definition at line 61 of file STK_String_Util.h.

Referenced by STK::operator>>().