CASM  1.1.0
A Clusters Approach to Statistical Mechanics
Named_impl.hh
Go to the documentation of this file.
1 #ifndef CASM_Named_impl
2 #define CASM_Named_impl
3 
5 #include "casm/database/Named.hh"
6 
7 namespace CASM {
8 namespace DB {
9 
10 template <typename Base>
11 Named<Base>::Named() : m_name("") {}
12 
13 template <typename Base>
14 std::string Named<Base>::name() const {
15  if (m_name.empty()) {
16  regenerate_name();
17  }
18  return m_name;
19 }
20 
23 template <typename Base>
24 std::string Named<Base>::alias() const {
25  return derived().primclex().template db<MostDerived>().alias(name());
26 }
27 
29 template <typename Base>
31  m_name = "";
32 }
33 
35 template <typename Base>
37  m_name = derived().generate_name_impl();
38 }
39 
41 template <typename Base>
42 void Named<Base>::set_name(std::string _name) const {
43  m_name = _name;
44 }
45 
46 template <typename _Base>
47 Indexed<_Base>::Indexed() : m_id("none") {}
48 
49 template <typename _Base>
50 std::string Indexed<_Base>::id() const {
51  return m_id;
52 }
53 
54 // If 'id' is already known, just return configname
55 template <typename _Base>
56 std::string Indexed<_Base>::name() const {
57  if (id() == "none") {
58  this->regenerate_name();
59  }
60  return Named<_Base>::name();
61 }
62 
64 template <typename _Base>
66  m_id = "none";
68 }
69 
75 template <typename _Base>
76 void Indexed<_Base>::set_id(Index _id) const {
77  set_id(std::to_string(_id));
78 }
79 
85 template <typename _Base>
86 void Indexed<_Base>::set_id(std::string _id) const {
88  m_id = _id;
89 }
90 
91 } // namespace DB
92 } // namespace CASM
93 
94 #endif
std::string id() const
Definition: Named_impl.hh:50
void clear_name() const
Unset "id" and "name", if object is modified.
Definition: Named_impl.hh:65
void set_id(Index _id) const
Set id.
Definition: Named_impl.hh:76
std::string name() const
Definition: Named_impl.hh:56
void regenerate_name() const
Regenerate "name".
Definition: Named_impl.hh:36
std::string alias() const
Return "alias" if object stored in database and alias exists, return empty string otherwise.
Definition: Named_impl.hh:24
void set_name(std::string _name) const
Set "name", explicity.
Definition: Named_impl.hh:42
std::string name() const
Definition: Named_impl.hh:14
void clear_name() const
Unset "name", if object is modified.
Definition: Named_impl.hh:30
std::string to_string(ENUM val)
Return string representation of enum class.
Definition: io_traits.hh:172
Main CASM namespace.
Definition: APICommand.hh:8
GenericDatumFormatter< std::string, DataObject > name()
INDEX_TYPE Index
For long integer indexing:
Definition: definitions.hh:39