PetaVision  Alpha
KeywordHandler.cpp
1 /*
2  * KeywordHandler.cpp
3  *
4  * Created on: Jan 20, 2016
5  * Author: pschultz
6  */
7 
8 #include "KeywordHandler.hpp"
9 #include <cerrno>
10 #include <cstdio>
11 #include <cstdlib>
12 #include <cstring>
13 #include <include/pv_common.h>
14 
15 namespace PV {
16 
17 KeywordHandler::KeywordHandler(char const *kw, ObjectCreateFn creator) { initialize(kw, creator); }
18 
20  initialize(orig.getKeyword(), orig.getCreator());
21 }
22 
24  free(keyword);
25  initialize(orig.getKeyword(), orig.getCreator());
26  return *this;
27 }
28 
29 int KeywordHandler::initialize(char const *kw, ObjectCreateFn creator) {
30  keyword = strdup(kw);
31  if (keyword == NULL) {
32  Fatal().printf("KeywordHandler unable to store type \"%s\": %s\n", keyword, strerror(errno));
33  }
34  this->creator = creator;
35  return PV_SUCCESS;
36 }
37 
38 BaseObject *KeywordHandler::create(char const *name, HyPerCol *hc) const {
39  return (creator)(name, hc);
40 }
41 
42 KeywordHandler::~KeywordHandler() { free(keyword); }
43 
44 } /* namespace PV */
BaseObject * create(char const *name, HyPerCol *hc) const
KeywordHandler(char const *kw, ObjectCreateFn creator)
ObjectCreateFn getCreator() const
KeywordHandler & operator=(KeywordHandler const &orig)
const char * getKeyword() const
int initialize(char const *kw, BaseObject *(*creator)(char const *name, HyPerCol *hc))