Main   Namespaces   Classes   Hierarchy   Annotated   Files   Compound   Global   Pages  

Misc.hpp

Go to the documentation of this file.
00001 //----------------------------------------------------------------------------
00002 /** @file Misc.hpp
00003  */
00004 //----------------------------------------------------------------------------
00005 
00006 #ifndef MISC_HPP
00007 #define MISC_HPP
00008 
00009 #include <sstream>
00010 #include <string>
00011 #include <vector>
00012 #include "Benzene.hpp"
00013 #include "Types.hpp"
00014 
00015 _BEGIN_BENZENE_NAMESPACE_
00016 
00017 //----------------------------------------------------------------------------
00018 
00019 /** Misc. Utilities. */
00020 namespace MiscUtil
00021 {
00022     /** Converts a word to an array of bytes. */
00023     void WordToBytes(unsigned word, byte* out);
00024 
00025     /** Converts an array of four bytes into a word. */
00026     unsigned BytesToWord(const byte* bytes);
00027 
00028     /** Returns the number of bytes need to hold the given number of
00029         bits. Equal to (bits + 7)/8.
00030      */
00031     int NumBytesToHoldBits(int bits);
00032 
00033     /** Prints a vector with a space between elements. */
00034     template<typename TYPE>
00035     std::string PrintVector(const std::vector<TYPE>& v);
00036 }
00037 
00038 /** Prints a vector with a space between elements. */
00039 template<typename TYPE>
00040 std::string MiscUtil::PrintVector(const std::vector<TYPE>& v)
00041 {
00042     std::ostringstream is;
00043     for (std::size_t i=0; i<v.size(); ++i) {
00044         if (i) is << ' ';
00045         is << v[i];
00046     }
00047     return is.str();
00048 } 
00049 
00050 //----------------------------------------------------------------------------
00051 
00052 _END_BENZENE_NAMESPACE_
00053 
00054 #endif // MISC_HPP


6 Jan 2011 Doxygen 1.6.3