1
// ---------------------------------------------------------------------------
3
// - standard object library - boolean class definition -
4
// ---------------------------------------------------------------------------
5
// - This program is free software; you can redistribute it and/or modify -
6
// - it provided that this copyright notice is kept intact. -
8
// - This program is distributed in the hope that it will be useful, but -
9
// - without any warranty; without even the implied warranty of -
10
// - merchantability or fitness for a particular purpose. In no event shall -
11
// - the copyright holder be liable for any direct, indirect, incidental or -
12
// - special damages arising in any way out of the use of this software. -
13
// ---------------------------------------------------------------------------
14
// - copyright (c) 1999-2007 amaury darsch -
15
// ---------------------------------------------------------------------------
17
#ifndef AFNIX_BOOLEAN_HPP
18
#define AFNIX_BOOLEAN_HPP
20
#ifndef AFNIX_LITERAL_HPP
21
#include "Literal.hpp"
26
/// The Boolean class is a builtin object for the boolean native type.
27
/// The Boolean class accepts only two values (true or false) and is mostly
28
/// used for binary testing. There is no automatic conversion from or to the
29
/// boolean type - except for string representation.
30
/// @author amaury darsch
32
class Boolean : public Literal {
34
/// the native boolean representation
38
/// create a new default boolean - by default it is false
41
/// create a new boolean from a native boolean
42
/// @param value the value to create
43
Boolean (const bool value);
45
/// create a new boolean from a string
46
/// @param value the value to convert
47
Boolean (const String& value);
49
/// copy constructor for this boolean
50
/// @param that the boolean class to copy
51
Boolean (const Boolean& that);
53
/// @return the class name
54
String repr (void) const;
56
/// @return a literal representation of this boolean
57
String toliteral (void) const;
59
/// @return a string representation of this boolean
60
String tostring (void) const;
62
/// @return a clone of this boolean
63
Object* clone (void) const;
65
/// @return the boolean serial code
66
t_byte serialid (void) const;
68
/// serialize this boolean to an output stream
69
/// @param os the output stream to write
70
void wrstream (class Output& os) const;
72
/// deserialize a boolean from an input stream
73
/// @param is the input steam to read in
74
void rdstream (class Input& is);
76
/// @return the boolean value of this boolean
77
bool toboolean (void) const;
79
/// assign a boolean with a native value
80
/// @param value the value to assign
81
Boolean& operator = (const bool value);
83
/// assign a boolean with a boolean
84
/// @param value the value to assign
85
Boolean& operator = (const Boolean& value);
87
/// compare this boolean with a native value
88
/// @param value the value to compare
89
/// @return true if they are equals
90
bool operator == (const bool value) const;
92
/// compare this boolean with a native value
93
/// @param value the value to compare
94
/// @return true if they are not equals
95
bool operator != (const bool value) const;
97
/// compare two booleans
98
/// @param value the value to compare
99
/// @return true if they are equals
100
bool operator == (const Boolean& value) const;
102
/// compare two boolean
103
/// @param value the value to compare
104
/// @return true if they are not equals
105
bool operator != (const Boolean& value) const;
108
/// evaluate an object to a boolean value
109
/// @param robj the current runnable
110
/// @param nset the current nameset
111
/// @param object the object to evaluate
112
static bool evalto (Runnable* robj, Nameset* nset, Object* object);
114
/// create a new object in a generic way
115
/// @param argv the argument vector
116
static Object* mknew (Vector* argv);
118
/// @return true if the given quark is defined
119
bool isquark (const long quark, const bool hflg) const;
121
/// operate this object with another object
122
/// @param type the operator type
123
/// @param object the operand object
124
Object* oper (t_oper type, Object* object);
126
/// set an object to this boolean
127
/// @param robj the current runnable
128
/// @param nset the current nameset
129
/// @param object the object to set
130
Object* vdef (Runnable* robj, Nameset* nset, Object* object);
132
/// apply this object with a set of arguments and a quark
133
/// @param robj the current runnable
134
/// @param nset the current nameset
135
/// @param quark the quark to apply these arguments
136
/// @param argv the arguments to apply
137
Object* apply (Runnable* robj, Nameset* nset, const long quark,
141
// the memory allocation
142
void* operator new (const t_size size);
143
void operator delete (void* handle);