BaseObject.h
Go to the documentation of this file.
1 // This file is part of the MercuryDPM project (https://www.mercurydpm.org).
2 // Copyright (c), The MercuryDPM Developers Team. All rights reserved.
3 // License: BSD 3-Clause License; see the LICENSE file in the root directory.
4 
5 #ifndef BASEOBJECT_H
6 #define BASEOBJECT_H
7 
8 #include <iostream>
9 
10 // Foward declation of base object.
11 class BaseObject;
12 
16 std::ostream& operator<<(std::ostream& os, const BaseObject& o);
17 
21 std::istream& operator>>(std::istream& is, BaseObject& o);
22 
30 {
31 public:
35  BaseObject() = default;
36 
40  BaseObject(const BaseObject& p) = default;
41 
45  virtual ~BaseObject() = default;
46 
53  friend std::ostream& operator<<(std::ostream& os, const BaseObject& o);
54 
59  friend std::istream& operator>>(std::istream& is, BaseObject& o);
60 
65  virtual void read(std::istream& is) = 0;
66 
71  virtual void write(std::ostream& os) const = 0;
72 
76  virtual std::string getName() const = 0;
77 
81  virtual void moveInHandler(unsigned int index);
82 
86  void setIndex(unsigned int index);
87 
92  void setId(unsigned long id);
93 
97  unsigned int getIndex() const
98  { return index_; };
99 
104  unsigned int getId() const
105  { return id_; }
106 
110  void setGroupId(unsigned groupId)
111  { groupId_ = groupId; }
112 
116  unsigned getGroupId() const
117  { return groupId_; }
118 
119 private:
123  unsigned int index_ = 0;
124 
128  unsigned int id_ = 0;
129 
136  unsigned int groupId_ = 0;
137 
138 };
139 
140 #endif
std::istream & operator>>(std::istream &is, BaseObject &o)
Operator overloading for reading the data from an input stream into the BAseObject "o"
Definition: BaseObject.cc:25
float * p
Definition: Tutorial_Map_using.cpp:9
It is an abstract base class due to the purely virtual functions declared below. Even if the function...
Definition: BaseObject.h:30
virtual std::string getName() const =0
A purely virtual function.
unsigned int groupId_
Identifier of a group within handler.
Definition: BaseObject.h:136
unsigned getGroupId() const
Definition: BaseObject.h:116
friend std::ostream & operator<<(std::ostream &os, const BaseObject &o)
A purely virtual method with an implementation which reads the index from the stream and assigns it t...
Definition: BaseObject.cc:14
unsigned int getId() const
Returns the unique identifier of any particular object.
Definition: BaseObject.h:104
unsigned int id_
unique identifier within handler (remains constant even if particle is moved)
Definition: BaseObject.h:128
virtual void write(std::ostream &os) const =0
A purely virtual function which has an implementation which writes the name and the object id_ to the...
Definition: BaseObject.cc:69
unsigned int getIndex() const
Returns the index of the object in the handler.
Definition: BaseObject.h:97
BaseObject()=default
Default constructor.
void setIndex(unsigned int index)
Allows one to assign an index to an object in the handler/container.
Definition: BaseObject.cc:42
unsigned int index_
location in BaseHandler::objects_
Definition: BaseObject.h:123
void setGroupId(unsigned groupId)
Definition: BaseObject.h:110
friend std::istream & operator>>(std::istream &is, BaseObject &o)
Operator overloading for reading the data from an input stream into the BAseObject "o"
Definition: BaseObject.cc:25
virtual void moveInHandler(unsigned int index)
Except that it is virtual, it does the same thing as setIndex() does.
Definition: BaseObject.cc:34
virtual void read(std::istream &is)=0
Definition: BaseObject.cc:59
void setId(unsigned long id)
Assigns a unique identifier to each object in the handler (container) which remains constant even aft...
Definition: BaseObject.cc:50
BaseObject(const BaseObject &p)=default
Copy constructor, copies all the objects BaseObject contains.
virtual ~BaseObject()=default
virtual destructor
std::ostream & operator<<(std::ostream &s, const DenseBase< Derived > &m)
Definition: IO.h:222
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286