blob: b57446894bf5e32e84b344393f7b970a07f58952 [file] [log] [blame]
anjana_sreekumar@infosys.com991c2062020-01-08 11:42:57 +05301/*
2 * Copyright (c) 2019, Infosys Ltd.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <debug.h>
18
19using namespace cmn::utils;
20
21Debug::Debug()
22{
23 indent = 0;
24 newLine = true;
25}
26
27Debug::~Debug()
28{
29 //TODO
30}
31
32void Debug::printDebugStream()
33{
34 fprintf(stderr, "%s" , stream.str().c_str());
35}
36
37void Debug::clearStream()
38{
39 stream.str("");
40}
41
42void Debug::printDebugStreamToFile()
43{
44 // TODO
45}
46
47void Debug::add(char* data)
48{
49 if (newLine)
50 startNewLine();
51 stream << data;
52}
53
54void Debug::add(uint8_t data)
55{
56 if (newLine)
57 startNewLine();
58 stream << (uint16_t)data;
59}
60
61void Debug::add(uint16_t data)
62{
63 if (newLine)
64 startNewLine();
65 stream << data;
66}
67
68void Debug::add(uint32_t data)
69{
70 if (newLine)
71 startNewLine();
72 stream << data;
73}
74
75void Debug::add(uint64_t data)
76{
77 if (newLine)
78 startNewLine();
79 stream << data;
80}
81
82
83void Debug::endOfLine()
84{
85 stream <<"\n";
86 newLine = true;
87}
88
89void Debug::startNewLine()
90{
91 uint8_t i;
92 for (i = 0; i<= indent; i++)
93 {
94 stream <<" ";
95 }
96 newLine = false;
97}
98
99void Debug::incrIndent()
100{
101 indent++;
102}
103
104void Debug::decrIndent()
105{
106 if (indent > 0)
107 indent --;
108}
109
110void Debug::setHexOutput()
111{
112 stream.setf(ios::hex, ios::basefield);
113}
114
115void Debug::unsetHexOutput()
116{
117 stream.unsetf(ios::hex);
118}
119