Free Electron
InstanceMap.h
Go to the documentation of this file.
1 /* Copyright (C) 2003-2021 Free Electron Organization
2  Any use of this software requires a license. If a valid license
3  was not distributed with this file, visit freeelectron.org. */
4 
5 /** @file */
6 
7 #ifndef __core_InstanceMap_h__
8 #define __core_InstanceMap_h__
9 
10 namespace fe
11 {
12 
13 /** @brief Group of named instances
14 
15  @ingroup core
16  */
17 class FE_DL_EXPORT InstanceMap: public std::map< String, Instance >
18 {
19  public:
20  InstanceMap(void) {}
21  InstanceMap(sp<TypeMaster> a_spTypeMaster):
22  m_spTypeMaster(a_spTypeMaster) {}
23  ~InstanceMap(void) {}
24 
25  void deepCopy(const InstanceMap& r_other);
26 
27  BWORD exists(String a_name) const
28  { return find(a_name)!=end(); }
29 
30  template<class T>
31  T& create(String a_name)
32  {
33  FEASSERT(m_spTypeMaster.isValid());
34  T& rT=(*this)[a_name].create<T>(m_spTypeMaster);
35  return rT;
36  }
37 
38  template<class T>
39  T& property(String a_name)
40  {
41  if(!exists(a_name))
42  {
43  create<T>(a_name);
44  }
45  return (*this)[a_name].cast<T>();
46  }
47 
48  private:
49  sp<TypeMaster> m_spTypeMaster;
50 };
51 
52 } /* namespace */
53 #endif /* __core_InstanceMap_h__ */
kernel
Definition: namespace.dox:3
Automatically reference-counted string container.
Definition: String.h:128
Group of named instances.
Definition: InstanceMap.h:17