Tizen 2.0 Release
[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
38     explicit PathBuilderImpl(const std::string& path) :
39         m_stream(path, std::ios_base::app)
40     {
41     }
42
43     void Append(const std::string& path)
44     {
45         // TODO Check additionally if last char is not separator.
46         if (m_stream.tellp() > 0) {
47             m_stream << PATH_SEPARATOR;
48         }
49         m_stream << path;
50     }
51
52     void Concat(const std::string& arg)
53     {
54         m_stream << arg;
55     }
56
57     void Concat(int arg)
58     {
59         m_stream << arg;
60     }
61
62     void Reset()
63     {
64         m_stream.clear();
65         m_stream.str("");
66     }
67
68     bool Empty()
69     {
70         return (m_stream.tellp() == 0);
71     }
72
73     std::string GetFullPath() const
74     {
75         return m_stream.str();
76     }
77
78   private:
79     std::ostringstream m_stream;
80 };
81
82 PathBuilder::PathBuilder() : m_impl(new PathBuilderImpl())
83 {
84 }
85
86 PathBuilder::PathBuilder(const std::string& path) :
87     m_impl(new PathBuilderImpl(path))
88 {
89 }
90
91 PathBuilder::~PathBuilder()
92 {
93     delete m_impl;
94 }
95
96 PathBuilder& PathBuilder::Append(const std::string& path)
97 {
98     m_impl->Append(path);
99     return *this;
100 }
101
102 PathBuilder& PathBuilder::Concat(const std::string& arg)
103 {
104     m_impl->Concat(arg);
105     return *this;
106 }
107
108 PathBuilder& PathBuilder::Concat(int arg)
109 {
110     m_impl->Concat(arg);
111     return *this;
112 }
113
114 PathBuilder& PathBuilder::Reset()
115 {
116     m_impl->Reset();
117     return *this;
118 }
119
120 bool PathBuilder::Empty() const
121 {
122     return m_impl->Empty();
123 }
124
125 std::string PathBuilder::GetFullPath() const
126 {
127     return m_impl->GetFullPath();
128 }
129
130 } // namespace WrtDB