contain.h
Go to the documentation of this file.
/*
* contain.h
*
* Umbrella include for Container Classes.
*
* Portable Windows Library
*
* Copyright (c) 1993-1998 Equivalence Pty. Ltd.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Portable Windows Library.
*
* The Initial Developer of the Original Code is Equivalence Pty. Ltd.
*
* Portions are Copyright (C) 1993 Free Software Foundation, Inc.
* All Rights Reserved.
*
* Contributor(s): ______________________________________.
*
* $Revision: 25387 $
* $Author: rjongbloed $
* $Date: 2011-03-22 22:51:09 -0500 (Tue, 22 Mar 2011) $
*/
#ifndef PTLIB_CONTAIN_H
#define PTLIB_CONTAIN_H
#ifdef P_USE_PRAGMA
#pragma interface
#endif
#include <ptlib/critsec.h>
#include <ptlib/object.h>
// Abstract container class
// The type below cannot be nested into PContainer as DevStudio 2005 AUTOEXP.DAT doesn't like it
class PContainerReference
{
public:
__inline PContainerReference(PINDEX initialSize, bool isConst = false)
: size(initialSize)
, count(1)
, deleteObjects(true)
, constObject(isConst)
{
}
__inline PContainerReference(const PContainerReference & ref)
: size(ref.size)
, count(1)
, deleteObjects(ref.deleteObjects)
, constObject(false)
{
}
PINDEX size; // Size of what the container contains
PAtomicInteger count; // reference count to the container content - guaranteed to be atomic
bool deleteObjects; // Used by PCollection but put here for efficiency
bool constObject; // Indicates object is constant/static, copy on write.
PDECLARE_POOL_ALLOCATOR();
private:
void operator=(const PContainerReference &) { }
};
class PContainer : public PObject
{
PCLASSINFO(PContainer, PObject);
public:
PContainer(
PINDEX initialSize = 0
);
PContainer(
const PContainer & cont
);
PContainer & operator=(
const PContainer & cont
);
virtual ~PContainer()
{ Destruct(); }
virtual PINDEX GetSize() const;
virtual PBoolean SetSize(
PINDEX newSize
) = 0;
PBoolean SetMinSize(
PINDEX minSize
);
virtual PBoolean IsEmpty() const;
PBoolean IsUnique() const;
virtual PBoolean MakeUnique();
protected:
PContainer(
int dummy,
const PContainer * cont
);
PContainer(PContainerReference & reference);
virtual void DestroyContents() = 0;
virtual void AssignContents(const PContainer & c);
void CopyContents(const PContainer & c);
void CloneContents(const PContainer * src);
void Destruct();
virtual void DestroyReference();
PContainerReference * reference;
};
#define PCONTAINERINFO(cls, par) \
PCLASSINFO(cls, par) \
public: \
cls(const cls & c) : par(c) { CopyContents(c); } \
cls & operator=(const cls & c) \
{ AssignContents(c); return *this; } \
virtual ~cls() { Destruct(); } \
virtual PBoolean MakeUnique() \
{ if(par::MakeUnique())return true; CloneContents(this);return false; } \
protected: \
cls(int dummy, const cls * c) : par(dummy, c) { CloneContents(c); } \
virtual void DestroyContents(); \
void CloneContents(const cls * c); \
void CopyContents(const cls & c); \
virtual void AssignContents(const PContainer & c) \
{ par::AssignContents(c); CopyContents((const cls &)c); }
// Abstract collection of objects class
class PCollection : public PContainer
{
PCLASSINFO(PCollection, PContainer);
public:
PCollection(
PINDEX initialSize = 0
);
virtual void PrintOn(
ostream &strm
) const;
virtual PINDEX Append(
PObject * obj
) = 0;
virtual PINDEX Insert(
const PObject & before,
PObject * obj
) = 0;
virtual PINDEX InsertAt(
PINDEX index,
PObject * obj
) = 0;
virtual PBoolean Remove(
const PObject * obj
) = 0;
virtual PObject * RemoveAt(
PINDEX index
) = 0;
virtual void RemoveAll();
virtual PBoolean SetAt(
PINDEX index,
PObject * val
) = 0;
virtual PObject * GetAt(
PINDEX index
) const = 0;
virtual PINDEX GetObjectsIndex(
const PObject * obj
) const = 0;
virtual PINDEX GetValuesIndex(
const PObject & obj
) const = 0;
PINLINE void AllowDeleteObjects(
PBoolean yes = true
);
void DisallowDeleteObjects();
protected:
PINLINE PCollection(
int dummy,
const PCollection * coll
);
};
// The abstract array class
#include <ptlib/array.h>
// The abstract array class
#include <ptlib/lists.h>
// PString class (specialised version of PBASEARRAY(char))
#include <ptlib/dict.h>
// PString class
#include <ptlib/pstring.h>
// Fill in all the inline functions
#if P_USE_INLINES
#include <ptlib/contain.inl>
#endif
#endif // PTLIB_CONTAIN_H
// End Of File ///////////////////////////////////////////////////////////////
lists.h
PCLASSINFO
#define PCLASSINFO(cls, par)
Declare all the standard PTLib class information.
Definition: object.h:1049
PINLINE
#define PINLINE
Definition: object.h:127
dict.h
PrintOn
virtual void PrintOn(ostream &strm) const
Print the array.
array.h
PContainerReference::size
PINDEX size
Definition: contain.h:70
PBoolean
BOOL PBoolean
Definition: object.h:102
PAtomicInteger
This class implements an integer that can be atomically incremented and decremented in a thread-safe ...
Definition: critsec.h:171
pstring.h
PContainerReference::constObject
bool constObject
Definition: contain.h:73
PContainerReference
Definition: contain.h:51
PContainerReference::deleteObjects
bool deleteObjects
Definition: contain.h:72
PContainer::~PContainer
virtual ~PContainer()
Destroy the container class.
Definition: contain.h:140
PContainer
Abstract class to embody the base functionality of a container.
Definition: contain.h:104
object.h
PContainerReference::PContainerReference
__inline PContainerReference(PINDEX initialSize, bool isConst=false)
Definition: contain.h:54
PContainerReference::count
PAtomicInteger count
Definition: contain.h:71
critsec.h
PContainer::reference
PContainerReference * reference
Definition: contain.h:291
PContainerReference::PContainerReference
__inline PContainerReference(const PContainerReference &ref)
Definition: contain.h:62
PObject
Ultimate parent class for all objects in the class library.
Definition: object.h:1118
PCollection
A collection is a container that collects together descendents of the PObject class.
Definition: contain.h:395
PContainerReference::PDECLARE_POOL_ALLOCATOR
PDECLARE_POOL_ALLOCATOR()