/* * PDFedit - free program for PDF document manipulation. * Copyright (C) 2006, 2007 PDFedit team: Michal Hocko, * Miroslav Jahoda, * Jozef Misutka, * Martin Petricek * * Project is hosted on http://sourceforge.net/projects/pdfedit */ // vim:tabstop=4:shiftwidth=4:noexpandtab:textwidth=80 /* * ===================================================================================== * Filename: iproperty.cc * Description: IProperty. * Created: 12/04/2006 00:48:14 PM CET * Author: jmisutka (), * ===================================================================================== */ #include "static.h" #include "iproperty.h" #include "cobject.h" #include "cpdf.h" //===================================================================================== namespace pdfobjects { //===================================================================================== // // Constructor // IProperty::IProperty (CPdf* _pdf) : mode(mdUnknown), pdf(_pdf), wantDispatch (true) { ref.num = ref.gen = 0; } // // Constructor // IProperty::IProperty (CPdf* _pdf, const IndiRef& rf) : ref(rf), mode(mdUnknown), pdf(_pdf), wantDispatch (true) {} // // Deep copy // boost::shared_ptr IProperty::clone () const { // Call virtual doClone() to get the right clone boost::shared_ptr ip (doClone ()); if (typeid(*ip) != typeid (*this)) { assert (!"doClone INCORRECTLY overriden!!" ); throw CObjInvalidCast (); } assert (typeid (*ip) == typeid (*this)); return ip; } // // Set/Get pdf // void IProperty::setPdf (CPdf* p) { pdf = p; } void IProperty::canChange () const { if (pdf && wantDispatch) pdf->canChange (); } // // Dispatch change // void IProperty::dispatchChange () const { assert (hasValidPdf (this)); assert (hasValidRef (this)); if (!hasValidPdf (this)) throw CObjInvalidObject (); // If we do not want to dispatch methods return if (!wantDispatch) return; // // If this is an indirect object inform xref about the change // else find the closest indirect object and call dispatchChange on that object // boost::shared_ptr indiObj; if (utils::objHasParent (*this, indiObj)) { assert (indiObj); assert (getIndiRef() == indiObj->getIndiRef()); indiObj->dispatchChange (); }else { // Indicate to pdf that it should change this object CPdf* pdf = IProperty::getPdf (); assert (pdf); pdf->changeIndirectProperty (indiObj); } } //===================================================================================== // Output functions //===================================================================================== // // // std::ostream & operator << (std::ostream & out, PropertyType type) { using namespace std; string stringType; switch(type) { case pNull: stringType=getStringType(); break; case pBool: stringType=getStringType(); break; case pInt: stringType=getStringType(); break; case pReal: stringType=getStringType(); break; case pString: stringType=getStringType(); break; case pName: stringType=getStringType(); break; case pRef: stringType=getStringType(); break; case pArray: stringType=getStringType(); break; case pDict: stringType=getStringType(); break; case pStream: stringType=getStringType(); break; case pOther: stringType=getStringType(); break; case pOther1: stringType=getStringType(); break; case pOther2: stringType=getStringType(); break; case pOther3: stringType=getStringType(); break; } out<(); break; case objInt: // integer stringType=getStringType(); break; case objReal: // real stringType=getStringType(); break; case objString: // string stringType=getStringType(); break; case objName: // name stringType=getStringType(); break; case objNull: // null stringType=getStringType(); break; // complex objects case objArray: // array stringType=getStringType(); break; case objDict: // dictionary stringType=getStringType(); break; case objStream: // stream stringType=getStringType(); break; case objRef: // indirect reference stringType=getStringType(); break; // special objects case objCmd: // command name stringType=getStringType(); break; case objError: // error return from Lexer stringType=getStringType(); break; case objEOF: // end of file return from Lexer stringType=getStringType(); break; case objNone: // uninitialized object stringType=getStringType(); break; } out<