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 {
26 class StringBuilderImpl
29 StringBuilderImpl() : m_counter(1)
33 void append(const std::string& str)
37 ThrowMsg(PlatformException, "Couldn't append string.");
41 void append(const StringBuilderImpl* impl)
43 if (!(m_ss << impl->m_ss)) {
45 ThrowMsg(PlatformException,
46 "Couldn't append string builder.");
57 if (0 == --m_counter) {
62 StringBuilderImpl* clone()
70 StringBuilderImpl* result = new StringBuilderImpl();
75 std::string toString() const
81 std::stringstream m_ss;
82 unsigned int m_counter;
85 StringBuilder::StringBuilder() : m_impl(new StringBuilderImpl())
89 StringBuilder::~StringBuilder()
94 StringBuilder::StringBuilder(const StringBuilder& other)
96 other.m_impl->addRef();
97 m_impl = other.m_impl;
100 StringBuilder & StringBuilder::operator=(const StringBuilder& other)
102 if (this == &other) { return *this; }
104 other.m_impl->addRef();
107 m_impl = other.m_impl;
112 StringBuilder& StringBuilder::append(const std::string& str)
114 m_impl = m_impl->clone();
119 StringBuilder& StringBuilder::append(const StringBuilder& builder)
121 m_impl = m_impl->clone();
122 m_impl->append(builder.m_impl);
126 std::string StringBuilder::toString() const
128 return m_impl->toString();
132 } // WrtDeviceApisCommon