Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   Related Pages  

pdf::core::CDictionary Class Reference

the PDF dictionary class More...

#include <Dictionary.hh>

Inheritance diagram for pdf::core::CDictionary:

Inheritance graph
[legend]
Collaboration diagram for pdf::core::CDictionary:

Collaboration graph
[legend]
List of all members.

Public Types

Public Methods

Private Types

Private Attributes


Detailed Description

the PDF dictionary class

this class represents a PDF dictionary object. according to the PDF specs, the PDF dictionary is a collection of PDF name and PDF object pairs. the PDF name acts as a key to the corresponding object.

this class store the key pairs in a STL vector, not a map. it is because the key pairs will not be looked up frequently. using a vector can save the overhead of a map.


Member Typedef Documentation

typedef boost::shared_ptr<CObject> pdf::core::CDictionary::CObjPtr [private]
 

shortcut

typedef std::pair<CName, CObjPtr> pdf::core::CDictionary::CKeyPair [private]
 

the key pair

typedef std::vector<CKeyPair> pdf::core::CDictionary::CPairVec [private]
 

a vector of the key pair

typedef CPairVec::const_iterator pdf::core::CDictionary::iterator
 

immutable iterator

typedef CPairVec::value_type pdf::core::CDictionary::value_type
 

shortcut


Constructor & Destructor Documentation

pdf::core::CDictionary::CDictionary   [inline]
 

default constructor create empty dictionary

pdf::core::CDictionary::~CDictionary   [inline]
 

destructor do nothing. vector and shared_ptr will do the job.

pdf::core::CDictionary::CDictionary const CDictionary &    dict
 

the copy constructor will deep copy all contained objects.

00066 {
00067     using namespace std ;
00068     transform( dict.begin( ), dict.end( ), back_inserter( m_pairs ),
00069                DupKeyPair( ) ) ;
00070 }

template<typename InputIt>
pdf::core::CDictionary::CDictionary InputIt    first,
InputIt    last
[inline]
 

constructor will take a range of key pairs. assumes InputIt::value_type is the same as our own value_type.

00081         : m_pairs( first, last )
00082     {
00083     }

pdf::core::CDictionary::CDictionary const CName   name,
CObject   object
 

constructor to create a single key pair in the dictionary. it is like calling the default constructor and then call AddPair()

00045     : m_pairs( 1, CKeyPair( name, CObjPtr( object ) ) )
00046 {
00047     assert( !name.empty( ) ) ;
00048     assert( object != 0 ) ;
00049 }


Member Function Documentation

void pdf::core::CDictionary::AddPair const CName   name,
CObject   object
 

adds a new pair to the dictionary.

00075 {
00076     assert( !name.empty( ) ) ;
00077     assert( object != 0 ) ;
00078 
00079     m_pairs.push_back( CKeyPair( name, CObjPtr( object ) ) ) ;
00080 }

void pdf::core::CDictionary::AddPair const std::string &    name,
const std::string &    val_name
[inline]
 

shortcut

00091         { AddPair( CName( name ), new CName( val_name ) ) ; }

void pdf::core::CDictionary::AddPair const std::string &    name,
CObject   object
[inline]
 

another shortcut

00095         { AddPair( CName( name ), object ) ; }

iterator pdf::core::CDictionary::begin   const [inline]
 

read only access to the key pairs

00098 { return m_pairs.begin( ) ; }

iterator pdf::core::CDictionary::end   const [inline]
 

read only access to the key pairs

00101 { return m_pairs.end( ) ; }

std::ostream & pdf::core::CDictionary::Write std::ostream &    os const [virtual]
 

write the dictionary to the output stream, which should be a PDF file.

Implements pdf::core::CObject.

00090 {
00091     using namespace std ;
00092 
00093     os << "<<\n";
00094 
00095     copy( m_pairs.begin( ), m_pairs.end( ),
00096           ostream_iterator<value_type>( os, "\n" ) ) ;
00097 
00098     return os << ">>" ;
00099 }

CObject * pdf::core::CDictionary::Dup   const [virtual]
 

dynamic clone. like CArray::Dup(),it will deep copy the contained objects.

Implements pdf::core::CObject.

00105 {
00106     return new CDictionary( m_pairs.begin( ), m_pairs.end( ) ) ;
00107 }

boost::shared_ptr< CObject > & pdf::core::CDictionary::operator[] const std::string &    name
 

allows mutable access to the individual CObject inside the dictionary. this function uses a linear search to access the key.

Exceptions:
std::out_of_range  if cannot find the given key.

00115 {
00116     using namespace std ;
00117     using namespace __gnu_cxx ;
00118     using namespace boost ;
00119 
00120     CPairVec::iterator i
00121         = std::find_if( m_pairs.begin( ), m_pairs.end( ),
00122                         bind( equal_to<CName>( ),
00123                               bind( select1st<CKeyPair>( ), _1 ),
00124                               CName( name ) ) );
00125 
00126     if ( i == m_pairs.end( ) )
00127         throw std::out_of_range( "cannot find key" ) ;
00128     
00129     return i->second ;
00130 }

void pdf::core::CDictionary::clear   [inline]
 

removes all key pairs. becomes an empty dictionary

00110 { m_pairs.clear( ) ; }


Member Data Documentation

CPairVec pdf::core::CDictionary::m_pairs [private]
 

the vector of key pairs


The documentation for this class was generated from the following files:
Generated on Sun Feb 2 09:17:12 2003 for libpdf++ by doxygen1.2.16