BinaryValue.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00024 #include <iterator>
00025
00026 #include "BinaryValue.h"
00027
00028 using namespace std;
00029
00030
00031 const BinaryValue BinaryValue::UNSPECIFIED_VALUE;
00032
00033 BinaryValue::BinaryValue(const char* s): vector<char>(strlen(s))
00034 {
00035 copy(s, s+strlen(s), begin());
00036 }
00037
00038 BinaryValue::BinaryValue(size_t n): vector<char>(n)
00039 {
00040 }
00041
00042 BinaryValue::BinaryValue(const std::string& str)
00043 {
00044 *this = BinaryValue(str.c_str());
00045 }
00046
00047 BinaryValue::BinaryValue(const std::vector<char>& v) : vector<char>(v)
00048 {
00049 };
00050
00051 BinaryValue::BinaryValue(const char* b, const char* e) : vector<char>(b, e)
00052 {
00053 };
00054
00055 BinaryValue& BinaryValue::operator+=(const BinaryValue& rhs)
00056 {
00057 insert(end(), rhs.begin(), rhs.end());
00058 return *this;
00059 }
00060
00061 bool BinaryValue::isUnspecified() const
00062 {
00063 return empty();
00064 }
00065
00066
00067 std::ostream& operator << (std::ostream& os, const BinaryValue& v) {
00068 copy(v.begin(), v.end(), ostream_iterator<char>(os, ""));
00069 return os;
00070 }
00071
00072 bool BinaryValue::operator<(const BinaryValue& rhs)
00073 {
00074 size_type minSize = min(this->size(), rhs.size());
00075 for (size_type i=0; i<minSize; i++) {
00076 if ((*this)[i] < rhs[i]) {
00077 return true;
00078 } else if ((*this)[i] > rhs[i]) {
00079 return false;
00080 }
00081 }
00082
00083 return (this->size() < rhs.size()) ? true : false;
00084 }
00085
00086 void BinaryValue::netPack(cCommBuffer *b)
00087 {
00088 doPacking(b,(uint16_t)size());
00089 doPacking(b, (const char*)(&(*begin())), size());
00090 }
00091
00092 void BinaryValue::netUnpack(cCommBuffer *b)
00093 {
00094 uint16_t size;
00095 doUnpacking(b, size);
00096 resize(size);
00097 doUnpacking(b, (char*)(&(*begin())), size);
00098 }