X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=include%2Fanna%2Fcore%2Futil%2Fdefines.hpp;h=cd846a3d0d6131a0470448043a1254c2bce22b0c;hb=5a6cba5fde2b2f538a7515f8293cc0a8d9589dfa;hp=a5c5bc7047dd8af05c598756e7a2f36c8a208c80;hpb=3e258840b15577cb8bda3cdedd0b9b88e16404b3;p=anna.git diff --git a/include/anna/core/util/defines.hpp b/include/anna/core/util/defines.hpp index a5c5bc7..cd846a3 100644 --- a/include/anna/core/util/defines.hpp +++ b/include/anna/core/util/defines.hpp @@ -1,37 +1,9 @@ -// ANNA - Anna is Not Nothingness Anymore -// -// (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo -// -// https://bitbucket.org/testillano/anna -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -// Authors: eduardo.ramos.testillano@gmail.com -// cisco.tierra@gmail.com +// ANNA - Anna is Not Nothingness Anymore // +// // +// (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo // +// // +// See project site at http://redmine.teslayout.com/projects/anna-suite // +// See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE // #ifndef anna_core_util_defines_hpp @@ -44,6 +16,12 @@ #include +#include +// For cstd0x compatibility we will use stdint.h types instead of std:: ones on cstdint: +//#include when C++11 available + +// For xml representations (xml::Compiler and json::functions::json2xml) +#define ANNA_XML_INDENTATION_SPACES 3 // Decoding helpers @@ -58,78 +36,52 @@ namespace anna { -// type bits (bytes) % Diameter Data typedef -// ----------------------------------------------------------------------- -// unsigned short int 16 (2) hu U16 -// short int 16 (2) hd S16 -// unsigned int 32 (4) u Unsigned32 (*) U32 -// int 32 (4) d Integer32 (*) S32 -// -// Integer. Its length traditionally depends on the length of the system's Word type, thus in MSDOS -// it is 16 bits long, whereas in 32 bit systems (like Windows 9x/2000/NT and systems that work under -// protected mode in x86 systems) it is 32 bits long (4 bytes) -// -// Como está previsto que en algunas máquinas la palabra sea de 16 bits, los enteros serían -// de 16 y por ello C contempla: int (serían 16 bits), long int (32), long long int (64). Sin embargo -// en la práctica, 'int = long int = 32' y 'long long int = 64'. -// -// (*) Por un mal hábito, representamos enteros de 32 bits con el tipo 'int'/'unsigned int' de -// toda la vida, sin darnos cuenta de que en alguna máquina antigua, no tendría 32 bits. -// Corregir lo anterior sería tan sencillo como poner S32 = long int (no int), -// y U32 = unsigned long int (no unsigned int). Pero no lo vamos a hacer. -// -// El tipo 'long' tiene un tamaño que corresponde con el ancho de palabra del S.O. -// En Solaris (palabra de 64) tenemos long = 64 = long long -// En linux (palabra de 32) tenemos long = 32, long long = 64 -// En linux64 (palabra de 64) tenemos long = 64 = long long -// +#ifndef __x86_64__ +#undef __anna64__ +#else +#define __anna64__ +#endif + +// TYPE BITS (bytes) Format +// ----------------------- ------------------ --------------------------- // unsigned long int 32/64 (4/8) lu // long int 32/64 (4/8) ld // -// unsigned long long int 64 (8) llu Unsigned64 U64 -// long long int 64 (8) lld Integer64 S64 +// unsigned long long int 64 (8) llu +// long long int 64 (8) lld // // float 32 (4) f // double 64 (8) lf // long double 80 (10) Lf +// +// pointer = S.O. word 32/64 p -/** Alias for unsigned char: unsigned integer with 8 bits */ +/** Alias for unsigned integer with 8 bits */ +//typedef uint8_t U8; typedef unsigned char U8; -/** Alias for char: signed integer with 8 bits */ +/** Alias for signed integer with 8 bits */ +//typedef int8_t S8; typedef char S8; -/** Alias for unsigned short int: unsigned integer with 16 bits */ -typedef unsigned short int U16; +/** Alias for unsigned integer with 16 bits */ +typedef uint16_t U16; -/** Alias for short int: signed integer with 16 bits */ -typedef short int S16; +/** Alias for signed integer with 16 bits */ +typedef int16_t S16; -/** Alias for unsigned int: unsigned integer with 32 bits */ -typedef unsigned int U32; +/** Alias for unsigned integer with 32 bits */ +typedef uint32_t U32; -/** Alias for int: signed integer with 32 bits */ -typedef int S32; +/** Alias for signed integer with 32 bits */ +typedef int32_t S32; -///** Alias for unsigned long long: unsigned integer with 64 bits */ -//typedef unsigned long long int U64; -// -///** Alias for long long: signed integer with 64 bits */ -//typedef long long int S64; -#ifndef __x86_64__ -#undef __anna64__ -/** Alias for long long: signed integer with 64 bits */ -typedef int64_t S64 -/** Alias for unsigned long long: unsigned integer with 64 bits */ -typedef u_int64_t U64; -#else -#define __anna64__ -/** Alias for long long: signed integer with 64 bits */ -typedef long long int S64; -/** Alias for unsigned long long: unsigned integer with 64 bits */ -typedef unsigned long long int U64; -#endif +/** Alias for unsigned integer with 64 bits */ +typedef uint64_t U64; + +/** Alias for signed integer with 64 bits */ +typedef int64_t S64; /** Alias for float: floating number with 32 bits (1-8-23) */ typedef float F32; @@ -137,7 +89,10 @@ typedef float F32; /** Alias for double: floating number with 64 bits (1-11-52) */ typedef double F64; -/** Alias for unsigned int: unsigned integer with 32 bits used to contain 24 bits */ +/** Alias for long double: floating number with 80 bits (1-15-64) */ +typedef long double F80; + +/** Alias for unsigned integer with 32 bits used to contain 24 bits */ typedef U32 U24; @@ -466,7 +421,7 @@ typedef struct { * @param v Version type * @return Version description */ - static const char* asText(const _v v) throw() { // anna_declare_enum is not safe, because labels don't have to match a sequence + static const char* asText(const _v v) { // anna_declare_enum is not safe, because labels don't have to match a sequence if(v == IPv4) return "IPv4"; if(v == IPv6) return "IPv6"; @@ -492,29 +447,29 @@ typedef struct { /** Gets the address version */ - const U16 & getVersion() const throw() { return Version; } + const U16 & getVersion() const { return Version; } /** Gets the address printable value */ - const char * getValue() const throw() { return Value.c_str(); } + const char * getValue() const { return Value.c_str(); } // Helpers /** Return true when is an IPv4 address */ - bool isIPv4() const throw() { return ((iana_address_version_t::_v)Version == iana_address_version_t::IPv4); } + bool isIPv4() const { return ((iana_address_version_t::_v)Version == iana_address_version_t::IPv4); } /** Return true when is an IPv6 address */ - bool isIPv6() const throw() { return ((iana_address_version_t::_v)Version == iana_address_version_t::IPv6); } + bool isIPv6() const { return ((iana_address_version_t::_v)Version == iana_address_version_t::IPv6); } /** Return true when is an E164 (SMDS, Frame Relay, ATM) address */ - bool isE164() const throw() { return ((iana_address_version_t::_v)Version == iana_address_version_t::E164); } + bool isE164() const { return ((iana_address_version_t::_v)Version == iana_address_version_t::E164); } /** Sets version for IPv4 address and address itself. Checking is not performed (could assign IPv6 instead ...) */ - void setIPv4(const char *value) throw() { Version = iana_address_version_t::IPv4; Value = value ? value : ""; } + void setIPv4(const char *value) { Version = iana_address_version_t::IPv4; Value = value ? value : ""; } /** Sets version for IPv6 address and address itself. Checking is not performed (could assign IPv4 instead ...) */ - void setIPv6(const char *value) throw() { Version = iana_address_version_t::IPv6; Value = value ? value : ""; } + void setIPv6(const char *value) { Version = iana_address_version_t::IPv6; Value = value ? value : ""; } /** Sets version for E164 address and address itself. Checking is not performed ... */ - void setE164(const char *value) throw() { Version = iana_address_version_t::E164; Value = value ? value : ""; } + void setE164(const char *value) { Version = iana_address_version_t::E164; Value = value ? value : ""; } /** @@ -522,7 +477,7 @@ typedef struct { * * @return String with class content */ - std::string asString() const throw() { + std::string asString() const { std::string result; result += Value.c_str(); // assume that all IANA addresses have a printable representation result += " (";