Update implementation of Stringify.
[platform/core/security/key-manager.git] / src / manager / common / stringify.h
1 /*
2  *  Copyright (c) 2000 - 2015 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     StringifyBasic() = delete;
35 public:
36     static std::string Merge() {
37         return std::string();
38     }
39
40     template <typename... Args>
41     static std::string Merge(const Args&...){
42         return std::string();
43     }
44 };
45
46 template <>
47 class StringifyBasic<true> {
48     StringifyBasic() = delete;
49
50     static void Concatenate(std::ostringstream&) {}
51
52     template <typename t, typename... Args>
53     static void Concatenate(std::ostringstream& stream, const t& arg1, const Args&... args) {
54         stream << arg1;
55         Concatenate(stream, args...);
56     }
57 public:
58     static std::string Merge() {
59         return std::string();
60     }
61
62     template <typename T, typename... Args>
63     static std::string Merge(const T& arg1, const Args&... args) {
64         std::ostringstream stream;
65         Concatenate(stream, arg1, args...);
66         return stream.str();
67     }
68 };
69
70 #ifdef DEBUG
71 #define DEBUG_STATUS true
72 #else
73 #define DEBUG_STATUS false
74 #endif
75
76 typedef StringifyBasic<true>  Stringify;
77 typedef StringifyBasic<false> StringifyAvoid;
78 typedef StringifyBasic<true>  StringifyError;
79 typedef StringifyBasic<DEBUG_STATUS> StringifyDebug;
80
81 #undef DEBUG_STATUS
82
83 } // namespace CKM
84