00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _GLASS_TYPES_HH_
00022 #define _GLASS_TYPES_HH_
00023
00024 #include <string>
00025 #include <limits.h>
00026 #include "msvc.h"
00027
00028 namespace libglass {
00029
00030 class chain;
00031
00035 typedef enum { None = 0, Server, Client, Peer } nodeRelation;
00036
00040 typedef std::string string;
00041
00048
00049 #define PluginId std::string
00050
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00072 typedef int nodeFD;
00073
00074 # define GLASS_ERROR_FD (-1)
00075 # define GLASS_SOCKET_ERROR (-1)
00076
00077 const nodeFD nobodyFD = -1;
00078 const nodeFD everybodyFD = -2;
00079
00080
00081
00088 typedef unsigned int nodeId;
00089
00093 const nodeId nobodyId = 0;
00094
00098 const nodeId everybodyId = 1;
00099
00103 const nodeId serversId = 2;
00104
00108 const nodeId clientsId = 3;
00109
00113 const nodeId peersId = 4;
00114
00118 const nodeId firstId = 5;
00119
00123 const nodeId maxId = UINT_MAX;
00124
00128 inline unsigned int charToNum(unsigned char buf[4]) {
00129 return (((unsigned int)buf[0]) << 24) +
00130 (((unsigned int)buf[1]) << 16) +
00131 (((unsigned int)buf[2]) << 8) +
00132 (unsigned int)buf[3];
00133 }
00134
00138 inline void numToChar(unsigned int num, unsigned char buf[4]) {
00139 buf[0] = (unsigned char)((num >> 24) & 0xFF);
00140 buf[1] = (unsigned char)((num >> 16) & 0xFF);
00141 buf[2] = (unsigned char)((num >> 8) & 0xFF);
00142 buf[3] = (unsigned char)(num & 0xFF);
00143 }
00144
00145 inline void numToChar(unsigned int num, char buf[4]) {
00146 buf[0] = (unsigned char)((num >> 24) & 0xFF);
00147 buf[1] = (unsigned char)((num >> 16) & 0xFF);
00148 buf[2] = (unsigned char)((num >> 8) & 0xFF);
00149 buf[3] = (unsigned char)(num & 0xFF);
00150 }
00151
00155 inline void shortToChar(unsigned short num, unsigned char buf[2]) {
00156 buf[0] = (unsigned char)((num >> 8) & 0xFF);
00157 buf[1] = (unsigned char)(num & 0xFF);
00158 }
00159
00160 inline unsigned short charToShort(unsigned char buf[2]) {
00161 return (((unsigned int)buf[0]) << 8) +
00162 (unsigned int)buf[1];
00163 }
00164
00169 class StringPointerCompare {
00170 public:
00177 int operator() (const string *x, const string *y) const {
00178 return *x < *y;
00179 }
00180 };
00185 class ConstStringPointerCompare {
00186 public:
00193 int operator() (const string *const x, const string *const y) const {
00194 return *x < *y;
00195 }
00196 };
00197
00198
00199
00200
00201
00202
00203
00204 }
00205
00206 #endif // _GLASS_TYPES_HH_