/usr/include/crystalspace-2.0/csutil/scfarray.h is in libcrystalspace-dev 2.0+dfsg-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | /*
Copyright (C) 2006 by Frank Richter
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __CS_CSUTIL_SCFARRAY_H__
#define __CS_CSUTIL_SCFARRAY_H__
/**\file
* Implementation for iArrayReadOnly<>-, iArrayChangeElements<>- and
* iArrayChangeAll<>-derived interfaces.
*/
#include "iutil/array.h"
#include "csutil/array.h"
#include "csutil/scf_implementation.h"
/**\addtogroup util_containers
* @{ */
/**
* Implementation for iArrayReadOnly<>-, iArrayChangeElements<>- and
* iArrayChangeAll<>-derived interfaces, backed by a per-instance array.
* The \p IF template parameter denotes the array interface to be implemented,
* the optional \p Backend remplate parameter the array type internally used
* for storage.
*
* Usage example:
* \code
* struct iSomeArray : public iArrayChangeElements<...> { ... };
*
* void MyClass::MyMethod()
* {
* csRef<iSomeArray> array;
* array.AttachNew (new scfArray<iSomeArray>);
* ...
* }
* \endcode
*/
template<typename IF,
typename Backend = csArray<typename IF::ContainedType> >
class scfArray :
public scfImplementation1<scfArray<IF, Backend>, IF>
{
typedef scfImplementation1<scfArray<IF, Backend>, IF> scfImplementationType;
typedef typename IF::ContainedType ContainedType;
public:
/// The array storage
Backend storage;
//@{
/// Construct with empty storage.
scfArray () : scfImplementationType (this) {}
scfArray (iBase* scfParent) : scfImplementationType (this, scfParent) {}
//@}
//@{
/// Construct and copy to storage contents from given array.
scfArray (const Backend& storage) : scfImplementationType (this),
storage (storage) {}
scfArray (const Backend& storage, iBase* scfParent) :
scfImplementationType (this, scfParent), storage (storage) {}
//@}
/**\name iArrayReadOnly<> implementation
* @{ */
virtual size_t GetSize () const
{ return storage.GetSize(); }
virtual ContainedType const& Get (size_t n) const
{ return storage.Get (n); }
virtual ContainedType const& Top () const
{ return storage.Top(); }
virtual size_t Find (ContainedType const& which) const
{ return storage.Find (which); }
virtual size_t GetIndex (const ContainedType* which) const
{ return storage.GetIndex (which); }
virtual bool IsEmpty() const
{ return storage.IsEmpty(); }
virtual void GetAll (ContainedType* dest) const
{
for (size_t i = 0; i < storage.GetSize(); i++)
dest[i] = storage[i];
}
/** @} */
/**\name iArrayChangeElements<> implementation
* @{ */
virtual ContainedType& Get (size_t n)
{ return storage.Get (n); }
virtual ContainedType& Top ()
{ return storage.Top(); }
/** @} */
/**\name iArrayChangeAll<> implementation
* @{ */
virtual void SetSize (size_t n, ContainedType const& what)
{ storage.SetSize (n, what); }
virtual void SetSize (size_t n)
{ storage.SetSize (n); }
virtual ContainedType& GetExtend (size_t n)
{ return storage.GetExtend (n); }
virtual void Put (size_t n, ContainedType const& what)
{ storage.Put (n, what); }
virtual size_t Push (ContainedType const& what)
{ return storage.Push (what); }
virtual size_t PushSmart (ContainedType const& what)
{ return storage.PushSmart (what); }
virtual ContainedType Pop ()
{ return storage.Pop (); }
virtual bool Insert (size_t n, ContainedType const& item)
{ return storage.Insert (n, item); }
virtual void DeleteAll ()
{ storage.DeleteAll(); }
virtual void Truncate (size_t n)
{ storage.Truncate(n); }
virtual void Empty ()
{ storage.Empty(); }
virtual bool DeleteIndex (size_t n)
{ return storage.DeleteIndex (n); }
virtual bool DeleteIndexFast (size_t n)
{ return storage.DeleteIndexFast (n); }
virtual bool Delete (ContainedType const& item)
{ return storage.Delete (item); }
/** @} */
};
/**
* Implementation for iArrayReadOnly<>-, iArrayChangeElements<>- and
* iArrayChangeAll<>-derived interfaces, backed by a reference to another
* array.
* The \p IF template parameter denotes the array interface to be implemented,
* the \p Backend template parameter the array type used for storage.
* \warning It must be ensured that the referenced array used for storage is
* alive as long as any instance of scfArrayWrap exists!
*/
template<typename IF, typename Backend>
class scfArrayWrap :
public scfImplementation1<scfArrayWrap<IF, Backend>, IF>
{
typedef scfImplementation1<scfArrayWrap<IF, Backend>, IF>
scfImplementationType;
typedef typename IF::ContainedType ContainedType;
public:
/// Reference to the array storage.
Backend& storage;
//@{
/// Initialize with a reference to the given storage.
scfArrayWrap (Backend& storage) : scfImplementationType (this),
storage (storage) {}
scfArrayWrap (Backend& storage, iBase* scfParent) :
scfImplementationType (this, scfParent), storage (storage) {}
//@}
/**\name iArrayReadOnly<> implementation
* @{ */
virtual size_t GetSize () const
{ return storage.GetSize(); }
virtual ContainedType const& Get (size_t n) const
{ return storage.Get (n); }
virtual ContainedType const& Top () const
{ return storage.Top(); }
virtual size_t Find (ContainedType const& which) const
{ return storage.Find (which); }
virtual size_t GetIndex (const ContainedType* which) const
{ return storage.GetIndex (which); }
virtual bool IsEmpty() const
{ return storage.IsEmpty(); }
virtual void GetAll (ContainedType* dest) const
{
for (size_t i = 0; i < storage.GetSize(); i++)
dest[i] = storage[i];
}
/** @} */
/**\name iArrayChangeElements<> implementation
* @{ */
virtual ContainedType& Get (size_t n)
{ return storage.Get (n); }
virtual ContainedType& Top ()
{ return storage.Top(); }
/** @} */
/**\name iArrayChangeAll<> implementation
* @{ */
virtual void SetSize (size_t n, ContainedType const& what)
{ storage.SetSize (n, what); }
virtual void SetSize (size_t n)
{ storage.SetSize (n); }
virtual ContainedType& GetExtend (size_t n)
{ return storage.GetExtend (n); }
virtual void Put (size_t n, ContainedType const& what)
{ storage.Put (n, what); }
virtual size_t Push (ContainedType const& what)
{ return storage.Push (what); }
virtual size_t PushSmart (ContainedType const& what)
{ return storage.PushSmart (what); }
virtual ContainedType Pop ()
{ return storage.Pop (); }
virtual bool Insert (size_t n, ContainedType const& item)
{ return storage.Insert (n, item); }
virtual void DeleteAll ()
{ storage.DeleteAll(); }
virtual void Truncate (size_t n)
{ storage.Truncate(n); }
virtual void Empty ()
{ storage.Empty(); }
virtual bool DeleteIndex (size_t n)
{ return storage.DeleteIndex (n); }
virtual bool DeleteIndexFast (size_t n)
{ return storage.DeleteIndexFast (n); }
virtual bool Delete (ContainedType const& item)
{ return storage.Delete (item); }
/** @} */
};
/**
* Implementation for iArrayReadOnly<>-derived interfaces, backed by a
* reference to another array.
* The \p IF template parameter denotes the array interface to be implemented,
* the \p Backend template parameter the array type used for storage.
* \warning It must be ensured that the referenced array used for storage is
* alive as long as any instance of scfArrayWrap exists!
*/
template<typename IF, typename Backend>
class scfArrayWrapConst :
public scfImplementation1<scfArrayWrapConst<IF, Backend>, IF>
{
typedef scfImplementation1<scfArrayWrapConst<IF, Backend>, IF>
scfImplementationType;
typedef typename IF::ContainedType ContainedType;
public:
/// Reference to the array storage.
const Backend& storage;
//@{
/// Initialize with a reference to the given storage.
scfArrayWrapConst (const Backend& storage) : scfImplementationType (this),
storage (storage) {}
scfArrayWrapConst (const Backend& storage, iBase* scfParent) :
scfImplementationType (this, scfParent), storage (storage) {}
//@}
/**\name iArrayReadOnly<> implementation
* @{ */
virtual size_t GetSize () const
{ return storage.GetSize(); }
virtual ContainedType const& Get (size_t n) const
{ return storage.Get (n); }
virtual ContainedType const& Top () const
{ return storage.Top(); }
virtual size_t Find (ContainedType const& which) const
{ return storage.Find (which); }
virtual size_t GetIndex (const ContainedType* which) const
{ return storage.GetIndex (which); }
virtual bool IsEmpty() const
{ return storage.IsEmpty(); }
virtual void GetAll (ContainedType* dest) const
{
for (size_t i = 0; i < storage.GetSize(); i++)
dest[i] = storage[i];
}
/** @} */
};
/** @} */
#endif // __CS_CSUTIL_SCFARRAY_H__
|