BioDynaMo  v1.05.120-25dc9790
param_group.h
Go to the documentation of this file.
1 // -----------------------------------------------------------------------------
2 //
3 // Copyright (C) 2021 CERN & University of Surrey for the benefit of the
4 // BioDynaMo collaboration. All Rights Reserved.
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // See the LICENSE file distributed with this work for details.
10 // See the NOTICE file distributed with this work for additional information
11 // regarding copyright ownership.
12 //
13 // -----------------------------------------------------------------------------
14 
15 #ifndef CORE_PARAM_PARAM_GROUP_H_
16 #define CORE_PARAM_PARAM_GROUP_H_
17 
18 #include <memory>
19 #include "core/util/root.h"
20 #include "cpptoml/cpptoml.h"
21 
22 namespace bdm {
23 
24 struct Param;
25 
26 using ParamGroupUid = uint64_t;
27 
28 // TODO(lukas) code duplication with `NewAgentEventUidGenerator`
31  public:
34 
35  static ParamGroupUidGenerator* Get();
36 
38 
39  private:
41  std::atomic<ParamGroupUid> counter_;
42 };
43 
45 struct ParamGroup {
46  virtual ~ParamGroup();
47 
48  virtual ParamGroup* NewCopy() const = 0;
49 
50  virtual ParamGroupUid GetUid() const = 0;
51 
52  protected:
55  virtual void AssignFromConfig(const std::shared_ptr<cpptoml::table>&);
56 
57  private:
58  friend struct Param;
60 };
61 
62 #define BDM_PARAM_GROUP_HEADER(name, version_id) \
63  static const ParamGroupUid kUid; \
64  name() {} \
65  virtual ~name() {} \
66  ParamGroup* NewCopy() const override { return new name(*this); } \
67  ParamGroupUid GetUid() const override { return kUid; } \
68  \
69  private: \
70  BDM_CLASS_DEF_OVERRIDE(name, version_id); \
71  \
72  public:
73 
74 } // namespace bdm
75 
76 #endif // CORE_PARAM_PARAM_GROUP_H_
bdm::ParamGroup::AssignFromConfig
virtual void AssignFromConfig(const std::shared_ptr< cpptoml::table > &)
Definition: param_group.cc:31
bdm::ParamGroupUidGenerator::counter_
std::atomic< ParamGroupUid > counter_
Definition: param_group.h:41
bdm
Definition: agent.cc:39
bdm::ParamGroup::NewCopy
virtual ParamGroup * NewCopy() const =0
bdm::ParamGroup::GetUid
virtual ParamGroupUid GetUid() const =0
bdm::ParamGroupUid
uint64_t ParamGroupUid
Definition: param_group.h:26
bdm::ParamGroup::~ParamGroup
virtual ~ParamGroup()
root.h
bdm::ParamGroup
Interface for parameter groups.
Definition: param_group.h:45
bdm::ParamGroupUidGenerator::operator=
ParamGroupUidGenerator & operator=(const ParamGroupUidGenerator &)=delete
bdm::ParamGroupUidGenerator::Get
static ParamGroupUidGenerator * Get()
Definition: param_group.cc:20
bdm::ParamGroup::BDM_CLASS_DEF
BDM_CLASS_DEF(ParamGroup, 1)
bdm::Param
Definition: param.h:35
bdm::ParamGroupUidGenerator::NewUid
ParamGroupUid NewUid()
Definition: param_group.cc:27
bdm::ParamGroupUidGenerator::ParamGroupUidGenerator
ParamGroupUidGenerator()
Definition: param_group.cc:25
bdm::ParamGroupUidGenerator
This class generates unique ids for parameter groups. Thread safe.
Definition: param_group.h:30