Exotica
object.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2018, University of Edinburgh
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 notice,
9 // 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 nor the names of its contributors may be used to
14 // endorse or promote products derived from this software without specific
15 // prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 // POSSIBILITY OF SUCH DAMAGE.
28 //
29 
30 #ifndef EXOTICA_CORE_OBJECT_H_
31 #define EXOTICA_CORE_OBJECT_H_
32 
33 #include <exotica_core/tools.h>
34 #include <string> // C++ type strings
35 
36 #include <exotica_core/object_initializer.h>
37 #include <exotica_core/property.h>
38 
39 namespace exotica
40 {
41 template <typename BO>
42 class Factory;
43 
44 class Object
45 {
46  template <typename BO>
47  friend class Factory;
48 
49 public:
51  : ns_(""), debug_(false)
52  {
53  }
54 
55  virtual ~Object()
56  {
57  }
58 
61  inline virtual std::string type() const
62  {
63  return GetTypeName(typeid(*this));
64  }
65 
66  std::string GetObjectName()
67  {
68  return object_name_;
69  }
70 
71  void InstantiateObject(const Initializer& init)
72  {
73  ObjectInitializer oinit(init);
74  object_name_ = oinit.Name;
75  debug_ = oinit.Debug;
76  }
77 
78  virtual std::string Print(const std::string& prepend) const
79  {
80  return prepend + " " + object_name_ + " (" + type() + ")";
81  }
82 
83  // Namespace
84  std::string ns_;
85  std::string object_name_;
86  bool debug_;
87 };
88 } // namespace exotica
89 
90 #endif // EXOTICA_CORE_OBJECT_H_
exotica::Object::InstantiateObject
void InstantiateObject(const Initializer &init)
Definition: object.h:71
exotica::Object::type
virtual std::string type() const
Type Information wrapper: must be virtual so that it is polymorphic...
Definition: object.h:61
property.h
exotica::Object::Print
virtual std::string Print(const std::string &prepend) const
Definition: object.h:78
exotica::Object::object_name_
std::string object_name_
Definition: object.h:85
exotica::Factory
Templated Object factory for Default-constructible classes. The Factory is itself a singleton.
Definition: factory.h:61
exotica
Definition: cartpole_dynamics_solver.h:38
exotica::Object::ns_
std::string ns_
Definition: object.h:84
exotica::Object
Definition: object.h:44
exotica::Object::~Object
virtual ~Object()
Definition: object.h:55
exotica::Object::debug_
bool debug_
Definition: object.h:86
exotica::Initializer
Definition: property.h:70
exotica::Object::Object
Object()
Definition: object.h:50
tools.h
exotica::GetTypeName
std::string GetTypeName(const std::type_info &type)
exotica::Object::GetObjectName
std::string GetObjectName()
Definition: object.h:66