Machine Learning Library
CObject.h
Go to the documentation of this file.
1 /*
2  COPYRIGHT (C) 2003 APPLIED NEUROINFORMATIC GROUP - UNIVERSITY OF BIELEFELD.
3 
4  ALL RIGHTS RESERVED.
5 
6  REDISTRIBUTION AND USE IN SOURCE AND BINARY FORM, WITH OR WITHOUT
7  MODIFICATION, REQUIRE THE PERMISSION OF THE COPYRIGHT HOLDERS.
8 
9  COMMERCIAL USE WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT HOLDERS
10  IS FORBIDDEN
11 
12  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
13  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15  ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
16  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
18  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
19  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
20  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
21  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22 */
23 
24 
25 
26 #ifndef COBJECT_H
27 #define COBJECT_H
28 
29 #include <fstream>
30 #include <iostream>
31 #include <string>
32 #include <stdio.h>
33 
34 class CArchiv;
35 
36 using namespace std;
38 enum IO_MODE { READ, WRITE};
39 enum DATATYPE { INT, FLOAT, DOUBLE };
40 
41 #define COUT(msg,level) { if( level && level <= (int) this->verbose() ) cout << msg << endl; }
42 
43 
44 
45 
50 template<class Type>
51 class CObject {
52 protected:
53  unsigned char ucVerbose;
54 
55 public:
57  CObject();
58 
60  virtual ~CObject();
61 
62 
64 
70  virtual bool serialize(fstream& stream, IO_MODE mode=READ);
71  virtual bool serialize2(CArchiv& tArchiv) {return true;};
72 
74  virtual string className() const { return string("CObject"); };
75 
77 
80  void setVerbose(VERBOSE_LEVEL tVerbose) {this->ucVerbose= (unsigned char) tVerbose;}
81 
83 
86  VERBOSE_LEVEL verbose(void) const { return (VERBOSE_LEVEL) ucVerbose;}
87 
89  /*
90  * If the object class doesn't match the given class, the method searches upward in the class hierarchy
91  * @param acClass Name of class
92  */
93  virtual bool isA(const char* acClass) const { if(string(acClass) == string(this->className())) return true; else return false; };
94 
96 
99  DATATYPE dataType() const ;
100 };
101 
102 #endif
DATATYPE
Definition: CObject.h:39
Definition: CObject.h:38
IO_MODE
Definition: CObject.h:38
virtual string className() const
Returns the class name.
Definition: CObject.h:74
VERBOSE_LEVEL verbose(void) const
Return current verbose level.
Definition: CObject.h:86
Definition: CObject.h:37
Definition: CObject.h:39
Definition: CObject.h:37
unsigned char ucVerbose
Definition: CObject.h:53
Definition: CObject.h:38
VERBOSE_LEVEL
Definition: CObject.h:37
void setVerbose(VERBOSE_LEVEL tVerbose)
Set the verbose level.
Definition: CObject.h:80
Base class of object serialization.
Definition: CArchiv.h:19
Definition: CObject.h:39
Base class for all object.
Definition: CObject.h:51
virtual bool serialize2(CArchiv &tArchiv)
Definition: CObject.h:71
Definition: CObject.h:39
virtual bool isA(const char *acClass) const
Check if the object is an instance of the class with given name.
Definition: CObject.h:93
Definition: CObject.h:37
Definition: CObject.h:37