University of Sheffield   

    The Simons
    Component Library

Introduction   Class Hierarchy   Class Listing   Index of Classes   Index of Methods   Header Files  

Value.h

00001 
00002 //
00003 //  SCL : Simons Component Library
00004 //
00006 //
00007 //  Filename:   Value.h
00008 //  Contents:   Value class
00009 //  Author:     Anthony J H Simons
00010 //  Revised:    9 November 2005
00011 
00012 // This software is distributed free in the hope that others will
00013 // find it useful.  However, it comes WITHOUT ANY WARRANTY.  No
00014 // liability can be accepted for software failure, merchantability
00015 // or fitness for a particular purpose.  You can redistribute this
00016 // software in its original form, or in a modified form, provided
00017 // that this disclaimer is retained in the file banner.
00018 
00019 #ifndef SCL_VALUE
00020 #define SCL_VALUE
00021 
00022 #include "Object.h"             // Include my superclass type
00023 #include "ValueID.h"            // Include my pointer type
00024 
00025 #include "TypeID.h"             // Depends on these pointer types
00026 #include "ReaderID.h"
00027 #include "WriterID.h"
00028 
00036 
00037 class Value : public Object {
00038 protected:
00039         Value(const Value&);
00040 public:
00041         Value();
00042         virtual ~Value();
00043 };
00044 
00046 class BooleanBox : public Value {
00047 private:
00048         Boolean wrapped;
00049         BooleanBox(const BooleanBox&);
00050 public:
00051         BooleanBox();
00052         ~BooleanBox();
00053         BooleanBox(Boolean);
00054         virtual ObjectID clone() const;
00055         virtual TypeID type() const;
00056         virtual Natural hash() const;
00057         virtual Order compare(ObjectID) const;
00058         Void readOn(ReaderID);
00059         Void writeOn(WriterID) const;
00060         virtual Boolean toBoolean() const;
00061 };
00062 
00064 class CharacterBox : public Value {
00065 private:
00066         Character wrapped;
00067         CharacterBox(const CharacterBox&);
00068 public:
00069         CharacterBox();
00070         ~CharacterBox();
00071         CharacterBox(Character);
00072         virtual ObjectID clone() const;
00073         virtual TypeID type() const;
00074         virtual Natural hash() const;
00075         virtual Order compare(ObjectID) const;
00076         Void readOn(ReaderID);
00077         Void writeOn(WriterID) const;
00078         virtual Character toCharacter() const;
00079 };
00080 
00082 class NaturalBox : public Value {
00083 private:
00084         Natural wrapped;
00085         NaturalBox(const NaturalBox&);
00086 public:
00087         NaturalBox();
00088         ~NaturalBox();
00089         NaturalBox(Natural);
00090         virtual ObjectID clone() const;
00091         virtual TypeID type() const;
00092         virtual Natural hash() const;
00093         virtual Order compare(ObjectID) const;
00094         Void readOn(ReaderID);
00095         Void writeOn(WriterID) const;
00096         virtual Natural toNatural() const;
00097 };
00098 
00100 class IntegerBox : public Value {
00101 private:
00102         Integer wrapped;
00103         IntegerBox(const IntegerBox&);
00104 public:
00105         IntegerBox();
00106         ~IntegerBox();
00107         IntegerBox(Integer);
00108         virtual ObjectID clone() const;
00109         virtual TypeID type() const;
00110         virtual Natural hash() const;
00111         virtual Order compare(ObjectID) const;
00112         Void readOn(ReaderID);
00113         Void writeOn(WriterID) const;
00114         virtual Integer toInteger() const;
00115 };
00116 
00118 class DecimalBox : public Value {
00119 private:
00120         Decimal wrapped;
00121         DecimalBox(const DecimalBox&);
00122 public:
00123         DecimalBox();
00124         ~DecimalBox();
00125         DecimalBox(Decimal);
00126         virtual ObjectID clone() const;
00127         virtual TypeID type() const;
00128         virtual Natural hash() const;
00129         virtual Order compare(ObjectID) const;
00130         Void readOn(ReaderID);
00131         Void writeOn(WriterID) const;
00132         virtual Decimal toDecimal() const;
00133 };
00134 
00136 
00140 inline Value::Value() {}
00141 
00143 inline Value::~Value() {}
00144 
00148 inline Value::Value(const Value& other) : Object(other) {}
00149 
00151 
00154 inline Natural BooleanBox::hash() const {
00155         return Natural(wrapped);
00156 }
00157 
00160 inline Boolean BooleanBox::toBoolean() const {
00161         return wrapped;
00162 }
00163 
00165 
00168 inline Natural CharacterBox::hash() const {
00169         return Natural(wrapped);
00170 }
00171 
00174 inline Character CharacterBox::toCharacter() const {
00175         return wrapped;
00176 }
00177 
00179 
00182 inline Natural NaturalBox::hash() const {
00183         return wrapped;
00184 }
00185 
00188 inline Natural NaturalBox::toNatural() const {
00189         return wrapped;
00190 }
00191 
00193 
00196 inline Natural IntegerBox::hash() const {
00197         return Natural(wrapped);
00198 }
00199 
00202 inline Integer IntegerBox::toInteger() const {
00203         return wrapped;
00204 }
00205 
00207 
00210 inline Decimal DecimalBox::toDecimal() const {
00211         return wrapped;
00212 }
00213 
00215 
00218 inline ValueID::ValueID() {}
00219 
00221 inline ValueID::~ValueID() {}
00222 
00226 inline ValueID::ValueID(const Null* null) :
00227         ObjectID(null) {}
00228         
00232 inline ValueID::ValueID(const Value* box) :
00233         ObjectID(box) {}
00234         
00238 inline ValueID::ValueID(const ValueID& pointer) :
00239         ObjectID(pointer) {}
00240         
00244 inline ValueID::ValueID(Boolean value) : ObjectID(new BooleanBox(value)) {}
00245         
00249 inline ValueID::ValueID(Character value) : ObjectID(new CharacterBox(value)) {}
00250         
00254 inline ValueID::ValueID(Integer number) : ObjectID(new IntegerBox(number)) {}
00255         
00259 inline ValueID::ValueID(Natural number) : ObjectID(new NaturalBox(number)) {}
00260         
00264 inline ValueID::ValueID(Decimal number) : ObjectID(new DecimalBox(number)) {}
00265                 
00269 inline ValueID& ValueID::operator=(const Value* box) {
00270         assign(box);
00271         return *this;
00272 }
00273 
00278 inline ValueID& ValueID::operator=(const ValueID& pointer) {
00279         assign(pointer);
00280         return *this;
00281 }
00282 
00283 
00284 #endif
00285 

Generated on Fri May 5 17:17:16 2006 for The Simons Component Library by doxygen1.3