Remove dynamic exceptions
[anna.git] / source / core / util / Component.cpp
1 // ANNA - Anna is Not Nothingness Anymore                                                         //
2 //                                                                                                //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
4 //                                                                                                //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite                           //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
7
8
9 #include <anna/core/util/Component.hpp>
10 #include <anna/core/util/ComponentManager.hpp>
11
12 #include <anna/core/RuntimeException.hpp>
13 #include <anna/core/functions.hpp>
14 #include <anna/xml/Node.hpp>
15 #include <anna/xml/Attribute.hpp>
16 #include <anna/core/tracing/Logger.hpp>
17
18
19 anna::Component::Component(const char* className) :
20   a_className(className) {
21   ComponentManager &cm = ComponentManager::instantiate();
22
23   try {
24     cm.attach(this);
25   } catch(anna::RuntimeException& ex) {
26     ex.trace();
27   }
28 }
29
30 anna::Component::~Component() {
31   ComponentManager &cm = ComponentManager::instantiate();
32
33   try {
34     cm.detach(this);
35   } catch(anna::RuntimeException& ex) {
36     ex.trace();
37   }
38 }
39
40 std::string anna::Component::asString() const
41 {
42   std::string result("anna::Component { Name: ");
43   result += a_className;
44   result += " | Reference: ";
45   result += anna::functions::asHexString(anna_ptrnumber_cast(this));
46   return result += " }";
47 }
48
49 anna::xml::Node* anna::Component::asXML(anna::xml::Node* parent) const
50 {
51   anna::xml::Node* result = parent->createChild("anna.Component");
52   result->createAttribute("Name", a_className);
53   result->createAttribute("Reference", anna::functions::asHexString(anna_ptrnumber_cast(this)));
54   return result;
55 }
56