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(const std::string& str)
00039 {
00040 *this = BinaryValue(str.c_str());
00041 }
00042
00043 BinaryValue::BinaryValue(const std::vector<char>& v) : vector<char>(v)
00044 {
00045 };
00046
00047 bool BinaryValue::isUnspecified() const
00048 {
00049 return empty();
00050 }
00051
00052
00053 std::ostream& operator << (std::ostream& os, const BinaryValue& v) {
00054 copy(v.begin(), v.end(), ostream_iterator<char>(os, ""));
00055 return os;
00056 }
00057
00058 bool BinaryValue::operator<(const BinaryValue& rhs)
00059 {
00060 size_type minSize = min(this->size(), rhs.size());
00061 for (size_type i=0; i<minSize; i++) {
00062 if ((*this)[i] < rhs[i]) {
00063 return true;
00064 } else if ((*this)[i] > rhs[i]) {
00065 return false;
00066 }
00067 }
00068
00069 return (this->size() < rhs.size()) ? true : false;
00070 }
00071
00072 void BinaryValue::netPack(cCommBuffer *b)
00073 {
00074 doPacking(b,size());
00075 doPacking(b, (const char*)(&(*begin())), size());
00076 }
00077
00078 void BinaryValue::netUnpack(cCommBuffer *b)
00079 {
00080 int size;
00081 doUnpacking(b, size);
00082 resize(size);
00083 doUnpacking(b, (char*)(&(*begin())), size);
00084 }