pdfobjects::CDict Class Reference

#include <cdict.h>

Inheritance diagram for pdfobjects::CDict:
pdfobjects::IProperty observer::ObserverHandler< T >

List of all members.

Public Types

typedef std::list< std::pair
< std::string,
boost::shared_ptr< IProperty > > > 
Value
typedef const std::string & WriteType
typedef const std::string & PropertyId
typedef
observer::ComplexChangeContext
< IProperty, PropertyId
CDictComplexObserverContext

Public Member Functions

 CDict (boost::weak_ptr< CPdf > p, const Object &o, const IndiRef &rf)
 CDict (const Object &o)
 CDict ()
virtual PropertyType getType () const
virtual void getStringRepresentation (std::string &str) const
void init (const CDict &dict)
size_t getPropertyCount () const
template<typename Container >
void getAllPropertyNames (Container &container) const
bool containsProperty (const std::string &name) const
boost::shared_ptr< IPropertygetProperty (PropertyId id) const
PropertyType getPropertyType (PropertyId id) const
virtual void setPdf (boost::weak_ptr< CPdf > pdf)
virtual void setIndiRef (const IndiRef &rf)
boost::shared_ptr< IPropertysetProperty (PropertyId id, IProperty &ip)
boost::shared_ptr< IPropertyaddProperty (const std::string &propertyName, const IProperty &newIp)
void delProperty (PropertyId id)
 ~CDict ()
template<typename Fctor >
void forEach (Fctor &fctor)
virtual ::Object * _makeXpdfObject () const
template<typename Storage >
void _getAllChildObjects (Storage &store) const

Static Public Attributes

static const PropertyType type = pDict

Protected Member Functions

virtual IPropertydoClone () const
virtual CDict_newInstance () const
void _setMode (boost::shared_ptr< IProperty > ip, PropertyId id) const

Private Member Functions

ObserverContext_createContext (boost::shared_ptr< IProperty > changedIp, PropertyId id)
void _objectChanged (boost::shared_ptr< IProperty > newValue, boost::shared_ptr< const ObserverContext > context)

Private Attributes

Value value

Friends

class CStream

Detailed Description

Class representing dictionary object from pdf specification v1.5.

We do not want to use xpdf dictionary because it is a real mess and it is really not suitable for editing. We use xpdf object just for initializing.

According to pdf specification, dictionary is a container of keys and values. Keys are strings identifying items. You can not rely on the position of a value. Value can be any object from pdf specification. Pdf objects form a tree like structure.

This class does not provide default copy constructor because copying a property could be understood either as deep copy or shallow copy. Copying complex types could be very expensive so we have made the decision to avoid it.

REMARK: It is similar to CArray but it has also too much differences to be cleanly implemented as one template class. (It has been implemented like one template class but later was seperated to CArray and CDict)

See also:
CObjectSimple, CArray, CStream

Member Typedef Documentation

typedef const std::string& pdfobjects::CDict::PropertyId
typedef std::list<std::pair<std::string, boost::shared_ptr<IProperty> > > pdfobjects::CDict::Value
typedef const std::string& pdfobjects::CDict::WriteType

Constructor & Destructor Documentation

pdfobjects::CDict::CDict ( boost::weak_ptr< CPdf p,
const Object &  o,
const IndiRef rf 
)

Constructor.

Parameters:
p Pointer to pdf object.
o Xpdf object.
rf Indirect id and gen id.

References value.

pdfobjects::CDict::CDict ( const Object &  o  ) 

Constructor.

Parameters:
o Xpdf object.

References value.

pdfobjects::CDict::CDict (  )  [inline]

Public constructor. This object will not be associated with a pdf.

pdfobjects::CDict::~CDict (  )  [inline]

Destructor


Member Function Documentation

ObserverContext* pdfobjects::CDict::_createContext ( boost::shared_ptr< IProperty changedIp,
PropertyId  id 
) [private]

Create context of a change.

REMARK: Be carefull. Deallocate the object.

Parameters:
changedIp Pointer to old value.
id Id identifies changed property.
Returns:
Context in which a change occured.

Referenced by delProperty(), and setProperty().

template<typename Storage >
void pdfobjects::CDict::_getAllChildObjects ( Storage &  store  )  const [inline]

Return all child objects.

Parameters:
store Output container of all child objects.

References value.

Object * pdfobjects::CDict::_makeXpdfObject (  )  const [virtual]

Make xpdf Object from this object. This function allocates and initializes xpdf object. Caller has to deallocate the xpdf Object.

Returns:
Xpdf object representing this object.
Exceptions:
ObjBadValueE Thrown when xpdf can't parse the string representation of this object correctly.

Implements pdfobjects::IProperty.

References pdfobjects::XPdfObjectFactory::getInstance(), pdfobjects::IProperty::getPdf(), getPropertyCount(), pdfobjects::IProperty::pdf, and value.

virtual CDict* pdfobjects::CDict::_newInstance (  )  const [inline, protected, virtual]

Return new instance.

This function is a factory method design pattern for creating complex instances.

Returns:
New complex object.

Referenced by doClone().

void pdfobjects::CDict::_objectChanged ( boost::shared_ptr< IProperty newValue,
boost::shared_ptr< const ObserverContext context 
) [private]

Indicate that the object has changed. Notifies all observers associated with this property about the change.

Parameters:
newValue Pointer to new value of an object.
context Context in which a change occured.

