dashel-private.h
Go to the documentation of this file.
00001 /*
00002         Dashel
00003         A cross-platform DAta Stream Helper Encapsulation Library
00004         Copyright (C) 2007 -- 2012:
00005                 
00006                 Stephane Magnenat <stephane at magnenat dot net>
00007                         (http://stephane.magnenat.net)
00008                 Mobots group - Laboratory of Robotics Systems, EPFL, Lausanne
00009                         (http://mobots.epfl.ch)
00010                 
00011                 Sebastian Gerlach
00012                 Kenzan Technologies
00013                         (http://www.kenzantech.com)
00014         
00015         All rights reserved.
00016         
00017         Redistribution and use in source and binary forms, with or without
00018         modification, are permitted provided that the following conditions are met:
00019                 * Redistributions of source code must retain the above copyright
00020                   notice, this list of conditions and the following disclaimer.
00021                 * Redistributions in binary form must reproduce the above copyright
00022                   notice, this list of conditions and the following disclaimer in the
00023                   documentation and/or other materials provided with the distribution.
00024                 * Neither the names of "Mobots", "Laboratory of Robotics Systems", "EPFL",
00025                   "Kenzan Technologies" nor the names of the contributors may be used to
00026                   endorse or promote products derived from this software without specific
00027                   prior written permission.
00028         
00029         THIS SOFTWARE IS PROVIDED BY COPYRIGHT HOLDERS ``AS IS'' AND ANY
00030         EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00031         WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00032         DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS BE LIABLE FOR ANY
00033         DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00034         (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00035         LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00036         ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00037         (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00038         SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00039 */
00040 
00041 #ifndef INCLUDED_DASHEL_PRIVATE_H
00042 #define INCLUDED_DASHEL_PRIVATE_H
00043 
00044 #include "dashel.h"
00045 #include <cstring>
00046 #include <cstdlib>
00047 #include <sstream>
00048 #include <vector>
00049 #include <cassert>
00050 
00051 namespace Dashel
00052 {
00054         class ExpandableBuffer
00055         {
00056         private:
00057                 unsigned char* _data; 
00058                 size_t _size; 
00059                 size_t _pos; 
00060         
00061         public:
00063                 ExpandableBuffer(size_t size = 0);
00065                 ~ExpandableBuffer();
00067                 void clear();
00069                 void add(const void* data, const size_t size);
00070                 
00072                 unsigned char* get() { return _data; }
00074                 size_t size() const { return _pos; }
00076                 size_t reservedSize() const { return _size; }
00077         };
00078         
00080         class MemoryPacketStream: public PacketStream
00081         {
00082         protected:
00084                 ExpandableBuffer sendBuffer;
00086                 std::deque<unsigned char> receptionBuffer;
00087         
00088         public:
00090                 MemoryPacketStream(const std::string& protocolName) : Stream(protocolName), PacketStream(protocolName) { }
00091         
00092                 virtual void write(const void *data, const size_t size);
00093                 
00094                 virtual void flush() { }
00095                 
00096                 virtual void read(void *data, size_t size);
00097         };
00098         
00099         
00100         template<typename T> T ParameterSet::get(const char *key) const
00101         {
00102                 T t;
00103                 std::map<std::string, std::string>::const_iterator it = values.find(key);
00104                 if(it == values.end())
00105                 {
00106                         std::string r = std::string("Parameter missing: ").append(key);
00107                         throw Dashel::DashelException(DashelException::InvalidTarget, 0, r.c_str());
00108                 }
00109                 std::istringstream iss(it->second);
00110                 iss >> t;
00111                 return t;
00112         }
00113 }
00114 
00115 #endif


dashel
Author(s): Stéphane Magnenat
autogenerated on Sun Oct 5 2014 23:46:32