QMCPACK
OhmmsObject.h
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2016 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
8 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
9 //
10 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
11 //////////////////////////////////////////////////////////////////////////////////////
12 
13 
14 #ifndef OHMMS_OHMMSOBJECT_H
15 #define OHMMS_OHMMSOBJECT_H
16 #ifdef HAVE_CONFIG_H
17 #include "config.h"
18 #endif
20 #include <string>
21 
22 /**@file OhmmsObject.h
23  *@brief Declaration of OhmmsObject
24  */
25 
26 /** An OhmmsElementBase with extra members to keep track the object/type.
27  *
28  *Additional data members of OhmmsObject are
29  * - TypeName: the name of a type, e.g., PositionType
30  * - ObjectID: an ID for this object assigned by a constructor
31  * - ElementByteSize: the byte size of an object. A derived class specifies the value.
32  * - ObjectCounter: static data member. Incremented whenever an OhmmsObject is created.
33  *
34  *It is common for class libraries or applications to have a base
35  *class that has an object counter for garbage collections and other
36  *functions. This base class is not that smart but enables keeping
37  *track the list unique for a process and makes it easy to retrieve an
38  *object with a name.
39  *
40  *@todo This class should be integrated into OhmmsElementBase or
41  *an equivalent base class.
42  */
44 {
45 public:
46  OhmmsObject();
47  OhmmsObject(const std::string& tname, const std::string& oname);
48  ~OhmmsObject() override;
49 
50  ///return the ObjectID which is unique to each object
51  int id() const { return ObjectID; }
52 
53  ///overwrite ObjectID
54  void setID(int i) { ObjectID = i; }
55 
56  ///returns the byte size of the object
57  int elementByteSize() const { return ElementByteSize; }
58 
59  ///set the type name
60  void setTypeName(const std::string& tname) { TypeName = tname; }
61 
62  ///set the object name
63  void setObjName(const std::string& oname) { myName = oname; }
64 
65  ///return the type name
66  const std::string& typeName() const { return TypeName; }
67 
68  ///return the object name
69  const std::string& objName() const { return myName; }
70 
71  virtual OhmmsObject* makeClone() const = 0;
72 
73 protected:
74  ///the type name of this object
75  std::string TypeName;
76 
77  ///the unique ID of this object
78  int ObjectID;
79 
80  ///the byte size of this object
82 
83 private:
84  //static int ObjectCounter;
85 };
86 #endif
~OhmmsObject() override
Definition: OhmmsObject.cpp:52
const std::string & typeName() const
return the type name
Definition: OhmmsObject.h:66
void setTypeName(const std::string &tname)
set the type name
Definition: OhmmsObject.h:60
std::string myName
the name of the node, corresponds to the xml tag
virtual OhmmsObject * makeClone() const =0
int elementByteSize() const
returns the byte size of the object
Definition: OhmmsObject.h:57
int id() const
return the ObjectID which is unique to each object
Definition: OhmmsObject.h:51
void setID(int i)
overwrite ObjectID
Definition: OhmmsObject.h:54
Declaration of OhmmsElementBase and define xml-related macros.
int ObjectID
the unique ID of this object
Definition: OhmmsObject.h:78
An OhmmsElementBase with extra members to keep track the object/type.
Definition: OhmmsObject.h:43
int ElementByteSize
the byte size of this object
Definition: OhmmsObject.h:81
Abstract class to provide xml-compatible I/O interfaces for the derived classes.
void setObjName(const std::string &oname)
set the object name
Definition: OhmmsObject.h:63
std::string TypeName
the type name of this object
Definition: OhmmsObject.h:75
const std::string & objName() const
return the object name
Definition: OhmmsObject.h:69
OhmmsObject()
default constructor
Definition: OhmmsObject.cpp:28