BinaryValue.cc

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2007 Institut fuer Telematik, Universitaet Karlsruhe (TH)
00003 //
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU General Public License
00006 // as published by the Free Software Foundation; either version 2
00007 // of the License, or (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 //
00018 
00024 #include <iterator>
00025 
00026 #include "BinaryValue.h"
00027 
00028 using namespace std;
00029 
00030 // predefined BinaryValue
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());  // Inherits vector<char>::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 // Allow output of vector<char> using normal notation
00053 std::ostream& operator << (std::ostream& os, const BinaryValue& v) {
00054     copy(v.begin(), v.end(), ostream_iterator<char>(os, ""));
00055     return os;        // To allow (cout << a) << b;
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 }

Generated on Wed Mar 25 16:32:48 2009 for OverSim by  doxygen 1.5.5