CommandSections.h
1 /*
2 
3 MIT License
4 
5 Copyright (c) 2017 FMI Open Development / Markus Peura, first.last@fmi.fi
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files (the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions:
13 
14 The above copyright notice and this permission notice shall be included in all
15 copies or substantial portions of the Software.
16 
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 SOFTWARE.
24 
25 */
26 /*
27 Part of Rack development has been done in the BALTRAD projects part-financed
28 by the European Union (European Regional Development Fund and European
29 Neighbourhood Partnership Instrument, Baltic Sea Region Programme 2007-2013)
30 */
31 
32 #ifndef DRAIN_CMD_SECTIONS_H_
33 #define DRAIN_CMD_SECTIONS_H_
34 
35 #include <drain/Log.h>
36 #include <map>
37 #include <set>
38 //#include "drain/util/Debug.h"
39 //#include "drain/util/ReferenceMap.h"
40 
41 #include "drain/util/ReferenceMap.h"
42 
43 //#include "Command.h"
44 //#include "CommandRegistry.h"
45 
46 #include "CommandBank.h"
47 
48 
49 namespace drain {
50 
51 
52 
53 
55 
56 
57 public:
58 
59  CommandSection(const std::string & title) : title(title), index(drain::getCommandBank().addSection(title)){
60  Logger mout(__FILE__, __FUNCTION__);
61  //std::cerr << __FUNCTION__ << ':' << title << '(' << index << ')' << std::endl;
62  mout.debug(__FUNCTION__ , ':' , title , '(' , index , ')' );
63  }
64 
65  // Consider trying static?
66 
67  const std::string title;
68 
69  //const drain::Flagger::ivalue_t index;
70  const bank_section_t index;
71 
72  operator const std::string & () const {
73  return title;
74  }
75 
76  operator bank_section_t () const { // drain::Flagger::ivalue_t
77  return index;
78  }
79 
80 
81  /*
82  void hello(const std::string & title){
83  std::cerr << "installing " << title << '(' << index << ')' << ' ' << '"'<< title << '"' << std::endl;
84  }
85  */
86 
87 
88 protected:
89  // drain::Flagger::ivalue_t
94  CommandSection(const std::string & title, bank_section_t index) : title(title), index(index){
95  if (index > 0)
96  drain::getCommandBank().sections.add(title, index);
97  }
98 
99 
100 };
101 
102 struct HiddenSection : public CommandSection {
103 
104  inline
105  HiddenSection(): CommandSection("hidden", 0){
106  };
107 
108 };
109 
110 
112 
113  inline
114  GeneralSection(): CommandSection("general"){
115  };
116 
117 };
118 
119 
121 
122  inline
123  TriggerSection(): CommandSection("trigger"){
124  };
125 
126 };
127 
128 
129 
130 
131 
132 
133 }
134 
135 
136 /* namespace drain */
137 
138 #endif /* DRAINLET_H_ */
139 
140 // Rack
Definition: CommandSections.h:54
CommandSection(const std::string &title, bank_section_t index)
Definition: CommandSections.h:94
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition: Log.h:310
Logger & debug(const TT &... args)
Public, yet typically used "internally", when TIMING=true.
Definition: Log.h:678
Definition: DataSelector.cpp:1277
CommandBank & getCommandBank()
Global program command registry. Optional utility.
Definition: CommandBank.cpp:51
Definition: CommandSections.h:111
Definition: CommandSections.h:102
Definition: CommandSections.h:120