Urbi SDK Remote for C++  2.7.5
ubinary.hh
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2007-2011, Gostai S.A.S.
00003  *
00004  * This software is provided "as is" without warranty of any kind,
00005  * either expressed or implied, including but not limited to the
00006  * implied warranties of fitness for a particular purpose.
00007  *
00008  * See the LICENSE file for more information.
00009  */
00010 
00012 #ifndef URBI_UBINARY_HH
00013 # define URBI_UBINARY_HH
00014 
00015 # include <libport/cstring>
00016 # include <iosfwd>
00017 # include <list>
00018 # include <string>
00019 
00020 # include <urbi/export.hh>
00021 # include <urbi/uimage.hh>
00022 # include <urbi/usound.hh>
00023 
00024 namespace urbi
00025 {
00026 
00027   /*--------------.
00028   | UBinaryData.  |
00029   `--------------*/
00030 
00031   // Internal use: unparsed binary data.
00032   class URBI_SDK_API BinaryData
00033   {
00034   public:
00035     BinaryData();
00036     BinaryData(void *d, size_t s);
00038     void clear();
00039     void* data;
00040     size_t size;
00041   };
00042 
00044   typedef std::list<BinaryData> binaries_type;
00045 
00046 
00047   /*----------.
00048   | UBinary.  |
00049   `----------*/
00050 
00051   enum UBinaryType
00052   {
00053     BINARY_NONE,
00054     BINARY_UNKNOWN,
00055     BINARY_IMAGE,
00056     BINARY_SOUND,
00057   };
00058 
00063   class URBI_SDK_API UBinary
00064   {
00065   public:
00066     UBinary();
00068     UBinary(const UBinary &b, bool copy = true, bool temp = false);
00069     explicit UBinary(const UImage&, bool copy = true);
00070     explicit UBinary(const USound&, bool copy = true);
00071 
00073     UBinary& operator= (const UBinary &b);
00074 
00076     void buildMessage();
00078     std::string getMessage() const;
00079 
00081     void clear();
00082 
00084     ~UBinary();
00086     bool parse(std::istringstream& is,
00087                const binaries_type& bins,
00088                binaries_type::const_iterator& binpos, bool copy = true);
00089     int parse(const char* message, int pos,
00090               const binaries_type& bins,
00091               binaries_type::const_iterator& binpos, bool copy = true);
00092 
00094     std::ostream& print(std::ostream& o, int kernelMajor = 2) const;
00095 
00096     UBinaryType type;
00097     union
00098     {
00099       struct
00100       {
00101         void* data;             
00102         size_t size;
00103       } common;
00104       UImage image;
00105       USound sound;
00106     };
00108     std::string message;
00109 
00112     bool allocated_;
00118     bool temporary_;
00119   };
00120 
00121   URBI_SDK_API
00122   std::ostream& operator<< (std::ostream& o, const UBinary& t);
00123 
00124 } // end namespace urbi
00125 
00126 # include <urbi/ubinary.hxx>
00127 
00128 #endif // ! URBI_UBINARY_HH