Referenced by delProperty(), and setProperty().

void pdfobjects::CDict::_setMode ( boost::shared_ptr< IProperty ip,
PropertyId  id 
) const [protected]

Set mode of a property.

Parameters:
ip IProperty which mode will be set.
id Key identifying property.

Referenced by getProperty(), and setProperty().

boost::shared_ptr<IProperty> pdfobjects::CDict::addProperty ( const std::string &  propertyName,
const IProperty newIp 
)

Add property to dictionary.

Firstly, the property that is passed as argument is cloned and the cloned object is added. Indicate that this object has changed and return the pointer to the cloned object.

If a property with the same name is already in this dictionary an exception is thrown.

Parameters:
propertyName property name
newIp new property
Returns:
Pointer to the new property.
Exceptions:
OutOfRange Thrown when property not found.
CObjInvalid When the object is invalid

Referenced by pdfobjects::CPageContents::addInlineImage(), pdfobjects::CStream::addProperty(), pdfobjects::utils::dictFromXpdfObj(), and setProperty().

bool pdfobjects::CDict::containsProperty ( const std::string &  name  )  const

Returns true if the property name is present in the dictionary.

Parameters:
name Property name
Returns:
True if the property exists, false otherwise.

Referenced by pdfobjects::CStream::containsProperty(), and gui::QSDict::exist().

void pdfobjects::CDict::delProperty ( PropertyId  id  ) 
IProperty * pdfobjects::CDict::doClone (  )  const [protected, virtual]

Clone. Performs deep copy. REMARK: It will not copy pdf indirect objects that are referenced from the pdf object tree starting in this object.

Returns:
Deep copy of this object.

Implements pdfobjects::IProperty.

References _newInstance(), and value.

template<typename Fctor >
void pdfobjects::CDict::forEach ( Fctor &  fctor  )  [inline]

Apply functor operator() on each element. The operator() will get std::pair<string, shared_ptr<IProperty>> as parameter. First item identifies the property.

Parameters:
fctor Functor that will do the work.

References value.

template<typename Container >
void pdfobjects::CDict::getAllPropertyNames ( Container &  container  )  const [inline]

Inserts all property names of this complex type to the container supplied by caller.

Parameters:
container Output container of string objects. Could be vector,list,deque etc.

References value.

Referenced by pdfobjects::CStream::getAllPropertyNames(), gui::TreeItemDict::getChildNames(), pdfobjects::CInlineImage::getStringRepresentation(), and gui::QSDict::propertyNames().

shared_ptr< IProperty > pdfobjects::CDict::getProperty ( PropertyId  id  )  const
size_t pdfobjects::CDict::getPropertyCount (  )  const [inline]
PropertyType pdfobjects::CDict::getPropertyType ( PropertyId  id  )  const [inline]

Returns property type of an item identified by name.

Parameters:
id Name of the property.
Returns:
Property type.
Exceptions:
ObjInvalidPositionInComplex When the id does not correctly identify an item.

References getProperty().

Referenced by pdfobjects::CStream::getPropertyType().

virtual void pdfobjects::CDict::getStringRepresentation ( std::string &  str  )  const [virtual]

Returns string representation of this object according to pdf specification.

Parameters:
str Output string that will hold the string representation of current object.

Implements pdfobjects::IProperty.

Referenced by gui::QSDict::getText().

virtual PropertyType pdfobjects::CDict::getType (  )  const [inline, virtual]

Return type of this property.

Returns:
Type of this property.

Implements pdfobjects::IProperty.

References type.

void pdfobjects::CDict::init ( const CDict dict  ) 

Simple shallow copy constructor (does not copy pointers).

Parameters:
dict dictionary which will be copied

References value.

void pdfobjects::CDict::setIndiRef ( const IndiRef rf  )  [virtual]

Set ref to this object and its children.

Parameters:
rf New indirect reference number.

Reimplemented from pdfobjects::IProperty.

References value.

void pdfobjects::CDict::setPdf ( boost::weak_ptr< CPdf pdf  )  [virtual]

Set pdf to this object and its children.

Parameters:
pdf New pdf.

Reimplemented from pdfobjects::IProperty.

References value.

Referenced by pdfobjects::CPdf::getTrailer().

shared_ptr< IProperty > pdfobjects::CDict::setProperty ( PropertyId  id,
IProperty ip 
)

Sets property type of an item.

Firstly, the property that is passed as argument is cloned and the cloned object replaces object specified by id. If the item does not exist it is added.

Parameters:
id Name/Index of property
ip Value, for simple types (int,string,...) and for complex types IProperty*
Returns:
Pointer to the new property.

References _createContext(), _objectChanged(), _setMode(), addProperty(), pdfobjects::IProperty::canChange(), pdfobjects::IProperty::clone(), debug::DBG_DBG, pdfobjects::IProperty::getIndiRef(), pdfobjects::DictIdxComparator::getIProperty(), pdfobjects::IProperty::getPdf(), pdfobjects::hasValidPdf(), pdfobjects::hasValidRef(), kernelPrintDbg, and value.

Referenced by pdfobjects::CStream::setProperty().


Friends And Related Function Documentation

friend class CStream [friend]

Member Data Documentation

const PropertyType pdfobjects::CDict::type = pDict [static]

Type of this property object. This association allows us to get the PropertyType from object type.

Referenced by getType().


The documentation for this class was generated from the following files: