feisty meow concerns codebase  2.140
entity_defs.h
Go to the documentation of this file.
1 #ifndef ENTITY_DEFINITIONS_GROUP
2 #define ENTITY_DEFINITIONS_GROUP
3 
4 /*****************************************************************************\
5 * *
6 * Name : various definitions for octopus *
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 "infoton.h"
19 
20 #include <basis/byte_array.h>
21 #include <basis/astring.h>
22 #include <structures/set.h>
23 #include <structures/amorph.h>
24 #include <structures/unique_id.h>
25 #include <timely/time_stamp.h>
26 
27 namespace octopi {
28 
30 
34 class octopus_entity : public virtual basis::packable, public virtual basis::text_formable
35 {
36 public:
37  octopus_entity();
38 
40  int add_in);
42 
46  octopus_entity(const octopus_entity &to_copy);
47 
49 
50  octopus_entity &operator = (const octopus_entity &to_copy);
51 
52  DEFINE_CLASS_NAME("octopus_entity");
53 
54  bool blank() const;
56 
57  // comparison operators.
58  bool operator == (const octopus_entity &that) const;
59 
60  const basis::astring &hostname() const;
61  int process_id() const;
62  int sequencer() const;
63  int add_in() const;
64 
65  void hostname(const basis::astring &new_host);
66  void process_id(int id);
67  void sequencer(int seq);
68  void add_in(int add);
69 
72 
73  basis::astring text_form() const;
75 
76  virtual void text_form(basis::base_string &to_fill) const {
77  to_fill.assign(text_form());
78  }
79 
80  basis::astring to_text() const { return mangled_form(); }
82  static octopus_entity from_text(const basis::astring &to_convert);
84 
86  int &process_id, int &sequencer, int &add_in);
88 
89  int packed_size() const;
91 
92  virtual void pack(basis::byte_array &packed_form) const;
93  virtual bool unpack(basis::byte_array &packed_form);
94 
95 private:
96  basis::astring *_hostname;
97  int _pid;
98  int _sequencer;
99  int _add_in;
100 };
101 
103 
105 
113 class octopus_request_id : public virtual basis::packable
114 {
115 public:
118 
120 
121  octopus_request_id(const octopus_entity &entity, int request_num)
122  : _entity(entity), _request_num(request_num) {}
123 
126 
129  bool operator == (const octopus_request_id &that) const
130  { return (_entity == that._entity)
131  && (_request_num == that._request_num); }
132 
133  bool blank() const;
135 
136  int packed_size() const;
138 
139  basis::astring mangled_form() const;
140 
141  basis::astring text_form() const;
142 
143  basis::astring to_text() const { return mangled_form(); }
144  static octopus_request_id from_text(const basis::astring &to_convert);
145 
146  virtual void pack(basis::byte_array &packed_form) const;
147  virtual bool unpack(basis::byte_array &packed_form);
148 };
149 
151 class octopus_request_id_set : public structures::set<octopus_request_id>
152 {
153 public:
155 
157  : structures::set<octopus_request_id>(orig) {}
158 };
159 
161 
163 
165 class infoton_id_pair : public virtual basis::root_object
166 {
167 public:
170 
172  : _data(data), _id(id) {}
173 
175  delete _data;
177  }
178 };
179 
181 class infoton_list : public structures::amorph<infoton_id_pair> {};
182 
183 } //namespace.
184 
185 #endif
186 
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
virtual base_string & assign(const base_string &s)=0
Sets the contents of this string to "s".
A very common template for a dynamic array of bytes.
Definition: byte_array.h:36
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
implements a list of waiting infotons.
Definition: entity_defs.h:166
octopus_request_id _id
Definition: entity_defs.h:169
infoton_id_pair(infoton *data, const octopus_request_id &id)
Definition: entity_defs.h:171
a list of pending requests and who made them.
Definition: entity_defs.h:181
An infoton is an individual request parcel with accompanying information.
Definition: infoton.h:32
Provides a way of identifying users of an octopus object.
Definition: entity_defs.h:35
int process_id() const
returns the process number in the id.
Definition: entity_defs.cpp:84
int packed_size() const
reports how large the packed entity will be.
virtual bool unpack(basis::byte_array &packed_form)
Restores the packable from the "packed_form".
basis::astring text_form() const
returns a readable form of the identifier.
octopus_entity & operator=(const octopus_entity &to_copy)
Definition: entity_defs.cpp:72
virtual void text_form(basis::base_string &to_fill) const
Provides a text view of all the important info owned by this object.
Definition: entity_defs.h:76
const basis::astring & hostname() const
returns the hostname portion of the id.
Definition: entity_defs.cpp:82
bool operator==(const octopus_entity &that) const
octopus_entity()
blank constructor.
Definition: entity_defs.cpp:35
int add_in() const
returns the random add-in from the id.
Definition: entity_defs.cpp:88
DEFINE_CLASS_NAME("octopus_entity")
basis::astring to_text() const
conversion to text format for display.
Definition: entity_defs.h:80
int sequencer() const
returns the sequencing number from the id.
Definition: entity_defs.cpp:86
virtual void pack(basis::byte_array &packed_form) const
Creates a packed form of the packable object in "packed_form".
static void breakout(const basis::astring &mangled_form, basis::astring &hostname, int &process_id, int &sequencer, int &add_in)
takes a "mangled_form" of an entity id and retrieves the components.
static octopus_entity from_text(const basis::astring &to_convert)
conversion from text format, parsing parameters out.
Definition: entity_defs.cpp:57
bool blank() const
true if the entity is blank, as constructed by default constructor.
Definition: entity_defs.cpp:99
basis::astring mangled_form() const
returns the combined string form of the identifier.
a collection of unique request ids.
Definition: entity_defs.h:152
octopus_request_id_set(const structures::set< octopus_request_id > &orig)
Definition: entity_defs.h:156
Identifies requests made on an octopus by users.
Definition: entity_defs.h:114
int packed_size() const
reports how large the packed id will be.
basis::astring to_text() const
Definition: entity_defs.h:143
static octopus_request_id from_text(const basis::astring &to_convert)
basis::astring mangled_form() const
similar to entity id.
virtual void pack(basis::byte_array &packed_form) const
Creates a packed form of the packable object in "packed_form".
basis::astring text_form() const
human readable form of the request.
octopus_request_id(const octopus_entity &entity, int request_num)
Definition: entity_defs.h:121
int _request_num
the item number from the entity.
Definition: entity_defs.h:117
bool operator==(const octopus_request_id &that) const
Definition: entity_defs.h:129
octopus_entity _entity
the entity.
Definition: entity_defs.h:116
bool blank() const
returns true if this is a blank id (as constructed by default ctor).
static octopus_request_id randomized_id()
provides a pre-randomized request id.
virtual bool unpack(basis::byte_array &packed_form)
Restores the packable from the "packed_form".
Emulates a mathematical set, providing several standard set operations.
Definition: set.h:36
set(int num=0, const octopus_request_id *init=NULL_POINTER, basis::un_short flags=basis::array< octopus_request_id >::EXPONE)
Constructs a set with "num" elements, copying them from "init".
Definition: set.h:41
#define NULL_POINTER
The value representing a pointer to nothing.
Definition: definitions.h:32
A dynamic container class that holds any kind of object via pointers.
Definition: amorph.h:55