AgentXcpp  Revision:4ac4848
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 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 unsigned long long uint64_t;
00030 
00031 /**
00032  * \brief A type with exactly 8 bits
00033  *
00034  * The char types in C++ (char, unsigned char, signed char) are defined to have 
00035  * <em>at least</em> 8 bits. Although these types probably have 8 bits on 
00036  * virtually every platform, I'm a perfectionist here and define my own type, 
00037  * so that it can be redefined in one central place.
00038  */
00039 typedef unsigned char byte_t; // for machines where unsigned char has 8bits
00040 
00041 /**
00042  * \brief input stream for connection to master agent
00043  *
00044  * This type is used as input stream which is used to receive protocol messages 
00045  * from the master agent.
00046  */
00047 typedef std::basic_istream<byte_t> input_stream;
00048 
00049 /**
00050  * \internal
00051  *
00052  * \brief A type representing a contigous byte stream
00053  */
00054 class data_t : public std::basic_string<byte_t> { };
00055 
00056 inline std::ostream& operator<<(std::ostream& out, const data_t& stream)
00057 {
00058     out << "+----------+----------+----------+----------+" << std::endl;
00059     out << "| ";//begin line
00060     for(size_t i = 0; i < stream.size(); i++)
00061     {
00062         out.width(8);// 8 chars per field
00063         out << (int)stream[i] << " | ";
00064         if( (i+1)%4 == 0 )
00065         {
00066             out << std::endl;   // end line
00067             out << "+----------+----------+----------+----------+";
00068             if( i != stream.size() - 1 )
00069             {
00070                 // We have further data; begin a new line
00071                 out << std::endl << "| ";
00072             }
00073         }
00074     }
00075     out << std::endl;
00076 
00077     return out;
00078 }
00079 
00080 #endif