IBR-DTNSuite  0.8
ibrdtn/ibrdtn/data/BundleString.cpp
Go to the documentation of this file.
00001 /*
00002  * BundleString.cpp
00003  *
00004  *  Created on: 11.09.2009
00005  *      Author: morgenro
00006  */
00007 
00008 #include "ibrdtn/config.h"
00009 #include "ibrdtn/data/BundleString.h"
00010 #include "ibrdtn/data/SDNV.h"
00011 
00012 namespace dtn
00013 {
00014         namespace data
00015         {
00016                 BundleString::BundleString(std::string value)
00017                  : std::string(value)
00018                 {
00019                 }
00020 
00021                 BundleString::BundleString()
00022                 {
00023                 }
00024 
00025                 BundleString::~BundleString()
00026                 {
00027                 }
00028 
00029                 size_t BundleString::getLength() const
00030                 {
00031                         dtn::data::SDNV sdnv(length());
00032                         return sdnv.getLength() + length();
00033                 }
00034 
00035                 std::ostream &operator<<(std::ostream &stream, const BundleString &bstring)
00036                 {
00037                         std::string data = (std::string)bstring;
00038                         dtn::data::SDNV sdnv(data.length());
00039                         stream << sdnv << data;
00040                         return stream;
00041                 }
00042 
00043                 std::istream &operator>>(std::istream &stream, BundleString &bstring)
00044                 {
00045                         dtn::data::SDNV length;
00046                         stream >> length;
00047                         std::streamsize data_len = length.getValue();
00048 
00049                         // clear the content
00050                         ((std::string&)bstring) = "";
00051                         
00052                         if (data_len > 0)
00053                         {
00054                                 char data[data_len];
00055                                 stream.read(data, data_len);
00056                                 bstring.assign(data, data_len);
00057                         }
00058 
00059                         return stream;
00060                 }
00061         }
00062 }