IBR-DTNSuite
0.8
|
00001 /* 00002 * Copyright 2005-2006 Intel Corporation 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 * 00016 * THIS FILE BASES ON DTN_2.4.0/SERVLIB/BUNDLING/SDNV.H 00017 */ 00018 00019 #include <sys/types.h> 00020 #include <iostream> 00021 #include <stdio.h> 00022 00023 #ifndef _SDNV_H_ 00024 #define _SDNV_H_ 00025 00044 namespace dtn 00045 { 00046 namespace data 00047 { 00048 class SDNV 00049 { 00050 public: 00055 static const size_t MAX_LENGTH = 10; 00056 00061 SDNV(const u_int64_t value); 00062 00066 SDNV(); 00067 00072 ~SDNV(); 00073 00078 size_t getLength() const; 00079 00080 static size_t getLength(const u_int64_t &value); 00081 static size_t getLength(const unsigned char *data); 00082 00087 u_int64_t getValue() const; 00088 00095 size_t decode(const char *data, const size_t len); 00096 00103 size_t encode(char *data, const size_t len) const; 00104 00105 size_t operator=(const size_t &value); 00106 00107 bool operator==(const SDNV &value) const; 00108 bool operator!=(const SDNV &value) const; 00109 00110 SDNV operator+(const SDNV &value); 00111 SDNV& operator+=(const SDNV &value); 00112 00113 SDNV operator-(const SDNV &value); 00114 SDNV& operator-=(const SDNV &value); 00115 00116 bool operator&(const size_t &value) const; 00117 00118 bool operator<(const SDNV &value) const; 00119 bool operator<=(const SDNV &value) const; 00120 bool operator>(const SDNV &value) const; 00121 bool operator>=(const SDNV &value) const; 00122 00123 private: 00124 friend std::ostream &operator<<(std::ostream &stream, const dtn::data::SDNV &obj); 00125 friend std::istream &operator>>(std::istream &stream, dtn::data::SDNV &obj); 00126 00127 // INLINE-FUNCTIONS 00128 inline static size_t encoding_len(u_int16_t val){ return encoding_len((u_int64_t)val); } 00129 inline static size_t encoding_len(u_int32_t val){ return encoding_len((u_int64_t)val); } 00130 inline static int encode(u_int16_t val, char* bp, size_t len){ return encode((u_int64_t)val, (u_char*)bp, len); } 00131 inline static int encode(u_int32_t val, char* bp, size_t len){ return encode((u_int64_t)val, (u_char*)bp, len); } 00132 inline static int encode(u_int64_t val, char* bp, size_t len){ return encode(val, (u_char*)bp, len); } 00133 inline static int encode(float val, char* bp, size_t len){ return encode(val, (u_char*)bp, len); } 00134 inline static int decode(char* bp, size_t len, u_int64_t* val){ return decode((u_char*)bp, len, val); } 00135 inline static int decode(char* bp, size_t len, u_int32_t* val){ return decode((u_char*)bp, len, val); } 00136 00137 static size_t encoding_len(u_int64_t val); 00138 static size_t encoding_len(float val_f); 00139 static int encode(u_int64_t val, u_char* bp, size_t len); 00140 static int encode(float val_f, u_char* bp, size_t len); 00141 static int decode(const u_char* bp, size_t len, float* val_f); 00142 static int decode(const u_char* bp, size_t len, u_int64_t* val); 00143 static int decode(const u_char* bp, size_t len, u_int32_t* val); 00144 static int decode(const u_char* bp, size_t len, u_int16_t* val); 00145 static size_t len(const u_char* bp); 00146 00147 u_int64_t _value; 00148 }; 00149 } 00150 } 00151 00152 #endif /* _SDNV_H_ */