8 #include "BaseObject.hpp" 9 #include "columns/HyPerCol.hpp" 18 BaseObject::BaseObject() {
25 int BaseObject::initialize_base() {
31 int BaseObject::initialize(
const char *name, HyPerCol *hc) {
32 int status = setName(name);
33 if (status == PV_SUCCESS) {
34 status = setParent(hc);
36 if (status == PV_SUCCESS) {
43 return parent->parameters()->groupKeywordFromName(getName());
46 int BaseObject::setName(
char const *name) {
47 pvAssert(this->name == NULL);
48 int status = PV_SUCCESS;
49 this->name = strdup(name);
50 if (this->name == NULL) {
51 ErrorLog().printf(
"could not set name \"%s\": %s\n", name, strerror(errno));
57 int BaseObject::setParent(
HyPerCol *hc) {
58 pvAssert(parent == NULL);
60 int status = parentCol != NULL ? PV_SUCCESS : PV_FAILURE;
67 void BaseObject::setDescription() {
69 description = getObjectType() +
" \"" + getName() +
"\"";
72 void BaseObject::setObjectType() { mObjectType =
lookupKeyword(); }
76 parent->ioParamsStartGroup(ioFlag, name);
80 parent->ioParamsFinishGroup(ioFlag);
84 Response::Status BaseObject::respond(std::shared_ptr<BaseMessage const> message) {
86 Response::Status status = CheckpointerDataInterface::respond(message);
90 if (message ==
nullptr) {
91 return Response::NO_ACTION;
94 auto castMessage = std::dynamic_pointer_cast<CommunicateInitInfoMessage const>(message)) {
95 return respondCommunicateInitInfo(castMessage);
98 else if (
auto castMessage = std::dynamic_pointer_cast<SetCudaDeviceMessage const>(message)) {
99 return respondSetCudaDevice(castMessage);
101 #endif // PV_USE_CUDA 102 else if (
auto castMessage = std::dynamic_pointer_cast<AllocateDataMessage const>(message)) {
103 return respondAllocateData(castMessage);
105 else if (
auto castMessage = std::dynamic_pointer_cast<InitializeStateMessage const>(message)) {
106 return respondInitializeState(castMessage);
110 std::dynamic_pointer_cast<CopyInitialStateToGPUMessage const>(message)) {
111 return respondCopyInitialStateToGPU(castMessage);
113 else if (
auto castMessage = std::dynamic_pointer_cast<CleanupMessage const>(message)) {
114 return respondCleanup(castMessage);
117 return Response::SUCCESS;
122 BaseObject::respondCommunicateInitInfo(std::shared_ptr<CommunicateInitInfoMessage const> message) {
123 Response::Status status = Response::NO_ACTION;
127 status = communicateInitInfo(message);
136 BaseObject::respondSetCudaDevice(std::shared_ptr<SetCudaDeviceMessage const> message) {
137 return setCudaDevice(message);
139 #endif // PV_USE_CUDA 142 BaseObject::respondAllocateData(std::shared_ptr<AllocateDataMessage const> message) {
143 Response::Status status = Response::NO_ACTION;
147 status = allocateDataStructures();
155 BaseObject::respondInitializeState(std::shared_ptr<InitializeStateMessage const> message) {
156 auto status = Response::NO_ACTION;
158 return Response::NO_ACTION;
160 status = initializeState();
167 Response::Status BaseObject::respondCopyInitialStateToGPU(
168 std::shared_ptr<CopyInitialStateToGPUMessage const> message) {
169 return copyInitialStateToGPU();
172 Response::Status BaseObject::respondCleanup(std::shared_ptr<CleanupMessage const> message) {
177 Response::Status BaseObject::setCudaDevice(std::shared_ptr<SetCudaDeviceMessage const> message) {
179 mCudaDevice = message->mCudaDevice;
181 mCudaDevice ==
nullptr,
182 "%s received SetCudaDevice with null device pointer.\n",
185 return Response::SUCCESS;
187 #endif // PV_USE_CUDA 189 BaseObject::~BaseObject() { free(name); }
bool getInitialValuesSetFlag() const
bool getDataStructuresAllocatedFlag() const
static bool completed(Status &a)
virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag)
char const * lookupKeyword() const
void setInitInfoCommunicatedFlag()
void setDataStructuresAllocatedFlag()
void ioParams(enum ParamsIOFlag ioFlag, bool printHeader, bool printFooter)
void setInitialValuesSetFlag()
bool getInitInfoCommunicatedFlag() const