CLI  2.9
traces.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2006-2018, Alexis Royer, http://alexis.royer.free.fr/CLI
3 
4  All rights reserved.
5 
6  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7 
8  * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation
10  and/or other materials provided with the distribution.
11  * Neither the name of the CLI library project nor the names of its contributors may be used to endorse or promote products derived from this software
12  without specific prior written permission.
13 
14  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
22  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26 
27 
34 
35 #ifndef _CLI_TRACES_H_
36 #define _CLI_TRACES_H_
37 
38 #include "cli/namespace.h"
39 #include "cli/object.h"
40 #include "cli/help.h"
41 #include "cli/tk.h"
42 
43 
45 
46  // Forward declarations.
47  class OutputDevice;
48 
49 
51  class TraceClass : public Object
52  {
53  public:
56  typedef tk::Queue<TraceClass> List;
57 
58  private:
60  explicit TraceClass(void);
61 
62  public:
64  TraceClass(
65  const TraceClass& CLI_Class
66  );
67 
69  explicit TraceClass(
70  const char* const STR_ClassName,
71  const Help& CLI_Help
72  );
73 
75  virtual ~TraceClass(void);
76 
77  public:
80  const tk::String GetName(void) const;
81 
84  const Help& GetHelp(void) const;
85 
86  public:
90 
91  private:
93  tk::String m_strName;
94 
96  Help m_cliHelp;
97  };
98 
101  const bool operator==(
102  const TraceClass& CLI_Class1,
103  const TraceClass& CLI_Class2
104  );
105 
107  #define INTERNAL_ERROR GetInternalErrorTraceClass()
111 
112 
114  class Traces : public Object
115  {
116  public:
119  static Traces& GetInstance(void);
120 
121  protected:
123  explicit Traces(void);
124 
125  public:
127  virtual ~Traces(void);
128 
129  private:
131  Traces(const Traces&);
133  Traces& operator=(const Traces&);
134 
135  public:
138  const OutputDevice& GetStream(void) const;
139 
146  const bool SetStream(
147  OutputDevice& CLI_Stream
148  );
149 
154  const bool UnsetStream(
155  OutputDevice& CLI_Stream
156  );
157 
158  public:
162  const bool Declare(
163  const TraceClass& CLI_Class
164  );
165 
168  const TraceClass::List GetAllClasses(void) const;
169 
172  const TraceClass::List GetCurrentFilter(void) const;
173 
176  const bool SetFilter(
177  const TraceClass& CLI_Class,
178  const bool B_ShowTraces
179  );
180 
185  const bool SetAllFilter(
186  const bool B_ShowTraces
187  );
188 
189  public:
192  const bool IsTraceOn(
193  const TraceClass& CLI_Class
194  ) const;
195 
199  const OutputDevice& Trace(
200  const TraceClass& CLI_Class
201  );
202 
206  const OutputDevice& SafeTrace(
207  const TraceClass& CLI_Class,
208  const Object& CLI_AvoidStream
209  );
210 
211  private:
216  const OutputDevice& BeginTrace(
217  const TraceClass& CLI_Class
218  );
219 
221  const bool TraceFilterState(
222  const TraceClass& CLI_Class,
223  const bool B_ShowTraces
224  );
225 
226  private:
228  class TraceClassFlag : public TraceClass
229  {
230  public:
231  explicit TraceClassFlag(void);
232  explicit TraceClassFlag(const TraceClass& CLI_Source, const bool B_Show);
233  TraceClassFlag(const TraceClassFlag& CLI_Source);
234  virtual ~TraceClassFlag(void);
235  public:
236  TraceClassFlag& operator=(const TraceClassFlag& CLI_Class);
237  public:
238  const bool IsVisible(void) const;
239  private:
240  bool m_bShow;
241  };
242 
244  typedef tk::Map<tk::String, TraceClassFlag> ClassMap;
245 
247  ClassMap m_mapClasses;
248 
250  bool m_bTraceAll;
251 
253  tk::Queue<OutputDevice*> m_qStreams;
254  };
255 
258  Traces& GetTraces(void);
259 
261 
262 #endif // _CLI_TRACES_H_
Generic object.
Definition: object.h:42
Main namespace of the CLI library.
Help container class.
Definition: help.h:46
const bool IsTraceOn(const TraceClass &CLI_Class) const
Trace status.
const TraceClass::List GetCurrentFilter(void) const
Current filter retrieval.
const bool SetFilter(const TraceClass &CLI_Class, const bool B_ShowTraces)
Current filter modification.
const tk::String GetName(void) const
Class name accessor.
Traces service.
Definition: traces.h:114
virtual ~Traces(void)
Destructor.
#define CLI_NS_END(__ns)
End a namespace definition.
Definition: namespace.h:45
static Traces & GetInstance(void)
Singleton.
const bool Declare(const TraceClass &CLI_Class)
Trace class declaration.
const OutputDevice & Trace(const TraceClass &CLI_Class)
Trace routine.
Namespace management.
const TraceClass & GetInternalErrorTraceClass()
Internal error common trace class singleton.
const bool SetStream(OutputDevice &CLI_Stream)
Stream positionning (if not already set).
Generic output device.
Definition: io_device.h:256
Traces(void)
Default constructor.
const OutputDevice & SafeTrace(const TraceClass &CLI_Class, const Object &CLI_AvoidStream)
Safe trace routine.
const bool operator==(const TraceClass &CLI_Class1, const TraceClass &CLI_Class2)
Classes equivalence operator.
const OutputDevice & GetStream(void) const
Stream access.
#define CLI_NS_BEGIN(__ns)
Begin a namespace definition.
Definition: namespace.h:38
virtual ~TraceClass(void)
Destructor.
tk::Queue< TraceClass > List
Trace class list typedef.
Definition: traces.h:56
CLI toolkit definition.
Help class definition.
Object class definition.
TraceClass & operator=(const TraceClass &)
Assignment operator.
const bool UnsetStream(OutputDevice &CLI_Stream)
Stream dereferencing.
const Help & GetHelp(void) const
Description accessor.
Trace class object.
Definition: traces.h:51
Traces & GetTraces(void)
Singleton.
const TraceClass::List GetAllClasses(void) const
All classes accessor.
const bool SetAllFilter(const bool B_ShowTraces)
All filter management.