Update User Agent String
[framework/web/wrt-commons.git] / modules / widget_dao / dao / path_builder.cpp
1 /*
2  * Copyright (c) 2011 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    PathBuilder.cpp
18  * @author  Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
19  * @version 1.0
20  * @brief   Implementation file for PathBuilde class.
21  */
22 #include <dpl/wrt-dao-ro/path_builder.h>
23 #include <sstream>
24
25 namespace WrtDB {
26 namespace {
27 const char PATH_SEPARATOR = '/';
28 }
29
30 class PathBuilderImpl : DPL::Noncopyable
31 {
32   public:
33     PathBuilderImpl()
34     {
35     }
36
37     explicit PathBuilderImpl(const std::string& path) :
38         m_stream(path, std::ios_base::app)
39     {
40     }
41
42     void Append(const std::string& path)
43     {
44         // TODO Check additionally if last char is not separator.
45         if (m_stream.tellp() > 0) {
46             m_stream << PATH_SEPARATOR;
47         }
48         m_stream << path;
49     }
50
51     void Concat(const std::string& arg)
52     {
53         m_stream << arg;
54     }
55
56     void Concat(int arg)
57     {
58         m_stream << arg;
59     }
60
61     void Reset()
62     {
63         m_stream.clear();
64         m_stream.str("");
65     }
66
67     bool Empty()
68     {
69         return (m_stream.tellp() == 0);
70     }
71
72     std::string GetFullPath() const
73     {
74         return m_stream.str();
75     }
76
77   private:
78     std::ostringstream m_stream;
79 };
80
81 PathBuilder::PathBuilder() : m_impl(new PathBuilderImpl())
82 {
83 }
84
85 PathBuilder::PathBuilder(const std::string& path) :
86     m_impl(new PathBuilderImpl(path))
87 {
88 }
89
90 PathBuilder::~PathBuilder()
91 {
92     delete m_impl;
93 }
94
95 PathBuilder& PathBuilder::Append(const std::string& path)
96 {
97     m_impl->Append(path);
98     return *this;
99 }
100
101 PathBuilder& PathBuilder::Concat(const std::string& arg)
102 {
103     m_impl->Concat(arg);
104     return *this;
105 }
106
107 PathBuilder& PathBuilder::Concat(int arg)
108 {
109     m_impl->Concat(arg);
110     return *this;
111 }
112
113 PathBuilder& PathBuilder::Reset()
114 {
115     m_impl->Reset();
116     return *this;
117 }
118
119 bool PathBuilder::Empty() const
120 {
121     return m_impl->Empty();
122 }
123
124 std::string PathBuilder::GetFullPath() const
125 {
126     return m_impl->GetFullPath();
127 }
128
129 } // namespace WrtDB