feisty meow concerns codebase 2.140
infoton.h
Go to the documentation of this file.
1#ifndef INFOTON_CLASS
2#define INFOTON_CLASS
3
4/*****************************************************************************\
5* *
6* Name : infoton *
7* Author : Chris Koeritz *
8* *
9*******************************************************************************
10* Copyright (c) 2002-$now By Author. This program is free software; you can *
11* redistribute it and/or modify it under the terms of the GNU General Public *
12* License as published by the Free Software Foundation; either version 2 of *
13* the License or (at your option) any later version. This is online at: *
14* http://www.fsf.org/copyleft/gpl.html *
15* Please send any updates to: fred@gruntose.com *
16\*****************************************************************************/
17
18#include <basis/contracts.h>
20
21namespace octopi {
22
24
29: public virtual basis::packable,
30 public virtual basis::clonable,
31 public virtual basis::text_formable
32{
33public:
36
42 // takes care of the most common cases of 1, 2 & 3 level classifiers.
43 infoton(const basis::astring &class_1);
44 infoton(const basis::astring &class_1, const basis::astring &class_2);
45 infoton(const basis::astring &class_1, const basis::astring &class_2, const basis::astring &cl_3);
46
47 infoton(const infoton &to_copy);
49
52 virtual ~infoton();
53
55
56 infoton &operator =(const infoton &to_copy);
58
62
69 void set_classifier(const structures::string_array &new_classifier);
71
74 // these are also dangerous if you're not careful; they mimic the
75 // string constructors.
76 void set_classifier(const basis::astring &class_1);
77 void set_classifier(const basis::astring &class_1, const basis::astring &class_2);
78 void set_classifier(const basis::astring &class_1, const basis::astring &class_2,
79 const basis::astring &cl_3);
80
81 bool check_classifier(const basis::astring &class_name, const basis::astring &caller);
83
86 virtual void pack(basis::byte_array &packed_form) const = 0;
88
90 virtual bool unpack(basis::byte_array &packed_form) = 0;
92
95 virtual void text_form(basis::base_string &state_fill) const = 0;
97
98 virtual clonable *clone() const = 0;
100
101 virtual int packed_size() const = 0;
103
108 virtual basis::astring text_form() const { basis::astring fill; text_form(fill); return fill; }
109
111
112 // This defines the wire format for a flattened infoton. It is in essence
113 // a packet header format which all infotons must adhere to to ensure that
114 // they can be successfully unflattened when appropriate item managers are
115 // available.
116 static void fast_pack(basis::byte_array &packed_form, const infoton &to_pack);
118
120 basis::byte_array &info);
122
125 static bool test_fast_unpack(const basis::byte_array &packed_form,
126 int &packed_length);
128
137
142private:
143 structures::string_array *_classifier;
144};
145
147
149
150template <class contents>
151basis::clonable *cloner(const contents &this_obj) { return new contents(this_obj); }
152
153} //namespace.
154
155#endif
156
Provides a dynamically resizable ASCII character string.
Definition astring.h:35
Defines the base class for all string processing objects in hoople.
Definition base_string.h:28
A very common template for a dynamic array of bytes.
Definition byte_array.h:36
A clonable object knows how to make copy of itself.
Definition contracts.h:109
A base class for objects that can pack into an array of bytes.
Definition byte_array.h:87
A base class for objects that can provide a synopsis of their current state.
Definition contracts.h:142
virtual const char * class_name() const =0
Returns the bare name of this class as a constant character pointer.
An infoton is an individual request parcel with accompanying information.
Definition infoton.h:32
virtual ~infoton()
Definition infoton.cpp:79
virtual void text_form(basis::base_string &state_fill) const =0
requires derived infotons to be able to show their state as a string.
virtual basis::astring text_form() const
local version just makes text_form() more functional.
Definition infoton.h:108
virtual int packed_size() const =0
reports how large the infoton will be when packed.
static void fast_pack(basis::byte_array &packed_form, const infoton &to_pack)
flattens an infoton "to_pack" into the byte array "packed_form".
Definition infoton.cpp:162
virtual bool unpack(basis::byte_array &packed_form)=0
restores an infoton from a packed form.
infoton & operator=(const infoton &to_copy)
assigns only the base class portion.
Definition infoton.cpp:82
static bool fast_unpack(basis::byte_array &packed_form, structures::string_array &classifier, basis::byte_array &info)
undoes a previous fast_pack to restore the previous information.
Definition infoton.cpp:227
void set_classifier(const structures::string_array &new_classifier)
sets the infoton's classifier to the "new_classifier".
Definition infoton.cpp:104
const structures::string_array & classifier() const
this array of strings is the "name" for this infoton.
Definition infoton.cpp:85
bool check_classifier(const basis::astring &class_name, const basis::astring &caller)
checks that the classifier seems valid.
Definition infoton.cpp:88
static int fast_pack_overhead(const structures::string_array &classifier)
reports how much space is needed to pack the "classifier".
Definition infoton.cpp:155
DEFINE_CLASS_NAME("infoton")
static bool test_fast_unpack(const basis::byte_array &packed_form, int &packed_length)
checks that the "packed_form" could hold a valid packed infoton.
Definition infoton.cpp:185
virtual clonable * clone() const =0
must be provided to allow creation of a copy of this object.
virtual void pack(basis::byte_array &packed_form) const =0
stuffs the data in the infoton into the "packed_form".
An array of strings with some additional helpful methods.
basis::clonable * cloner(const contents &this_obj)
a templated method for cloning any infoton with a valid copy constructor.
Definition infoton.h:151