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 
71  operator const std::string & () const {
72  return title;
73  }
74 
75  operator drain::Flagger::ivalue_t () const {
76  return index;
77  }
78 
79 
80  /*
81  void hello(const std::string & title){
82  std::cerr << "installing " << title << '(' << index << ')' << ' ' << '"'<< title << '"' << std::endl;
83  }
84  */
85 
86 
87 protected:
88 
93  CommandSection(const std::string & title, drain::Flagger::ivalue_t index) : title(title), index(index){
94  if (index > 0)
95  drain::getCommandBank().sections.add(title, index);
96  }
97 
98 
99 };
100 
101 struct HiddenSection : public CommandSection {
102 
103  inline
104  HiddenSection(): CommandSection("hidden", 0){
105  };
106 
107 };
108 
109 
111 
112  inline
113  GeneralSection(): CommandSection("general"){
114  };
115 
116 };
117 
118 
120 
121  inline
122  TriggerSection(): CommandSection("trigger"){
123  };
124 
125 };
126 
127 
128 
129 
130 
131 
132 }
133 
134 
135 /* namespace drain */
136 
137 #endif /* DRAINLET_H_ */
138 
139 // Rack
Definition: CommandSections.h:54
CommandSection(const std::string &title, drain::Flagger::ivalue_t index)
Definition: CommandSections.h:93
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition: Log.h:308
Logger & debug(const TT &... args)
Public, yet typically used "internally", when TIMING=true.
Definition: Log.h:676
Definition: DataSelector.cpp:1277
CommandBank & getCommandBank()
Global program command registry. Optional utility.
Definition: CommandBank.cpp:51
Definition: CommandSections.h:110
Definition: CommandSections.h:101
Definition: CommandSections.h:119