feisty meow concerns codebase  2.140
contracts.h
Go to the documentation of this file.
1 #ifndef CONTRACTS_GROUP
2 #define CONTRACTS_GROUP
3 
4 /*****************************************************************************\
5 * *
6 * Name : contracts *
7 * Author : Chris Koeritz *
8 * *
9 *******************************************************************************
10 * Copyright (c) 1989-$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 
22 #include "outcome.h"
23 
24 namespace basis {
25 
26 // forward declarations.
27 class base_string;
28 
30 
32 
33 class attribute : public virtual root_object
34 {
35 public:
36  virtual const root_object &get() const = 0;
37  virtual void set(const root_object &new_value) = 0;
38 };
39 
41 
43 class equalizable : public virtual root_object
44 {
45 public:
46  virtual bool equal_to(const equalizable &s2) const = 0;
48  virtual bool operator == (const equalizable &s2) const { return equal_to(s2); }
50 };
51 
53 
55 
56 class orderable : public virtual equalizable
57 {
58 public:
59  virtual bool less_than(const orderable &s2) const = 0;
61  virtual bool operator < (const orderable &s2) const { return less_than(s2); }
63 };
64 
66 
68 
69 class base_logger : public virtual root_object
70 {
71 public:
72  virtual outcome log(const base_string &info, int filter) = 0;
74 
76 };
77 
79 
81 #define DEFINE_FILTER(NAME, CURRENT_VALUE, INFO_STRING) NAME = CURRENT_VALUE
82 
85  DEFINE_FILTER(NEVER_PRINT, -1, "This diagnostic entry should be dropped and never seen"),
86  DEFINE_FILTER(ALWAYS_PRINT, 0, "This diagnostic entry will always be shown or recorded")
87 };
88 
90 
92 
97 class base_synchronizer : public virtual root_object
98 {
99 public:
100  virtual void establish_lock() = 0;
101  virtual void repeal_lock() = 0;
102 };
103 
105 
107 
108 class clonable : public virtual root_object
109 {
110 public:
111  virtual clonable *clone() const = 0;
112 };
113 
115 
117 
122 class nameable : public virtual root_object
123 {
124 public:
125  virtual const char *class_name() const = 0;
127 
131 };
132 
134 
136 
141 class text_formable : public virtual nameable
142 {
143 public:
144  virtual const char *class_name() const = 0; // forwarded requirement from nameable.
145 
146  virtual void text_form(base_string &state_fill) const = 0;
148 
150 };
151 
153 
155 
160 class hoople_standard : public virtual text_formable, public virtual equalizable
161 {
162 public:
163  // this is a union class and has no extra behavior beyond its bases.
164 };
165 
167 
169 
170 class text_streamable : public virtual nameable
171 {
172 public:
173  virtual bool produce(base_string &target) const = 0;
175 
179  virtual bool consume(const base_string &source) = 0;
181 
183 };
184 
185 } //namespace.
186 
187 #endif
188 
Defines an attribute base class that supports get and set operations.
Definition: contracts.h:34
virtual void set(const root_object &new_value)=0
virtual const root_object & get() const =0
Provides an abstract base for logging mechanisms.
Definition: contracts.h:70
virtual outcome log(const base_string &info, int filter)=0
writes the information in "info" to the logger using the "filter".
Defines the base class for all string processing objects in hoople.
Definition: base_string.h:28
Interface for a simple form of synchronization.
Definition: contracts.h:98
virtual void establish_lock()=0
virtual void repeal_lock()=0
A clonable object knows how to make copy of itself.
Definition: contracts.h:109
virtual clonable * clone() const =0
Base class for object that can tell itself apart from other instances.
Definition: contracts.h:44
virtual bool operator==(const equalizable &s2) const
the virtual method for object equality.
Definition: contracts.h:48
virtual bool equal_to(const equalizable &s2) const =0
the base class of the most easily used and tested objects in the library.
Definition: contracts.h:161
Root object for any class that knows its own name.
Definition: contracts.h:123
virtual const char * class_name() const =0
Returns the bare name of this class as a constant character pointer.
A base for objects that can be alphabetically (lexicographically) ordered.
Definition: contracts.h:57
virtual bool less_than(const orderable &s2) const =0
virtual bool operator<(const orderable &s2) const
the virtual method for object ordering.
Definition: contracts.h:61
Outcomes describe the state of completion for an operation.
Definition: outcome.h:31
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.
virtual void text_form(base_string &state_fill) const =0
Provides a text view of all the important info owned by this object.
a base for classes that can stream their contents out to a textual form.
Definition: contracts.h:171
virtual bool consume(const base_string &source)=0
chows down on a string that supposedly contains a streamed form.
virtual bool produce(base_string &target) const =0
sends the derived class's member data into the "target" in a reversible manner.
The guards collection helps in testing preconditions and reporting errors.
Definition: array.h:30
root_logging_filters
These filter values are the most basic, and need to be known everywhere.
Definition: contracts.h:84
@ DEFINE_FILTER
Definition: contracts.h:85