infoton.h

Go to the documentation of this file.
00001 #ifndef INFOTON_CLASS
00002 #define INFOTON_CLASS
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : infoton                                                           *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 2002-$now By Author.  This program is free software; you can  *
00011 * redistribute it and/or modify it under the terms of the GNU General Public  *
00012 * License as published by the Free Software Foundation; either version 2 of   *
00013 * the License or (at your option) any later version.  This is online at:      *
00014 *     http://www.fsf.org/copyleft/gpl.html                                    *
00015 * Please send any updates to: fred@gruntose.com                               *
00016 \*****************************************************************************/
00017 
00018 #include <basis/contracts.h>
00019 #include <structures/string_array.h>
00020 
00021 namespace octopi {
00022 
00024 
00028 class infoton
00029 : public virtual basis::packable,
00030   public virtual basis::clonable,
00031   public virtual basis::text_formable
00032 {
00033 public:
00034   infoton(const structures::string_array &classifier);
00036 
00042   // takes care of the most common cases of 1, 2 & 3 level classifiers.
00043   infoton(const basis::astring &class_1);
00044   infoton(const basis::astring &class_1, const basis::astring &class_2);
00045   infoton(const basis::astring &class_1, const basis::astring &class_2, const basis::astring &cl_3);
00046 
00047   infoton(const infoton &to_copy);
00049 
00052   virtual ~infoton();
00053 
00054   DEFINE_CLASS_NAME("infoton");
00055 
00056   infoton &operator =(const infoton &to_copy);
00058 
00060   const structures::string_array &classifier() const;
00062 
00069   void set_classifier(const structures::string_array &new_classifier);
00071 
00074   // these are also dangerous if you're not careful; they mimic the
00075   // string constructors.
00076   void set_classifier(const basis::astring &class_1);
00077   void set_classifier(const basis::astring &class_1, const basis::astring &class_2);
00078   void set_classifier(const basis::astring &class_1, const basis::astring &class_2,
00079           const basis::astring &cl_3);
00080 
00081   bool check_classifier(const basis::astring &class_name, const basis::astring &caller);
00083 
00086   virtual void pack(basis::byte_array &packed_form) const = 0;
00088 
00090   virtual bool unpack(basis::byte_array &packed_form) = 0;
00092 
00095   virtual void text_form(basis::base_string &state_fill) const = 0;
00097 
00098   virtual clonable *clone() const = 0;
00100 
00101   virtual int packed_size() const = 0;
00103 
00107 
00108   virtual basis::astring text_form() const { basis::astring fill; text_form(fill); return fill; }
00109 
00111 
00112   // This defines the wire format for a flattened infoton.  It is in essence
00113   // a packet header format which all infotons must adhere to to ensure that
00114   // they can be successfully unflattened when appropriate item managers are
00115   // available.
00116   static void fast_pack(basis::byte_array &packed_form, const infoton &to_pack);
00118 
00119   static bool fast_unpack(basis::byte_array &packed_form, structures::string_array &classifier,
00120           basis::byte_array &info);
00122 
00125   static bool test_fast_unpack(const basis::byte_array &packed_form,
00126           int &packed_length);
00128 
00135   static int fast_pack_overhead(const structures::string_array &classifier);
00137 
00142 private:
00143   structures::string_array *_classifier;  
00144 };
00145 
00147 
00149 
00150 template <class contents>
00151 basis::clonable *cloner(const contents &this_obj) { return new contents(this_obj); }
00152 
00153 } //namespace.
00154 
00155 #endif
00156 
Generated on Sat Jan 28 04:22:43 2012 for hoople2 project by  doxygen 1.6.3