| 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ |
| 2 | /* librevenge |
| 3 | * Version: MPL 2.0 / LGPLv2.1+ |
| 4 | * |
| 5 | * This Source Code Form is subject to the terms of the Mozilla Public |
| 6 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 | * |
| 9 | * Major Contributor(s): |
| 10 | * Copyright (C) 2005 William Lachance ([email protected]) |
| 11 | * Copyright (C) 2005 Net Integration Technologies, Inc. (http://www.net-itech.com) |
| 12 | * Copyright (C) 2006 Fridrich Strba ([email protected]) |
| 13 | * |
| 14 | * For minor contributions see the git repository. |
| 15 | * |
| 16 | * Alternatively, the contents of this file may be used under the terms |
| 17 | * of the GNU Lesser General Public License Version 2.1 or later |
| 18 | * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are |
| 19 | * applicable instead of those above. |
| 20 | */ |
| 21 | |
| 22 | #include <librevenge/librevenge.h> |
| 23 | #include <vector> |
| 24 | |
| 25 | namespace librevenge |
| 26 | { |
| 27 | |
| 28 | class RVNGPropertyListVectorImpl |
| 29 | { |
| 30 | public: |
| 31 | RVNGPropertyListVectorImpl(const std::vector<RVNGPropertyList> &_vector) : m_vector(_vector) {} |
| 32 | RVNGPropertyListVectorImpl() : m_vector() {} |
| 33 | void append(const RVNGPropertyList &elem) |
| 34 | { |
| 35 | m_vector.push_back(elem); |
| 36 | } |
| 37 | unsigned long count() const |
| 38 | { |
| 39 | return m_vector.size(); |
| 40 | } |
| 41 | bool empty() const |
| 42 | { |
| 43 | return m_vector.empty(); |
| 44 | } |
| 45 | void clear() |
| 46 | { |
| 47 | m_vector.clear(); |
| 48 | } |
| 49 | const RVNGPropertyList &operator[](unsigned long index) const |
| 50 | { |
| 51 | return m_vector[index]; |
| 52 | } |
| 53 | std::vector<RVNGPropertyList> m_vector; |
| 54 | }; |
| 55 | |
| 56 | class RVNGPropertyListVectorIterImpl |
| 57 | { |
| 58 | public: |
| 59 | RVNGPropertyListVectorIterImpl(std::vector<RVNGPropertyList> *vect) : |
| 60 | m_vector(vect), |
| 61 | m_iter(m_vector->begin()), |
| 62 | m_imaginaryFirst(false) {} |
| 63 | ~RVNGPropertyListVectorIterImpl() {} |
| 64 | void rewind() |
| 65 | { |
| 66 | m_iter = m_vector->begin(); |
| 67 | m_imaginaryFirst = true; |
| 68 | } |
| 69 | bool next() |
| 70 | { |
| 71 | if (!m_imaginaryFirst && m_iter != m_vector->end()) |
| 72 | ++m_iter; |
| 73 | m_imaginaryFirst = false; |
| 74 | return (m_iter != m_vector->end()); |
| 75 | } |
| 76 | bool last() |
| 77 | { |
| 78 | return (m_iter == m_vector->end()); |
| 79 | } |
| 80 | const RVNGPropertyList &operator()() const |
| 81 | { |
| 82 | return (*m_iter); |
| 83 | } |
| 84 | |
| 85 | private: |
| 86 | RVNGPropertyListVectorIterImpl(const RVNGPropertyListVectorIterImpl &); |
| 87 | RVNGPropertyListVectorIterImpl &operator=(const RVNGPropertyListVectorIterImpl &); |
| 88 | std::vector<RVNGPropertyList> *m_vector; |
| 89 | std::vector<RVNGPropertyList>::iterator m_iter; |
| 90 | bool m_imaginaryFirst; |
| 91 | }; |
| 92 | |
| 93 | RVNGPropertyListVector::RVNGPropertyListVector(const RVNGPropertyListVector &vect) : |
| 94 | m_impl(new RVNGPropertyListVectorImpl(vect.m_impl->m_vector)) |
| 95 | { |
| 96 | } |
| 97 | |
| 98 | RVNGPropertyListVector::RVNGPropertyListVector() : |
| 99 | m_impl(new RVNGPropertyListVectorImpl) |
| 100 | { |
| 101 | } |
| 102 | |
| 103 | RVNGPropertyListVector::~RVNGPropertyListVector() |
| 104 | { |
| 105 | delete m_impl; |
| 106 | } |
| 107 | |
| 108 | int RVNGPropertyListVector::getInt() const |
| 109 | { |
| 110 | return 0; |
| 111 | } |
| 112 | |
| 113 | double RVNGPropertyListVector::getDouble() const |
| 114 | { |
| 115 | return 0.0; |
| 116 | } |
| 117 | |
| 118 | RVNGUnit RVNGPropertyListVector::getUnit() const |
| 119 | { |
| 120 | return RVNG_UNIT_ERROR; |
| 121 | } |
| 122 | |
| 123 | RVNGString RVNGPropertyListVector::getStr() const |
| 124 | { |
| 125 | return RVNGString(); |
| 126 | } |
| 127 | |
| 128 | RVNGProperty *RVNGPropertyListVector::clone() const |
| 129 | { |
| 130 | return new RVNGPropertyListVector(*this); |
| 131 | } |
| 132 | |
| 133 | void RVNGPropertyListVector::append(const RVNGPropertyList &elem) |
| 134 | { |
| 135 | m_impl->append(elem); |
| 136 | } |
| 137 | |
| 138 | void RVNGPropertyListVector::append(const RVNGPropertyListVector &vec) |
| 139 | { |
| 140 | std::vector<RVNGPropertyList> &other = vec.m_impl->m_vector; |
| 141 | m_impl->m_vector.reserve(m_impl->m_vector.size() + other.size()); |
| 142 | m_impl->m_vector.insert(m_impl->m_vector.end(), other.begin(), other.end()); |
| 143 | } |
| 144 | |
| 145 | unsigned long RVNGPropertyListVector::count() const |
| 146 | { |
| 147 | return m_impl->count(); |
| 148 | } |
| 149 | |
| 150 | bool RVNGPropertyListVector::empty() const |
| 151 | { |
| 152 | return m_impl->empty(); |
| 153 | } |
| 154 | |
| 155 | void RVNGPropertyListVector::clear() |
| 156 | { |
| 157 | m_impl->clear(); |
| 158 | } |
| 159 | |
| 160 | const RVNGPropertyList &RVNGPropertyListVector::operator[](unsigned long index) const |
| 161 | { |
| 162 | return m_impl->operator[](index); |
| 163 | } |
| 164 | |
| 165 | RVNGPropertyListVector &RVNGPropertyListVector::operator=(const RVNGPropertyListVector &vect) |
| 166 | { |
| 167 | m_impl->m_vector = vect.m_impl->m_vector; |
| 168 | return *this; |
| 169 | } |
| 170 | |
| 171 | RVNGPropertyListVector::Iter::Iter(const RVNGPropertyListVector &vect) : |
| 172 | m_iterImpl(new RVNGPropertyListVectorIterImpl(&(vect.m_impl->m_vector))) |
| 173 | { |
| 174 | } |
| 175 | |
| 176 | RVNGString RVNGPropertyListVector::getPropString() const |
| 177 | { |
| 178 | RVNGString propString; |
| 179 | |
| 180 | propString.append("("); |
| 181 | RVNGPropertyListVector::Iter i(*this); |
| 182 | |
| 183 | if (!i.last()) |
| 184 | { |
| 185 | propString.append("("); |
| 186 | propString.append(i().getPropString()); |
| 187 | propString.append(")"); |
| 188 | |
| 189 | for (; i.next();) |
| 190 | { |
| 191 | propString.append(", ("); |
| 192 | propString.append(i().getPropString()); |
| 193 | propString.append(")"); |
| 194 | } |
| 195 | |
| 196 | } |
| 197 | propString.append(")"); |
| 198 | return propString; |
| 199 | } |
| 200 | |
| 201 | RVNGPropertyListVector::Iter::~Iter() |
| 202 | { |
| 203 | delete m_iterImpl; |
| 204 | } |
| 205 | |
| 206 | void RVNGPropertyListVector::Iter::rewind() |
| 207 | { |
| 208 | m_iterImpl->rewind(); |
| 209 | } |
| 210 | |
| 211 | bool RVNGPropertyListVector::Iter::next() |
| 212 | { |
| 213 | return m_iterImpl->next(); |
| 214 | } |
| 215 | |
| 216 | bool RVNGPropertyListVector::Iter::last() |
| 217 | { |
| 218 | return m_iterImpl->last(); |
| 219 | } |
| 220 | |
| 221 | const RVNGPropertyList &RVNGPropertyListVector::Iter::operator()() const |
| 222 | { |
| 223 | return (*m_iterImpl)(); |
| 224 | } |
| 225 | |
| 226 | } |
| 227 | |
| 228 | /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */ |