crompish_pax.h

Go to the documentation of this file.
00001 #ifndef CROMPISH_PAX_GROUP
00002 #define CROMPISH_PAX_GROUP
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : crompish packets for tester                                       *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *  Purpose:                                                                   *
00010 *                                                                             *
00011 *    Some simple transactions that can be used for the CROMP tester.          *
00012 *                                                                             *
00013 *******************************************************************************
00014 * Copyright (c) 2002-$now By Author.  This program is free software; you can  *
00015 * redistribute it and/or modify it under the terms of the GNU General Public  *
00016 * License as published by the Free Software Foundation; either version 2 of   *
00017 * the License or (at your option) any later version.  This is online at:      *
00018 *     http://www.fsf.org/copyleft/gpl.html                                    *
00019 * Please send any updates to: fred@gruntose.com                               *
00020 \*****************************************************************************/
00021 
00022 #include <basis/chaos.h>
00023 #include <basis/string_array.h>
00024 #include <cromp/cromp_transaction.h>
00025 #include <geometric/screen_rectangle.h>
00026 #include <octopus/infoton.h>
00027 #include <octopus/tentacle_helper.h>
00028 
00029 using namespace geometric;
00030 
00031 class bubble : public infoton
00032 {
00033 public:
00034   bubble(int data_segment_size = 0, const screen_rectangle &boundaries
00035       = screen_rectangle(), int color = 0)
00036     // constructs a bubble within the "boundaries" that has "color" and a data
00037     // segment size specified by "data_segment_size".  the color definitions
00038     // reside elsewhere.
00039   : infoton(bubble_classing()), _data()
00040   { reset(data_segment_size, boundaries, color); }
00041 
00042   const string_array &bubble_classing() {
00043     static istring bubbs[2] = { "bubble", "rubble" };
00044     static string_array barray(2, bubbs);
00045     return barray;
00046   }
00047 
00048   void reset(int data_segment_size, const screen_rectangle &boundaries,
00049       int color) {
00050     _color = color;
00051     _bounds = boundaries;
00052     _data.reset(data_segment_size);
00053   }
00054 
00055   int data_length() const { return _data.length(); }
00056 
00057   clonable *clone() const { return cloner<bubble>(*this); }
00058 
00059   byte_array &data() { return _data; }
00060 
00061   int non_data_overhead() const { return packed_size() - _data.length(); }
00062 
00063   virtual void pack(byte_array &packed_form) const {
00064     basis::attach(packed_form, _color);
00065     _bounds.pack(packed_form);
00066     basis::attach(packed_form, _data);
00067   }
00068 
00069   int packed_size() const {
00070     return _data.length() + 2 * sizeof(int)       // packed byte array.
00071         + sizeof(int)                         // packed color.
00072         + 4 * sizeof(int);                    // packed screen rectangle.
00073   }
00074 
00075   virtual bool unpack(byte_array &packed_form) {
00076     if (!basis::detach(packed_form, _color)) return false;
00077     if (!_bounds.unpack(packed_form)) return false;
00078     if (!basis::detach(packed_form, _data)) return false;
00079     return true;
00080   }
00081 
00082 private:
00083   screen_rectangle _bounds;
00084   int _color;
00085   byte_array _data;
00086 };
00087 
00089 
00090 class bubbles_tentacle : public tentacle_helper<bubble>
00091 {
00092 public:
00093   bubbles_tentacle(bool backgrounded)
00094       : tentacle_helper<bubble>(bubble().classifier(), backgrounded)
00095   {}
00096 };
00097 
00098 #endif
00099 

Generated on Fri Nov 28 04:29:33 2008 for HOOPLE Libraries by  doxygen 1.5.1