SECompartment.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 #include <string>
13 #include <vector>
14 
15 #include <biogears/cdm/CommonDataModel.h>
16 
17 #pragma once
18 
19 CDM_BIND_DECL(CompartmentData)
20 
21 namespace biogears {
22 
23 class SEScalar;
24 class SEGasCompartment;
25 class SELiquidCompartment;
26 class SEThermalCompartment;
27 class SETissueCompartment;
28 class SESubstance;
29 class SECircuitManager;
30 
31 class BIOGEARS_API SECompartment : public Loggable {
32 protected:
33  SECompartment(const char* name, Logger* logger);
34  SECompartment(const std::string& name, Logger* logger);
35 
36 public:
37  virtual ~SECompartment() override;
38 
39  virtual void Clear();
40 
41  virtual bool Load(const CDM::CompartmentData& in, SECircuitManager* circuits = nullptr);
42  virtual CDM::CompartmentData* Unload() = 0;
43 
44 protected:
45  virtual void Unload(CDM::CompartmentData& data);
46 
47 public:
48  virtual std::string GetName() const;
49  virtual const char* GetName_cStr() const;
50 
51  virtual const SEScalar* GetScalar(const char* name) = 0;
52  virtual const SEScalar* GetScalar(const std::string& name) = 0;
53 
54  virtual bool HasChildren() const = 0; // Compartments with children contain 'read only' scalars
55 
56  virtual void StateChange() = 0;
57 
58 protected:
59  std::string m_Name;
60 
61 public:
62  template <typename CompartmentType>
63  static void FindLeaves(CompartmentType& cmpt, std::vector<CompartmentType*>& leaves)
64  {
65  for (CompartmentType* child : cmpt.GetChildren()) {
66  if (!child->HasChildren())
67  leaves.push_back(child);
68  else
69  FindLeaves(*child, leaves);
70  }
71  }
72 };
73 }
Definition: SEScalar.h:33
Definition: Logger.h:27
Definition: Logger.h:75
Class corresponding to the CompartmentData schema type.
Definition: Compartment.hxx:858
std::string m_Name
Definition: SECompartment.h:59
Definition: SECompartment.h:31
static void FindLeaves(CompartmentType &cmpt, std::vector< CompartmentType * > &leaves)
Definition: SECompartment.h:63
Definition: SEElectricalCircuit.h:18
Definition: SECircuitManager.h:53