AgentXcpp  Revision:0.1
Internals Documentation
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends
/home/tanjeff/projekte/agentxcpp/src/types.hpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2011-2012 Tanjeff-Nicolai Moos <tanjeff@cccmz.de>
00003  *
00004  * This file is part of the agentXcpp library.
00005  *
00006  * AgentXcpp is free software: you can redistribute it and/or modify
00007  * it under the terms of the AgentXcpp library license, version 1, which 
00008  * consists of the GNU General Public License and some additional 
00009  * permissions.
00010  *
00011  * AgentXcpp is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * See the AgentXcpp library license in the LICENSE file of this package 
00017  * for more details.
00018  */
00019 #ifndef _TYPES_H_
00020 #define _TYPES_H_
00021 
00022 #include <string>
00023 #include <istream>
00024 #include <ostream>
00025 
00026 typedef unsigned char uint8_t;
00027 typedef unsigned short uint16_t;
00028 typedef unsigned int uint32_t;
00029 typedef signed int int32_t;
00030 typedef unsigned long long uint64_t;
00031 
00032 /**
00033  * \brief A type with exactly 8 bits
00034  *
00035  * The char types in C++ (char, unsigned char, signed char) are defined to have 
00036  * <em>at least</em> 8 bits. Although these types probably have 8 bits on 
00037  * virtually every platform, I'm a perfectionist here and define my own type, 
00038  * so that it can be redefined in one central place.
00039  */
00040 typedef unsigned char byte_t; // for machines where unsigned char has 8bits
00041 
00042 /**
00043  * \brief A type representing a contigous byte stream
00044  */
00045 class data_t : public std::basic_string<byte_t> { };
00046 
00047 inline std::ostream& operator<<(std::ostream& out, const data_t& stream)
00048 {
00049     out << "+----------+----------+----------+----------+" << std::endl;
00050     out << "| ";//begin line
00051     for(size_t i = 0; i < stream.size(); i++)
00052     {
00053         out.width(8);// 8 chars per field
00054         out << (int)stream[i] << " | ";
00055         if( (i+1)%4 == 0 )
00056         {
00057             out << std::endl;   // end line
00058             out << "+----------+----------+----------+----------+";
00059             if( i != stream.size() - 1 )
00060             {
00061                 // We have further data; begin a new line
00062                 out << std::endl << "| ";
00063             }
00064         }
00065     }
00066     out << std::endl;
00067 
00068     return out;
00069 }
00070 
00071 #endif