utils.hpp File Reference

LibNebular, Some useful stuff. More...

#include "config.h"
#include <stdexcept>
#include <iostream>
#include <string>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <csetjmp>
#include <boost/shared_ptr.hpp>
#include <loki/Functor.h>
Include dependency graph for utils.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  HexInteger< Integer >
 Analogue of Integer that uses redefined for hexadecimal output operator<<(std::ostream &, const HexInteger<Integer> &). More...
struct  null_deleter
 Deleter which does nothing. More...
class  CArrayOfArrayDeleter
 Deleter for C-style array of C-style arrays. More...
class  CFileWrapper
 Wraps C-style FILE structure. More...
struct  CFileWrapper::CFileDeleter
 Deleter for C-style FILE structure.

Defines

#define LOKI_ENABLE_FUNCTION
#define LOKI_FUNCTOR_IS_NOT_A_SMALLOBJECT
#define TODO_HERE(x)
 Doesn't do anything with x and writes to std::clog "TODO" with location info.
#define TODO(x)
 Doesn't evaluate x and writes to std::clog "TODO" with location info and x in literal form.
#define TRACE(x)   std::clog << "\"" << #x << "\" = \"" << x << "\"" << std::endl
 Traces to std::clog: x in literal form and value of x evaluated.
#define ARRAY_SIZE(a)   ( (sizeof( (a) )/sizeof( (a)[0])) )
 Array size of one-dimensional C-style array.

Functions

template<typename Integer >
std::ostream & operator<< (std::ostream &aOstream, const HexInteger< Integer > &x)
 Output Integer with hexadecimal representation enabled.
template<typename Integer >
Integer roundDiv (Integer a, Integer b)
 Division of positive a by positive b with rounding of result to nearest integer.
template<typename T >
std::istream & readBin (std::istream &inStream, T &field)
 Reads field of arbitrary type T as binary data from std::istream.
template<typename T >
std::ostream & writeBin (std::ostream &outStream, T &field)
 Writes field of arbitrary type T as binary data to std::istream.
template<typename Integer >
Integer checkedDivByMultiple (Integer a, Integer b)
 Division of integer a to its multiple b which checks that b is really multiple.
template<typename Integer >
Integer checkedBitsToIntBytes (Integer bits)
 Conversion from bit count to byte count which checks that number of bits is a multiple of bitsPerByte.
template<typename Out >
Out getBytes (const char *whereFrom, int numBytes)
 Safely gets numBytes from memory region whereFrom.
template<typename In >
void setBytes (char *whereTo, int numBytes, In newValue)
 Safely sets numBytes from memory region whereTo to newValue.
template<typename In >
std::string lexicalCastToStdString (In a)
 Does "lexical cast" to std::string.

Variables

const char bitsPerByte = 8

Detailed Description

LibNebular, Some useful stuff.

Copyright (C) 2011 Leonid Sadikov ⟨ leonius@inbox.ru

This file is part of LibNebular.

LibNebular is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 3 as published by the Free Software Foundation.

See "COPYING.LESSER" and "COPYING" in distribution or ⟨http://www.gnu.org/licenses/⟩ for full license text.

Author:
Leonid Sadikov ( leonius@inbox.ru )
Date:
Created: 19 Mar 2011

Definition in file utils.hpp.


Define Documentation

#define ARRAY_SIZE (  )     ( (sizeof( (a) )/sizeof( (a)[0])) )

Array size of one-dimensional C-style array.

Definition at line 297 of file utils.hpp.

#define LOKI_ENABLE_FUNCTION

Definition at line 40 of file utils.hpp.

#define LOKI_FUNCTOR_IS_NOT_A_SMALLOBJECT

Definition at line 41 of file utils.hpp.

#define TODO (  ) 
Value:
{                                                           \
    std::clog << std::string("TODO: ") +                                    \
    "in function \"" + __PRETTY_FUNCTION__ +                                \
    "\", file \"" + __FILE__ +                                              \
    "\" at line " + lexicalCastToStdString(__LINE__) +                      \
    ": \n" + #x << std::endl; }                                         \
while(false)

Doesn't evaluate x and writes to std::clog "TODO" with location info and x in literal form.

Definition at line 285 of file utils.hpp.

#define TODO_HERE (  ) 
Value:
{                                                   \
    std::clog << std::string("TODO: ") +                                    \
    "in function \"" + __PRETTY_FUNCTION__ +                                \
    "\", file \"" + __FILE__ +                                              \
    "\" at line " + lexicalCastToStdString(__LINE__) <<                 \
    std::endl; }                                                            \
while(false)

Doesn't do anything with x and writes to std::clog "TODO" with location info.

Definition at line 276 of file utils.hpp.

#define TRACE (  )     std::clog << "\"" << #x << "\" = \"" << x << "\"" << std::endl

Traces to std::clog: x in literal form and value of x evaluated.

Definition at line 294 of file utils.hpp.


Function Documentation

template<typename Integer >
Integer checkedBitsToIntBytes ( Integer  bits  )  [inline]

Conversion from bit count to byte count which checks that number of bits is a multiple of bitsPerByte.

Definition at line 223 of file utils.hpp.

Here is the call graph for this function:

Here is the caller graph for this function:

template<typename Integer >
Integer checkedDivByMultiple ( Integer  a,
Integer  b 
) [inline]

Division of integer a to its multiple b which checks that b is really multiple.

Definition at line 215 of file utils.hpp.

Here is the caller graph for this function:

template<typename Out >
Out getBytes ( const char *  whereFrom,
int  numBytes 
) [inline]

Safely gets numBytes from memory region whereFrom.

Safety means that there won't be read of bytes that we don't need. (That's to protect read from "going through boundary" and probable consequent segmentation fault.)

Definition at line 230 of file utils.hpp.

template<typename In >
std::string lexicalCastToStdString ( In  a  )  [inline]

Does "lexical cast" to std::string.

Definition at line 269 of file utils.hpp.

template<typename Integer >
std::ostream& operator<< ( std::ostream &  aOstream,
const HexInteger< Integer > &  x 
) [inline]

Output Integer with hexadecimal representation enabled.

See also:
HexInteger

Definition at line 68 of file utils.hpp.

template<typename T >
std::istream& readBin ( std::istream &  inStream,
T &  field 
) [inline]

Reads field of arbitrary type T as binary data from std::istream.

Definition at line 199 of file utils.hpp.

template<typename Integer >
Integer roundDiv ( Integer  a,
Integer  b 
) [inline]

Division of positive a by positive b with rounding of result to nearest integer.

If fraction is half, rounds to nearest even

Definition at line 177 of file utils.hpp.

Here is the caller graph for this function:

template<typename In >
void setBytes ( char *  whereTo,
int  numBytes,
In  newValue 
) [inline]

Safely sets numBytes from memory region whereTo to newValue.

About safety:

See also:
getBytes()

Definition at line 253 of file utils.hpp.

Here is the caller graph for this function:

template<typename T >
std::ostream& writeBin ( std::ostream &  outStream,
T &  field 
) [inline]

Writes field of arbitrary type T as binary data to std::istream.

Definition at line 207 of file utils.hpp.


Variable Documentation

const char bitsPerByte = 8

Definition at line 49 of file utils.hpp.

Generated on Sun May 29 18:23:53 2011 for libnebular by  doxygen 1.6.3