F´ Flight Software - C/C++ Documentation  devel
A framework for building embedded system applications to NASA flight quality standards.
ObjBase.cpp
Go to the documentation of this file.
1 #include <FpConfig.hpp>
2 #include <Fw/Obj/ObjBase.hpp>
3 #include <cstring>
4 #include <cstdio>
5 #include <Fw/Types/Assert.hpp>
6 
7 namespace Fw {
8 
9 #if FW_OBJECT_REGISTRATION == 1
10  ObjRegistry* ObjBase::s_objRegistry = nullptr;
11 #endif
12 
13 #if FW_OBJECT_NAMES == 1
14  ObjBase::ObjBase(const char* objName) {
15  if (nullptr == objName) {
16  this->setObjName("NoName");
17  } else {
18  this->setObjName(objName);
19  }
20  }
21 #else
22  ObjBase::ObjBase(const char* objName) {
23 
24  }
25 #endif
26 
27  void ObjBase::init() {
28 #if FW_OBJECT_REGISTRATION
29  if (ObjBase::s_objRegistry) {
30  ObjBase::s_objRegistry->regObject(this);
31  }
32 #endif
33  }
34 
36 
37  }
38 
39 #if FW_OBJECT_NAMES == 1
40  const char* ObjBase::getObjName() {
41  return this->m_objName.toChar();
42  }
43 
44  void ObjBase::setObjName(const char* name) {
45  this->m_objName = name;
46  }
47 #if FW_OBJECT_TO_STRING == 1
48  void ObjBase::toString(char* str, NATIVE_INT_TYPE size) {
49  FW_ASSERT(size > 0);
50  FW_ASSERT(str != nullptr);
51  PlatformIntType status = snprintf(str, static_cast<size_t>(size), "Obj: %s", this->m_objName.toChar());
52  if (status < 0) {
53  str[0] = 0;
54  }
55  }
56 #endif
57 #endif
58 
59 #if FW_OBJECT_REGISTRATION == 1
60  void ObjBase::setObjRegistry(ObjRegistry* reg) {
61  ObjBase::s_objRegistry = reg;
62  }
63 
64  ObjRegistry::~ObjRegistry() {
65  }
66 
67 #endif
68 } // Fw
#define FW_ASSERT(...)
Definition: Assert.hpp:14
PlatformIntType NATIVE_INT_TYPE
Definition: BasicTypes.h:55
int PlatformIntType
DefaultTypes.hpp provides fallback defaults for the platform types.
C++-compatible configuration header for fprime configuration.
Declarations for Fw::ObjBase and Fw::ObjRegistry.
void init()
Object initializer.
Definition: ObjBase.cpp:27
virtual ~ObjBase()
Destructor.
Definition: ObjBase.cpp:35
ObjBase(const char *name)
ObjBase constructor.
Definition: ObjBase.cpp:22