Free Electron
Config.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 __data_Config_h__
8 #define __data_Config_h__
9 
10 #include "ConfigI.h"
11 
12 namespace fe
13 {
14 namespace ext
15 {
16 
17 /** Convienience base class for specification and use of path accessors.
18  */
19 class FE_DL_EXPORT Config : virtual public ConfigI
20 {
21  public:
22  Config(void);
23 virtual ~Config(void);
24 
25 
26  template <typename T>
27  T &cfg(const String &a_key);
28 
29 virtual void configParent(sp<ConfigI> a_parent);
30 virtual bool configLookup(const String &a_key, Instance &a_instance);
31 
32 virtual void configSet(const String &a_key, Instance &a_instance);
33 virtual void configSet(const String &a_key, Record &a_record,
34  const String &a_attr);
35 
36  private:
37  //std::map<String, String> m_dictionary;
38  sp<ConfigI> m_parent;
39  std::map<String, Instance> m_catalog;
40 };
41 
42 template <typename T>
43 T &Config::cfg(const String &a_key)
44 {
45  Instance instance;
46  bool preexists = configLookup(a_key, instance);
47 
48  if(preexists)
49  {
50  return instance.cast<T>();
51  }
52 
53  if(!registry().isValid())
54  {
55  feX("Config Components must be created so as to have a registry");
56  }
57  const sp<TypeMaster> &spTM = registry()->master()->typeMaster();
58  Instance &new_instance = m_catalog[a_key];
59  new_instance.create<T>(spTM);
60  return new_instance.cast<T>();
61 }
62 
63 } /* namespace ext */
64 } /* namespace fe */
65 
66 #endif /* __data_Config_h__ */
Convienience base class for specification and use of path accessors.
Definition: Config.h:19
ConfigI Interface See Config (implementation) for the interesting details.
Definition: ConfigI.h:19
Smart pointer used with types represented by BaseType.
Definition: Instance.h:28
kernel
Definition: namespace.dox:3
Automatically reference-counted string container.
Definition: String.h:128
Reference to an instance of a Layout.
Definition: RecordSB.h:35
Intrusive Smart Pointer.
Definition: src/core/ptr.h:53
sp< Master > master(void) const
Access the Master (ptr may not be valid)
Definition: Registry.cc:98