OSCUnpacker.h

00001 /* Open SoundControl kit in C++                                              */
00002 /* Copyright (C) 2002-2004 libOSC++ contributors. See AUTHORS                */
00003 /*                                                                           */
00004 /* This library is free software; you can redistribute it and/or             */
00005 /* modify it under the terms of the GNU Lesser General Public                */
00006 /* License as published by the Free Software Foundation; either              */
00007 /* version 2.1 of the License, or (at your option) any later version.        */
00008 /*                                                                           */
00009 /* This library 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 GNU         */
00012 /* Lesser General Public License for more details.                           */
00013 /*                                                                           */
00014 /* You should have received a copy of the GNU Lesser General Public          */
00015 /* License along with this library; if not, write to the Free Software       */
00016 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
00017 /*                                                                           */
00018 /* For questions regarding this program contact                              */
00019 /* Daniel Holth <dholth@fastmail.fm> or visit                                */
00020 /* http://wiretap.stetson.edu/                                               */
00021 
00075 #ifndef OSCUNPACKER_H
00076 #define OSCUNPACKER_H
00077 
00078 #include "int64_t.h"
00079 
00080 #ifdef __MACH__
00081 #include <sys/types.h>
00082 #include <machine/endian.h>
00083 #else
00084 #include <netinet/in.h>
00085 #endif
00086 
00087 #include <string>
00088 #include <string.h>
00089 #include <utility>
00090 
00091 #include <iostream>
00092 
00093 
00094 class OSCUnpacker
00095 {
00096   private:
00097     std::string    myData;
00098     int       myPosition;
00099 
00100   protected:
00101     std::string *getDataPointer()  { return &(this->myData); }
00103     bool unpackBytes(char *out, int bytes);
00105     bool skipBytes(int bytes);
00106     int  getPosition()        { return this->myPosition; }
00107     void setPosition(int p)   { this->myPosition = p;    }
00108     
00109   public:
00110     OSCUnpacker();
00111     
00112     void init()   { this->reset(); }
00113     void reset()  { this->setPosition(0); }
00114     
00116     bool unpackDouble (double  *out);
00118     bool unpackFloat  (float   *out);
00120     bool unpackHyper  (int64_t *out);
00122     bool unpackInt    (int32_t *out);
00123     
00125     bool unpackString (std::string  *out);
00127     bool unpackBlob   (std::string  *out);
00128 
00129     // These functions skip data.
00130     // For example: If you skip an int and the next argument
00131     // is a string, you will be positioned to read the string.
00132     
00134     bool skipDouble();
00136     bool skipFloat();
00138     bool skipHyper();
00140     bool skipInt();
00142     bool skipString();
00144     bool skipBlob();
00145 
00146     void setData(const std::string& data);
00147 };
00148 
00149 #endif

Generated on Thu Mar 2 23:51:35 2006 for libOSC++ by  doxygen 1.4.6