1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
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 //
9 #include <anna/comm/functions.hpp>
11 #include <anna/comm/INetAddress.hpp>
12 #include <anna/comm/Device.hpp>
14 #include <anna/xml/Node.hpp>
15 #include <anna/xml/Attribute.hpp>
20 const comm::Device* comm::INetAddress::getDevice(const bool exceptionWhenNull) const
21 throw(RuntimeException) {
22 if(a_device == NULL && exceptionWhenNull == true) {
23 string msg(asString());
24 msg += " | No device attached";
25 throw RuntimeException(msg, ANNA_FILE_LOCATION);
31 string comm::INetAddress::asString() const
33 string result("comm::INetAddress { ");
34 result += functions::asString(a_device);
35 return result += anna::functions::asString(" | Port: %d }", a_port);
38 string comm::INetAddress::serialize() const
40 in_addr_t inaddr = (a_device) ? a_device->getAddress() : 0;
41 string result(Device::asString(inaddr));
42 return result += anna::functions::asString(".%d", a_port);
45 xml::Node* comm::INetAddress::asXML(xml::Node* parent) const
46 throw(RuntimeException) {
47 xml::Node* result = parent->createChild("comm.INetAddress");
50 a_device->asAttribute(result);
52 result->createAttribute("Device", "<null>");
54 result->createAttribute("Port", a_port);