Open Lighting Architecture: include/ola/messaging/MessagePrinter.h Source File

| Open Lighting Architecture 0.10.9

Loading...
Searching...
No Matches
MessagePrinter.h
1/*
2 * This library is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2.1 of the License, or (at your option) any later version.
6 *
7 * This library is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
11 *
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with this library; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15 *
16 * MessagePrinter.h
17 * Print the contents of a message.
18 * Copyright (C) 2011 Simon Newton
19 */
20
21#ifndef INCLUDE_OLA_MESSAGING_MESSAGEPRINTER_H_
22#define INCLUDE_OLA_MESSAGING_MESSAGEPRINTER_H_
23
24#include <ola/messaging/MessageVisitor.h>
25#include <string>
26#include <sstream>
27
28namespace ola {
29namespace messaging {
30
31
35 class MessagePrinter: public MessageVisitor {
36 public:
37 virtual ~MessagePrinter() {}
38
39 std::string AsString(const class Message *message);
40
41 virtual void Visit(const BoolMessageField*) {}
42 virtual void Visit(const IPV4MessageField*) {}
43 virtual void Visit(const MACMessageField*) {}
44 virtual void Visit(const UIDMessageField*) {}
45 virtual void Visit(const StringMessageField*) {}
46 virtual void Visit(const BasicMessageField<uint8_t>*) {}
47 virtual void Visit(const BasicMessageField<uint16_t>*) {}
48 virtual void Visit(const BasicMessageField<uint32_t>*) {}
49 virtual void Visit(const BasicMessageField<int8_t>*) {}
50 virtual void Visit(const BasicMessageField<int16_t>*) {}
51 virtual void Visit(const BasicMessageField<int32_t>*) {}
52 virtual void Visit(const GroupMessageField*) {}
53 virtual void PostVisit(const GroupMessageField*) {}
54
55 protected:
56 std::ostringstream& Stream() { return m_str; }
57 virtual void PostStringHook() {}
58 virtual std::string TransformLabel(const std::string &label) {
59 return label;
60 }
61
62 private:
63 std::ostringstream m_str;
64};
65
66
70 class GenericMessagePrinter: public MessagePrinter {
71 public:
72 GenericMessagePrinter(unsigned int indent_size = DEFAULT_INDENT,
73 unsigned int initial_indent = 0)
74 : m_indent(initial_indent),
75 m_indent_size(indent_size) {
76 }
77 ~GenericMessagePrinter() {}
78
79 virtual void Visit(const BoolMessageField*);
80 virtual void Visit(const IPV4MessageField*);
81 virtual void Visit(const MACMessageField*);
82 virtual void Visit(const UIDMessageField*);
83 virtual void Visit(const StringMessageField*);
84 virtual void Visit(const BasicMessageField<uint8_t>*);
85 virtual void Visit(const BasicMessageField<uint16_t>*);
86 virtual void Visit(const BasicMessageField<uint32_t>*);
87 virtual void Visit(const BasicMessageField<int8_t>*);
88 virtual void Visit(const BasicMessageField<int16_t>*);
89 virtual void Visit(const BasicMessageField<int32_t>*);
90 virtual void Visit(const GroupMessageField*);
91 virtual void PostVisit(const GroupMessageField*);
92
93 static const unsigned int DEFAULT_INDENT = 2;
94
95 private:
96 unsigned int m_indent, m_indent_size;
97
98 void AppendUInt(const std::string &name,
99 unsigned int value,
100 const std::string &label,
101 int8_t multiplier);
102 void AppendInt(const std::string &name,
103 int value,
104 const std::string &label,
105 int8_t multiplier);
106 void AppendMultiplier(int8_t multiplier);
107};
108} // namespace messaging
109} // namespace ola
110#endif // INCLUDE_OLA_MESSAGING_MESSAGEPRINTER_H_
ola::messaging::BasicMessageField
Definition Message.h:208
ola::messaging::BoolMessageField
Definition Message.h:73
ola::messaging::GroupMessageField
Definition Message.h:242
ola::messaging::IPV4MessageField
Definition Message.h:99
ola::messaging::MACMessageField
Definition Message.h:131
ola::messaging::Message
Definition Message.h:39
ola::messaging::MessagePrinter
Definition MessagePrinter.h:35
ola::messaging::MessagePrinter::AsString
std::string AsString(const class Message *message)
Definition MessagePrinter.cpp:39
ola::messaging::MessageVisitor
Definition MessageVisitor.h:43
ola::messaging::StringMessageField
Definition Message.h:183
ola::messaging::UIDMessageField
Definition Message.h:157
ola::messaging
A framework for serializing simple message structures.
Definition Descriptor.cpp:25
ola
The namespace containing all OLA symbols.
Definition Credentials.cpp:44