Darwin  1.10(beta)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
drwnInterfaces.h
1 /*****************************************************************************
2 ** DARWIN: A FRAMEWORK FOR MACHINE LEARNING RESEARCH AND DEVELOPMENT
3 ** Distributed under the terms of the BSD license (see the LICENSE file)
4 ** Copyright (c) 2007-2015, Stephen Gould
5 ** All rights reserved.
6 **
7 ******************************************************************************
8 ** FILENAME: drwnInterfaces.h
9 ** AUTHOR(S): Stephen Gould <stephen.gould@anu.edu.au>
10 **
11 *****************************************************************************/
12 
13 #pragma once
14 
15 #include <cstdlib>
16 #include <cassert>
17 
18 #include "drwnXMLParser.h"
19 
20 using namespace std;
21 
22 // drwnTypeable -------------------------------------------------------------
23 
25 class drwnTypeable {
26  public:
27  virtual ~drwnTypeable() { /* do nothing */ }
28 
30  virtual const char *type() const = 0;
31 };
32 
33 // drwnCloneable ------------------------------------------------------------
34 
37  public:
38  virtual ~drwnCloneable() { /* do nothing */ }
39 
42  virtual drwnCloneable *clone() const = 0;
43 };
44 
45 // drwnWriteable ------------------------------------------------------------
46 
48 class drwnWriteable : public drwnTypeable {
49  public:
50  virtual ~drwnWriteable() { /* do nothing */ }
51 
53  bool write(const char *filename) const;
55  bool read(const char *filename);
56 
58  virtual bool save(drwnXMLNode& xml) const = 0;
60  virtual bool load(drwnXMLNode& xml) = 0;
61 
63  void dump() const;
64 };
65 
66 // drwnStdObjIface ----------------------------------------------------------
67 
73  public:
74  virtual ~drwnStdObjIface() { /* do nothing */ }
75 };
76 
77 // helper macros ------------------------------------------------------------
78 
80 #define DRWN_TYPE_AND_CLONE_IMPL(C) \
81  virtual const char *type() const { return #C; } \
82  virtual C* clone() const { return new C(*this); }
83 
84 
interface for objects that can serialize and de-serialize themselves
Definition: drwnInterfaces.h:48
interface for an object that returns its own type as a string
Definition: drwnInterfaces.h:25
interface for cloning object (i.e., virtual copy constructor)
Definition: drwnInterfaces.h:36
Provides XML parsing functionality for serializing and deserializing objects and containers of object...
standard Darwin object interface (cloneable and writeable)
Definition: drwnInterfaces.h:72