Free Electron
RecordCookbook.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_RecordCookbook_h__
8 #define __data_RecordCookbook_h__
9 
10 namespace fe
11 {
12 
13 /**************************************************************************//**
14  @brief Instructions to set attributes of a Record
15 
16  @ingroup data
17 *//***************************************************************************/
18 class FE_DL_EXPORT RecordCookbook: public Component,
19  public Initialize<RecordCookbook>
20 {
21  public:
22  class Clear:
23  public Counted,
24  public CastableAs<Clear>
25  {
26  public:
27  Clear(sp<RecordCookbook> a_spRecordCookBook):
28  m_spRecordCookBook(a_spRecordCookBook)
29  {
30 #if FE_COUNTED_STORE_TRACKER
31  setName("RecordCookbook::Clear");
32 #endif
33  }
34  ~Clear(void)
35  { m_spRecordCookBook->clear(); }
36 
37  sp<RecordCookbook> m_spRecordCookBook;
38  };
39 
40  class Ingredient: public Instance
41  {
42  public:
43  Ingredient(void) {}
44  ~Ingredient(void);
45 
46  BWORD set(FE_UWORD a_locator,sp<BaseType>& a_rspBT,void* a_pData);
47 
48  FE_UWORD m_locator;
49  };
50 
51 typedef AutoHashMap< String, String > StringStringMap;
52 typedef AutoHashMap< String, Ingredient > StringIngredientMap;
53 typedef AutoHashMap< hp<Scope>, StringIngredientMap > ScopeCacheMap;
54 
55  RecordCookbook(void);
56 virtual ~RecordCookbook(void);
57 
58  void initialize(void);
59  void registerDependency(sp<Registry> a_spRegistry);
60 
61  void clear(void);
62 
63  /// @brief Add a prerequisite to a recipe
64  void derive(String recipeName,String parentName);
65 
66  /** @brief Return the layouts for a recipe
67 
68  Often the Layout name will match the recipe name,
69  but if a derived recipe is merging Layouts or
70  just replacing replacing initial values, it may not.
71  In this case, the parent classes are searched
72  for a required Layouts. */
73  void findLayoutList(sp<Scope> spScope,String recipeName,
74  Array<String>& rLayoutList);
75 
76  /** @brief Define an initial value for a recipe's attribute
77 
78  Redundant definitions favor the latest. */
79  void add(String recipeName,String attributeName,String value);
80 
81  /// @brief Apply initial values for a recipe to a Record
82  void cook(sp<Scope> spScope,String recipeName,Record& rRecord);
83 
84  /** @brief Recursively cook recipes
85 
86  @internal */
87  void cook_internal(sp<Scope> spScope,String recipeName,
88  Record& rRecord,BWORD try_cache,
89  StringIngredientMap* pNewCacheMap);
90 
91  /** @brief Recursively clear cached Record templates
92 
93  @internal */
94  void spoil(String recipeName);
95 
96 const String& name(void) const { return m_name; }
97 
98  StringStringsMap& factoryMultiMap(void)
99  { return m_factoryMultiMap; }
100 
101  private:
102 
103  class Recipe:
104  public Counted,
105  public CastableAs<Recipe>
106  {
107  public:
108  Recipe(void)
109  {
110 #if FE_COUNTED_STORE_TRACKER
111  setName("RecordCookbook::Recipe");
112 #endif
113  }
114 
115  void setup(String name,sp<RecordCookbook> spRecordCookBook);
116  void derive(String recipeName);
117  void adopt(String recipeName);
118  void findLayoutList(sp<Scope> spScope,
119  Array<String>& rLayoutList);
120  void add(String attributeName,String value);
121  void cook(sp<Scope> spScope,Record& rRecord,BWORD ignore_cache,
122  StringIngredientMap* pNewCacheMap);
123  void spoil(void);
124 
125  const String& name(void) const { return m_name; }
126  const String verboseName(void) const { return "Recipe " + name(); }
127 
128  private:
129 
130  String m_name;
131  hp<RecordCookbook> m_hpRecordCookbook;
132  Array<String> m_prerequisites;
133  Array<String> m_dependents;
134  StringStringMap m_attributeMap;
135  ScopeCacheMap m_cacheMap;
136  };
137 
138  sp<Recipe> lookup(String recipeName);
139 
140  String m_name;
141 
142 typedef HashMap< String,
143  sp<Recipe>,
144  hash_string,
145  eq_string > StringRecipeMap;
146 
147  StringRecipeMap m_recipeMap;
148 
149  StringStringsMap m_factoryMultiMap;
150 };
151 
152 } /* namespace */
153 
154 #endif /* __data_RecordCookbook_h__ */
Heap-based support for classes participating in fe::ptr <>
Definition: Counted.h:35
Smart pointer used with types represented by BaseType.
Definition: Instance.h:28
Instructions to set attributes of a Record.
Definition: RecordCookbook.h:18
kernel
Definition: namespace.dox:3
Per-class participation in the Initialized <> mechanism.
Definition: Initialized.h:117
Safe handle for shared pointer.
Definition: Handled.h:61
Automatically reference-counted string container.
Definition: String.h:128
Wrapper for std::vector.
Definition: Array.h:21
Reference to an instance of a Layout.
Definition: RecordSB.h:35
Base for all interfacable components.
Definition: Component.h:20
Intrusive Smart Pointer.
Definition: src/core/ptr.h:53
Per-class participation non-RTTI fallback dynamic casting mechanism.
Definition: Castable.h:192