strusTrace  0.17
traceElement.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Patrick P. Frey
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
10 #ifndef _STRUS_TRACE_ELEMENT_HPP_INCLUDED
11 #define _STRUS_TRACE_ELEMENT_HPP_INCLUDED
12 #include <string>
13 #include <cstring>
14 #include "strus/base/stdint.h"
15 
16 namespace strus
17 {
18 
19 typedef unsigned int TraceObjectId;
20 typedef unsigned int TraceTimeCounter;
21 typedef std::size_t TraceLogRecordHandle;
22 
25 {
26  typedef int64_t IntType;
27  typedef uint64_t UIntType;
28 
29  enum Type
30  {
41  };
42 
43  union Value
44  {
47  double Double;
48  bool Bool;
49  std::size_t Index;
50  struct { TraceObjectId Id; const char* Class; } Obj;
51  struct { const char* Ptr; std::size_t Size; } String;
52  };
53 
55  Type type() const
56  {
57  return m_type;
58  }
60  Value value() const
61  {
62  return m_value;
63  }
64 
66  TraceElement() :m_type(TypeVoid) {m_value.UInt = 0;}
68  TraceElement( IntType value_) :m_type(TypeInt) {m_value.Int = value_;}
70  TraceElement( UIntType value_) :m_type(TypeUInt) {m_value.UInt = value_;}
72  TraceElement( double value_) :m_type(TypeDouble) {m_value.Double = value_;}
74  TraceElement( float value_) :m_type(TypeDouble) {m_value.Double = value_;}
76  TraceElement( bool value_) :m_type(TypeBool) {m_value.Bool = value_;}
78  TraceElement( Type type_, std::size_t index_) :m_type(type_) {m_value.Index = index_;}
79  TraceElement( Type type_, TraceObjectId oid_, const char* cid_)
80  :m_type(type_) {m_value.Obj.Class = cid_; m_value.Obj.Id = oid_;}
82  TraceElement( Type type_, const char* ptr_, std::size_t size_)
83  :m_type(type_) {m_value.String.Ptr = ptr_; m_value.String.Size = size_;}
84  TraceElement( Type type_, const char* ptr_)
85  :m_type(type_) {m_value.String.Ptr = ptr_; m_value.String.Size = ptr_?std::strlen(ptr_):0;}
87  :m_type(type_) {m_value.UInt = 0;}
88 
91  {
92  std::memcpy( this, &o, sizeof(*this));
93  }
94 
95 private:
96  Type m_type;
97  Value m_value;
98 };
99 
100 } //namespace
101 #endif
102 
Definition: traceElement.hpp:35
double Double
Definition: traceElement.hpp:47
std::size_t TraceLogRecordHandle
Handle of a trace log entry.
Definition: traceElement.hpp:21
Definition: traceElement.hpp:36
Type
Definition: traceElement.hpp:29
Definition: traceElement.hpp:39
TraceElement(const TraceElement &o)
Copy constructor.
Definition: traceElement.hpp:90
TraceElement(IntType value_)
Constructor.
Definition: traceElement.hpp:68
const char * Ptr
Definition: traceElement.hpp:51
Definition: traceElement.hpp:43
bool Bool
Definition: traceElement.hpp:48
struct strus::TraceElement::Value::@0 Obj
unsigned int TraceObjectId
Unique object identifier.
Definition: traceElement.hpp:19
TraceElement(bool value_)
Constructor.
Definition: traceElement.hpp:76
struct strus::TraceElement::Value::@1 String
TraceElement(UIntType value_)
Constructor.
Definition: traceElement.hpp:70
std::size_t Size
Definition: traceElement.hpp:51
std::size_t Index
Definition: traceElement.hpp:49
Definition: traceElement.hpp:32
unsigned int TraceTimeCounter
Unique timestamp of logged events.
Definition: traceElement.hpp:20
Definition: traceElement.hpp:31
TraceElement(Type type_)
Definition: traceElement.hpp:86
UIntType UInt
Definition: traceElement.hpp:45
TraceElement(Type type_, const char *ptr_)
Definition: traceElement.hpp:84
TraceElement(Type type_, const char *ptr_, std::size_t size_)
Constructor.
Definition: traceElement.hpp:82
Value value() const
Get the element value.
Definition: traceElement.hpp:60
int64_t IntType
Definition: traceElement.hpp:26
uint64_t UIntType
Definition: traceElement.hpp:27
TraceElement()
Default constructor.
Definition: traceElement.hpp:66
Definition: traceElement.hpp:38
Definition: traceElement.hpp:37
const char * Class
Definition: traceElement.hpp:50
TraceElement(Type type_, std::size_t index_)
Constructor.
Definition: traceElement.hpp:78
TraceElement(float value_)
Constructor.
Definition: traceElement.hpp:74
Element type used to describe traced structures. Any atomic value or structure is described as sequen...
Definition: traceElement.hpp:24
Type type() const
Get the element type.
Definition: traceElement.hpp:55
Definition: traceElement.hpp:40
Definition: traceElement.hpp:33
TraceObjectId Id
Definition: traceElement.hpp:50
Definition: traceElement.hpp:34
TraceElement(Type type_, TraceObjectId oid_, const char *cid_)
Definition: traceElement.hpp:79
TraceElement(double value_)
Constructor.
Definition: traceElement.hpp:72
IntType Int
Definition: traceElement.hpp:46