DPsim
IdentifiedObject.h
1 /* Copyright 2017-2021 Institute for Automation of Complex Power Systems,
2  * EONERC, RWTH Aachen University
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at https://mozilla.org/MPL/2.0/.
7  *********************************************************************************/
8 
9 #pragma once
10 
11 #include <dpsim-models/AttributeList.h>
12 #include <dpsim-models/Config.h>
13 #include <dpsim-models/Definitions.h>
14 #include <dpsim-models/Utils.h>
15 
16 namespace CPS {
20 protected:
22  AttributeList::Ptr mAttributes = AttributeList::make();
23 
24 public:
29 
30  typedef std::shared_ptr<IdentifiedObject> Ptr;
31  typedef std::vector<Ptr> List;
32 
33  IdentifiedObject() {}
34 
35  IdentifiedObject(const String &uid, const String &name)
36  : mName(mAttributes->create("name", name)),
37  mUID(mAttributes->create("uid", uid)) {}
38 
39  explicit IdentifiedObject(const String &name)
40  : IdentifiedObject(name, name) {}
41 
42  virtual ~IdentifiedObject() = default;
43 
45  AttributeBase::Ptr attribute(const String &name) const {
46  return mAttributes->attribute(name);
47  }
48 
50  template <typename T>
51  typename Attribute<T>::Ptr attributeTyped(const String &name) const {
52  return mAttributes->attributeTyped<T>(name);
53  }
54 
55  const AttributeBase::Map &attributes() const {
56  return mAttributes->attributes();
57  };
58 
59  String name() { return **mName; }
61  String uid() { return **mUID; }
63  String type() { return Utils::className(this); }
64 };
65 } // namespace CPS
const Attribute< String >::Ptr mName
Human readable name.
String uid()
Returns unique id.
String type()
Get component type (cross-platform)
AttributeBase::Ptr attribute(const String &name) const
Return pointer to an attribute.
const Attribute< String >::Ptr mUID
Unique identifier.
Attribute< T >::Ptr attributeTyped(const String &name) const
Return pointer to an attribute.
AttributeList::Ptr mAttributes
Attribute List.