SMIL  0.9.1
DBaseObject.h
1 /*
2  * Copyright (c) 2011-2016, Matthieu FAESSEL and ARMINES
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of Matthieu FAESSEL, or ARMINES nor the
14  * names of its contributors may be used to endorse or promote products
15  * derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY
18  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 
30 #ifndef _D_BASEOBJECT_H
31 #define _D_BASEOBJECT_H
32 
33 #include <iostream>
34 #include <sstream>
35 
36 #include <string>
37 
38 
39 #include "DCommon.h"
40 #include "DSlot.h"
41 #include "DCoreInstance.h"
42 
43 using namespace std;
44 
45 namespace smil
46 {
47 
48  class Core;
49 
53  class BaseObject
54  {
55  public:
56 // BaseObject(bool _register=true);
57  BaseObject(const char *_className, bool _register=true)
58  : triggerEvents(true),
59  registered(false),
60  className(_className),
61  name("")
62  {
63  if (_register)
64  {
65  Core *core = Core::getInstance();
66  if (core)
67  core->registerObject(this);
68  }
69  }
70  BaseObject(const BaseObject &rhs, bool _register=true)
71  : registered(false),
72  className(rhs.className),
73  name("")
74  {
75  this->_clone(rhs);
76  if (_register)
77  {
78  Core *core = Core::getInstance();
79  if (core)
80  core->registerObject(this);
81  }
82  }
83 
84  virtual ~BaseObject()
85  {
86  if (registered)
87  {
88  Core *core = Core::getInstance();
89  if (core)
90  core->unregisterObject(this);
91  }
92  }
93 
94  // Assignment operator
95  BaseObject& operator=(const BaseObject &rhs)
96  {
97  this->_clone(rhs);
98  return *this;
99  }
100 
101  private:
102  void _clone(const BaseObject &rhs)
103  {
104  this->className = rhs.getClassName();
105  this->triggerEvents = rhs.triggerEvents;
106  }
107 
108  public:
109 
110 
111  Core *getCoreInstance();
112  typedef void parentClass;
113  virtual const char *getInfoString(const char * = "") const { return NULL; }
114  virtual void printSelf(ostream & = std::cout, string ="") const {}
115  virtual const char *getClassName() const
116  {
117  return this->className.c_str();
118  }
119 
120  virtual void setName(const char *_name)
121  {
122  name = _name;
123  }
124  virtual const char *getName() const
125  {
126  return name.c_str();
127  }
128  typedef void(BaseObject::*voidMemberFunc)();
129 
130  virtual size_t getAllocatedSize() const
131  {
132  return sizeof(*this);
133  }
134  bool triggerEvents;
135  protected:
136  bool registered;
137  string className;
138  string name;
139 
140  friend class Core;
141  };
142 
143 } // namespace smil
144 
145 #endif
Definition: DColorConvert.h:38
Base Smil Object.
Definition: DBaseObject.h:53
Core module instance.
Definition: DCoreInstance.h:57