2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @author Zbigniew Kostrzewa (z.kostrzewa@samsung.com)
20 #include "Exception.h"
21 #include "StringBuilder.h"
23 namespace WrtDeviceApis {
25 class StringBuilderImpl
28 StringBuilderImpl() : m_counter(1)
31 void append(const std::string& str)
35 ThrowMsg(PlatformException, "Couldn't append string.");
39 void append(const StringBuilderImpl* impl)
41 if (!(m_ss << impl->m_ss)) {
43 ThrowMsg(PlatformException,
44 "Couldn't append string builder.");
55 if (0 == --m_counter) {
60 StringBuilderImpl* clone()
68 StringBuilderImpl* result = new StringBuilderImpl();
73 std::string toString() const
79 std::stringstream m_ss;
80 unsigned int m_counter;
83 StringBuilder::StringBuilder() : m_impl(new StringBuilderImpl())
86 StringBuilder::~StringBuilder()
91 StringBuilder::StringBuilder(const StringBuilder& other)
93 other.m_impl->addRef();
94 m_impl = other.m_impl;
97 StringBuilder & StringBuilder::operator=(const StringBuilder& other)
103 other.m_impl->addRef();
106 m_impl = other.m_impl;
111 StringBuilder& StringBuilder::append(const std::string& str)
113 m_impl = m_impl->clone();
118 StringBuilder& StringBuilder::append(const StringBuilder& builder)
120 m_impl = m_impl->clone();
121 m_impl->append(builder.m_impl);
125 std::string StringBuilder::toString() const
127 return m_impl->toString();
130 } // WrtDeviceApisCommon