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