SECircuit.h
1 /**************************************************************************************
2 Copyright 2015 Applied Research Associates, Inc.
3 Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 this file except in compliance with the License. You may obtain a copy of the License
5 at:
6 http://www.apache.org/licenses/LICENSE-2.0
7 Unless required by applicable law or agreed to in writing, software distributed under
8 the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
9 CONDITIONS OF ANY KIND, either express or implied. See the License for the
10 specific language governing permissions and limitations under the License.
11 **************************************************************************************/
12 
13 #pragma once
14 #include <biogears/cdm/CommonDataModel.h>
15 #include <biogears/cdm/circuit/SECircuitNode.h>
16 #include <biogears/cdm/circuit/SECircuitPath.h>
17 
18 #define CIRCUIT_TEMPLATE typename CircuitBindType, typename NodeType, typename CircuitNodeBindType, typename PathType, typename CircuitPathBindType
19 #define CIRCUIT_TYPES CircuitBindType, NodeType, CircuitNodeBindType, PathType, CircuitPathBindType
20 
21 CDM_BIND_DECL(CircuitData)
22 
23 namespace biogears {
24 template <CIRCUIT_TEMPLATE>
25 class SECircuit : public Loggable {
26 public:
27  SECircuit(const char* name, Logger* logger);
28  SECircuit(const std::string& name, Logger* logger);
29  virtual ~SECircuit();
30 
31  virtual void Clear(); //clear memory
32 
33  virtual bool Load(const CircuitBindType& in, const std::map<std::string, NodeType*>& nodes, const std::map<std::string, PathType*>& paths);
34  virtual CircuitBindType* Unload() const;
35 
36 protected:
37  virtual void Unload(CircuitBindType& data) const;
38 
39 public:
40  virtual std::string GetName() const;
41  virtual const char* GetName_cStr() const;
42 
43  virtual bool HasReferenceNode() const;
44  virtual bool IsReferenceNode(NodeType& node) const;
45  virtual const std::vector<NodeType*>& GetReferenceNodes() const;
46  virtual void AddReferenceNode(NodeType& node);
47 
48  // Nodes //
49  virtual void AddNode(NodeType& node);
50  virtual bool HasNode(NodeType& node);
51  virtual bool HasNode(const char* name);
52  virtual bool HasNode(const std::string& name);
53  virtual NodeType* GetNode(const char* name);
54  virtual NodeType* GetNode(const std::string& name);
55  virtual const NodeType* GetNode(const char* name) const;
56  virtual const NodeType* GetNode(const std::string& name) const;
57  virtual const std::vector<NodeType*>& GetNodes() const;
58  virtual void RemoveNode(const NodeType& node);
59  virtual void RemoveNode(const char* name);
60  virtual void RemoveNode(const std::string& name);
61  size_t GetCalculatorIndex(const NodeType& node) const; // Does not count the reference node
62 
63  // Paths //
64  virtual void AddPath(PathType& node);
65  virtual bool HasPath(PathType& node);
66  virtual bool HasPath(const char* name);
67  virtual bool HasPath(const std::string& name);
68  virtual PathType* GetPath(const char* name);
69  virtual PathType* GetPath(const std::string& name);
70  virtual const PathType* GetPath(const char* name) const;
71  virtual const PathType* GetPath(const std::string& name) const;
72  virtual const std::vector<PathType*>& GetPaths() const;
73  virtual void RemovePath(const PathType& path);
74  virtual void RemovePath(const char* name);
75  virtual void RemovePath(const std::string& name);
76  virtual const std::vector<PathType*>& GetValvePaths();
77  virtual const std::vector<PathType*>& GetPolarizedElementPaths();
78 
79  virtual const std::vector<PathType*>* GetTargetPaths(const NodeType& node) const;
80  virtual const std::vector<PathType*>* GetSourcePaths(const NodeType& node) const;
81  virtual const std::vector<PathType*>* GetConnectedPaths(const NodeType& node) const;
82 
83  virtual void StateChange();
84  virtual void SetNextAndCurrentFromBaselines();
85 
86 protected:
87  std::string m_Name;
88  std::stringstream m_ss;
89 
90  std::vector<NodeType*> m_ReferenceNodes;
91  std::vector<NodeType*> m_Nodes;
92  std::vector<PathType*> m_Paths;
93 
94  std::map<const NodeType*, std::vector<PathType*>*> m_TargetPathMap;
95  std::map<const NodeType*, std::vector<PathType*>*> m_SourcePathMap;
96  std::map<const NodeType*, std::vector<PathType*>*> m_ConnectedPathMap;
97 
98  std::vector<PathType*> m_ValvePaths;
99  std::vector<PathType*> m_PolarizedElementPaths;
100  std::map<const NodeType*, size_t> m_CalculatorIndex; // A unique id (starting at 0) for all nodes except the reference node
101 };
102 }
103 #include <biogears/cdm/circuit/SECircuit.inl>
Definition: SECircuit.h:25
std::vector< NodeType * > m_Nodes
Definition: SECircuit.h:91
std::map< const NodeType *, std::vector< PathType * > * > m_SourcePathMap
Definition: SECircuit.h:95
std::map< const NodeType *, std::vector< PathType * > * > m_ConnectedPathMap
Definition: SECircuit.h:96
Definition: Logger.h:27
std::vector< PathType * > m_ValvePaths
Definition: SECircuit.h:98
Definition: Logger.h:75
std::vector< PathType * > m_Paths
Definition: SECircuit.h:92
std::vector< PathType * > m_PolarizedElementPaths
Definition: SECircuit.h:99
std::vector< NodeType * > m_ReferenceNodes
Definition: SECircuit.h:90
std::stringstream m_ss
Definition: SECircuit.h:88
std::map< const NodeType *, std::vector< PathType * > * > m_TargetPathMap
Definition: SECircuit.h:94
std::string m_Name
Definition: SECircuit.h:87
Definition: SEElectricalCircuit.h:18
std::map< const NodeType *, size_t > m_CalculatorIndex
Definition: SECircuit.h:100