d989f445c6eec40be02caf40b0b09745852cb17b
[platform/core/security/key-manager.git] / src / manager / common / stringify.h
1 /*
2  *  Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
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  * @file       stringify.h
18  * @author     Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
19  * @author     Bartlomiej Grzelewski (b.grzelewski@samsung.com)
20  * @version    1.0
21  */
22 #pragma once
23
24 #include <sstream>
25 #include <string>
26
27 namespace CKM {
28
29 template <bool Mode>
30 class StringifyBasic;
31
32 template <>
33 class StringifyBasic<false> {
34 public:
35     std::string operator()() {
36         return std::string();
37     }
38
39     template <typename... Args>
40     std::string operator()(const Args&...){
41         return std::string();
42     }
43 };
44
45 template <>
46 class StringifyBasic<true> {
47     void concatenate(std::ostringstream&) {}
48
49     template <typename t, typename... Args>
50     void concatenate(std::ostringstream& stream, const t& arg1, const Args&... args) {
51         stream << arg1;
52         concatenate(stream, args...);
53     }
54 public:
55     std::string operator()() {
56         return std::string();
57     }
58
59     template <typename T, typename... Args>
60     std::string operator()(const T& arg1, const Args&... args){
61         std::ostringstream stream;
62         concatenate(stream, arg1, args...);
63         return stream.str();
64     }
65 };
66
67 #ifdef DEBUG
68 #define DEBUG_STATUS true
69 #else
70 #define DEBUG_STATUS false
71 #endif
72
73 typedef StringifyBasic<true>  Stringify;
74 typedef StringifyBasic<false> StringifyAvoid;
75 typedef StringifyBasic<true>  StringifyError;
76 typedef StringifyBasic<DEBUG_STATUS> StringifyDebug;
77
78 #undef DEBUG_STATUS
79
80 } // namespace CKM
81