Initial Version of LayerManagementService added.
[profile/ivi/layer-management.git] / LayerManagerUtils / include / LogMessageBuffer.h
1 /***************************************************************************
2 *
3 * Copyright 2010 BMW Car IT GmbH
4 *
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 *               http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 ****************************************************************************/
19 #ifndef _LOGMESSAGEBUFFER_H_
20 #define _LOGMESSAGEBUFFER_H_
21 #include <sstream>
22
23 class LogMessageBuffer {
24         typedef std::ios_base& (*ios_base_manip)(std::ios_base&);
25 public:
26         /**
27          *  Creates a new instance.
28          */
29        LogMessageBuffer();
30         /**
31          *  Destructor.
32          */
33         ~LogMessageBuffer();
34
35
36         LogMessageBuffer& operator<<(const std::basic_string<char>& msg);
37
38         LogMessageBuffer& operator<<(const char* msg);
39
40         LogMessageBuffer& operator<<(char* msg);
41
42         LogMessageBuffer& operator<<(const char msg);
43
44         std::ostream& operator<<(ios_base_manip manip);
45
46         std::ostream& operator<<(bool val);
47
48         std::ostream& operator<<(short val);
49
50         std::ostream& operator<<(int val);
51
52         std::ostream& operator<<(unsigned int val);
53
54         std::ostream& operator<<(long val);
55
56         std::ostream& operator<<(unsigned long val);
57
58         std::ostream& operator<<(float val);
59
60         std::ostream& operator<<(double val);
61
62         std::ostream& operator<<(long double val);
63
64         std::ostream& operator<<(void* val);
65
66       /**
67        *  Cast to ostream.
68        */
69       operator std::basic_ostream<char>&();
70
71       const std::basic_string<char>& str(std::basic_ostream<char>& os);
72
73       const std::basic_string<char>& str();
74
75       bool hasStream() const;
76
77    private:
78         /**
79          * No default copy constructor.
80          */
81       LogMessageBuffer(const LogMessageBuffer&);
82         /**
83          *  No assignment operator.
84          */
85       LogMessageBuffer& operator=(const LogMessageBuffer&);
86
87                 /**
88          * Encapsulated std::string.
89          */
90         std::basic_string<char> buf;
91
92         /**
93          *  Encapsulated stream, created on demand.
94          */
95         std::basic_ostringstream<char>* stream;
96    };
97 template<class V>
98 std::basic_ostream<char>& operator<<(LogMessageBuffer& os, const V& val) {
99    return ((std::basic_ostream<char>&) os) << val;
100 }
101
102 #endif /* _LOGMESSAGEBUFFER_H_ */