• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

element.h

Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
00003 //   Foundation, Inc
00004 // 
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 3 of the License, or
00008 // (at your option) any later version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 
00019 #ifndef GNASH_ELEMENT_H
00020 #define GNASH_ELEMENT_H
00021 
00022 #include <vector>
00023 #include <string>
00024 #include <cstring>
00025 #include <iostream> // for output operator
00026 #include <boost/cstdint.hpp>
00027 #include <boost/shared_ptr.hpp>
00028 #include <boost/scoped_ptr.hpp>
00029 
00030 //#include "network.h"
00031 #include "dsodefs.h" // DSOEXPORT
00032 
00036 namespace cygnal
00037 {
00038 
00039 // Forward decleration
00040 class Buffer;
00041 
00047 class DSOEXPORT Element {
00048 public:
00051     typedef enum {
00052         NOTYPE            = -1,
00053         NUMBER_AMF0       = 0x00,
00054         BOOLEAN_AMF0      = 0x01,
00055         STRING_AMF0       = 0x02,
00056         OBJECT_AMF0       = 0x03,
00057         MOVIECLIP_AMF0    = 0x04,
00058         NULL_AMF0         = 0x05,
00059         UNDEFINED_AMF0    = 0x06,
00060         REFERENCE_AMF0    = 0x07,
00061         ECMA_ARRAY_AMF0   = 0x08,
00062         OBJECT_END_AMF0   = 0x09,
00063         STRICT_ARRAY_AMF0 = 0x0a,
00064         DATE_AMF0         = 0x0b,
00065         LONG_STRING_AMF0  = 0x0c,
00066         UNSUPPORTED_AMF0  = 0x0d,
00067         RECORD_SET_AMF0   = 0x0e,
00068         XML_OBJECT_AMF0   = 0x0f,
00069         TYPED_OBJECT_AMF0 = 0x10,
00070         AMF3_DATA         = 0x11,
00071 //      // these aren't part of the AMF spec, they're used internally
00072         RTMP_HEADER       = 0x20
00073 //      FUNCTION=0x12
00074     } amf0_type_e;
00075     
00081     typedef enum {
00082         UNDEFINED_AMF3 = 0x00,
00083         NULL_AMF3    = 0x01,
00084         FALSE_AMF3   = 0x02,
00085         TRUE_AMF3    = 0x03,
00086         INTEGER_AMF3 = 0x04,
00087         DOUBLE_AMF3  = 0x05,
00088         STRING_AMF3  = 0x06,
00089         XMLDOC_AMF3  = 0x07,
00090         DATE_AMF3    = 0x08,
00091         ARRAY_AMF3   = 0x09,
00092         OBJECT_AMF3  = 0x0a,
00093         XML_AMF3     = 0x0b,
00094         BYTES_AMF3   = 0x0c
00095     } amf3_type_e;
00096 
00098     Element();
00099 
00102     ~Element();
00103 
00107     Element(double data);
00108 
00114     Element(const std::string &name, double num);
00115     
00121     Element(const char *data);
00123     Element(const std::string &data);
00124     
00130     Element(const std::string &name, const std::string &data);
00131     
00135     Element(bool data);
00136 
00142     Element(const std::string &name, bool data);
00143     
00149     Element(std::vector<double> &data);
00150 
00156     Element(std::vector<std::string> &data);
00157 
00163     Element(std::vector<Element > &data);
00164 
00169     void clear();
00170     
00171 #if 0
00172     // Create a function block for AMF
00173     Element(bool, double, double, const std::string &str);
00174 
00175     // Create a function block for AMF
00176     Element &init(bool, double, double, const std::string &str);
00177 #endif
00178     
00184     Element &operator=(Element &el);
00185 //    Element &operator=(boost::shared_ptr<Element>);
00186 
00193     Element &operator=(double num);
00194     
00201     Element &operator=(const std::string &str);
00202 
00209     Element &operator=(bool flag);
00210 
00215     Element &makeNullString();
00216 
00224     Element &makeString(const char *str, size_t size);
00226     Element &makeString(boost::uint8_t *data, size_t size);
00227 
00233     Element &makeString(const std::string &data);
00234     
00243     Element &makeString(const std::string &name, const std::string &str);
00244 
00250     Element &makeNumber(double num); 
00251 
00257     Element &makeNumber(boost::shared_ptr<cygnal::Buffer> buf); 
00258 
00265     Element &makeNumber(boost::uint8_t *data);
00266     
00272     Element &makeNumber(const std::string &name, double num) ;
00275     Element &makeNumber(const std::string &name, boost::uint8_t *data);
00276 
00283     Element &makeBoolean(boost::uint8_t *data);
00284 
00290     Element &makeBoolean(bool data);
00291 
00299     Element &makeBoolean(const std::string &name, bool data);
00300     
00304     Element &makeUndefined();
00305 
00311     Element &makeUndefined(const std::string &name);
00312 
00316     Element &makeNull();
00317     
00323     Element &makeNull(const std::string &name);
00324 
00328     Element &makeObjectEnd();
00329 
00338     Element &makeObject();
00339 
00346     Element &makeObject(const std::string &name);
00347 
00353     Element &makeObject(std::vector<boost::shared_ptr<cygnal::Element> > &data);
00354     
00362     Element &makeObject(const std::string &name, std::vector<boost::shared_ptr<cygnal::Element> > &data);
00363     
00368     Element &makeXMLObject();
00369     
00377     Element &makeXMLObject(const std::string &name);
00378 
00386     Element &makeXMLObject(const std::string &name, const std::string &data);
00387     Element &makeXMLObject(boost::uint8_t *data);
00388 
00394     Element &makeECMAArray();
00395 
00401     Element &makeECMAArray(const std::string &name);
00402 
00410     Element &makeECMAArray(std::vector<boost::shared_ptr<cygnal::Element> > &data);
00411 
00419     Element &makeECMAArray(const std::string &name, std::vector<boost::shared_ptr<cygnal::Element> > &data);
00420 
00426     Element &makeStrictArray();
00427 
00435     Element &makeStrictArray(const std::string &name);
00436 
00444     Element &makeStrictArray(std::vector<boost::shared_ptr<cygnal::Element> > &data);
00445 
00453     Element &makeStrictArray(const std::string &name, std::vector<boost::shared_ptr<cygnal::Element> > &data);
00454 
00460     Element &makeTypedObject();
00461     Element &makeTypedObject(const std::string &name);
00462 
00470     Element &makeTypedObject(boost::uint8_t *data);
00471     
00475     Element &makeReference();
00476     Element &makeReference(boost::uint16_t index);
00477 
00485     Element &makeReference(boost::uint8_t *data, size_t size);
00486     
00490     Element &makeMovieClip();
00491 
00499     Element &makeMovieClip(boost::uint8_t *data, size_t size);
00500 
00504     Element &makeLongString();
00505     
00513     Element &makeLongString(boost::uint8_t *data);
00514     
00518     Element &makeRecordSet();
00519 
00527     Element &makeRecordSet(boost::uint8_t *data);
00528     
00532     Element &makeDate();
00533 
00539     Element &makeDate(boost::uint8_t *data);
00540     Element &makeDate(double data);
00541     
00545     Element &makeUnsupported();
00546 
00554     Element &makeUnsupported(boost::uint8_t *data);
00555     
00565     bool operator==(Element &);
00566     
00576     bool operator==(boost::shared_ptr<cygnal::Element> );
00577     
00587     bool operator==(bool x);
00588 
00595     boost::shared_ptr<cygnal::Element> operator[](size_t index);
00596 
00601     size_t getDataSize() const;
00602     
00606     amf0_type_e getType() const { return _type; };
00607     
00613     void setType(amf0_type_e type) { _type = type; };
00614 //    void setData(Buffer *buf) { _buffer = buf; };
00615 
00619     bool to_bool() const;
00620     
00624     double to_number() const;
00625 
00629     boost::uint16_t to_short() const;
00630 
00634     boost::uint32_t to_integer() const;
00635 
00639     const char *to_string() const;
00640 
00644     boost::uint8_t *to_reference();
00645     const boost::uint8_t *to_reference() const;
00646 
00647     // Manipulate the name of a property
00648 
00653     size_t getNameSize() const;
00654     
00659     char *getName() const { return _name; };
00660 
00667     void setName(const std::string &name);
00669     void setName(const char *name, size_t x);
00670 
00681     void setName(boost::uint8_t *name, size_t size);
00682 
00683     // Manipulate the children Elements of an object
00684 
00691     boost::shared_ptr<Element> findProperty(const std::string &name);
00692 
00698     boost::shared_ptr<Element> getProperty(size_t index) const { return _properties[index]; };
00699 
00705     void addProperty(boost::shared_ptr<Element> el) { _properties.push_back(el); };
00706 
00707     void clearProperties() { return _properties.clear(); };
00708 
00715     boost::shared_ptr<Element> popProperty()
00716                         { return _properties.front(); };
00717 
00721     size_t propertySize() const
00722                         { return _properties.size(); };
00723 
00733     boost::shared_ptr<Buffer> encode();
00734     boost::shared_ptr<Buffer> encode(bool notobject);
00735 
00742     std::vector<boost::shared_ptr<Element> > getProperties() const
00743                         { return _properties; };
00744 
00745     size_t calculateSize();
00746     size_t calculateSize(cygnal::Element &el) const;
00747 
00750     void dump() const { dump(std::cerr); }
00752     void dump(std::ostream& os) const;
00753     
00754 private:
00763     void check_buffer(size_t size);
00764 
00768     char                *_name;
00769     
00773     boost::shared_ptr<cygnal::Buffer> _buffer;
00774 
00777     amf0_type_e         _type;
00778 
00782     std::vector<boost::shared_ptr<Element> > _properties;
00783 };                              // end of class definition
00784 
00785 
00787 inline std::ostream& operator << (std::ostream& os, const Element& el)
00788 {
00789         el.dump(os);
00790         return os;
00791 }
00792 
00793 
00794 } // end of amf namespace
00795 
00796 // end of _ELEMENT_H_
00797 #endif
00798 
00799 // local Variables:
00800 // mode: C++
00801 // indent-tabs-mode: nil
00802 // End:

Generated on Fri Mar 16 2012 15:46:09 for Gnash by  doxygen 1.7.1