/* * 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: cobjectsimpleI.h * Created: 02/02/2006 * Author: jmisutka (06/01/19), * * ===================================================================================== */ #ifndef _COBJECTSIMPLEI_H #define _COBJECTSIMPLEI_H //===================================================================================== namespace pdfobjects { //===================================================================================== //===================================================================================== // CObjectSimple //===================================================================================== // // Constructors // // // Protected constructor, called when we have parsed an object // template CObjectSimple::CObjectSimple (CPdf& p, Object& o, const IndiRef& rf) : IProperty (&p,rf), value(Value()) { //kernelPrintDbg (debug::DBG_DBG,"CObjectSimple <" << debug::getStringType() << ">(p,o,rf) constructor."); // Set object's value utils::simpleValueFromXpdfObj (o,value); } // // Protected constructor, called when we have parsed an object // template CObjectSimple::CObjectSimple (Object& o) : value(Value()) { //kernelPrintDbg (debug::DBG_DBG,"CObjectSimple <" << debug::getStringType() << ">(o) constructor."); // Set object's value utils::simpleValueFromXpdfObj (o,value); } // // Public constructor // template CObjectSimple::CObjectSimple (const Value& val) : IProperty(), value(val) { //kernelPrintDbg (debug::DBG_DBG,"CObjectSimple <" << debug::getStringType() << ">(val) constructor."); } // // Get methods // // // Turn object to string // template void CObjectSimple::getStringRepresentation (std::string& str) const { utils::simpleValueToString (value, str); } // // Get the value of an property // template void CObjectSimple::getValue (Value& val) const { STATIC_CHECK ((pNull != Tp),INCORRECT_USE_OF_writeValue_FUNCTION_FOR_pNULL_TYPE); val = value; } // // Get the value of an property // template typename PropertyTraitSimple::value CObjectSimple::getValue () const { STATIC_CHECK ((pNull != Tp),INCORRECT_USE_OF_writeValue_FUNCTION_FOR_pNULL_TYPE); return value; } // // Set methods // // // Set string representation // template void CObjectSimple::setStringRepresentation (const std::string& strO) { STATIC_CHECK ((Tp != pNull),INCORRECT_USE_OF_setStringRepresentation_FUNCTION_FOR_pNULL_TYPE); //kernelPrintDbg (debug::DBG_DBG,"text:" << strO); // Check whether we can make the change this->canChange(); if (hasValidPdf (this)) { assert (hasValidRef (this)); // Create context in which the change occurs boost::shared_ptr context (this->_createContext()); // Change our value utils::simpleValueFromString (strO, value); try { // notify observers and dispatch the change _objectChanged (context); }catch (PdfException&) { assert (!"Should not happen.. Condition must be included in CPdf::canChange()..."); throw; } }else { assert (!hasValidRef (this)); // Change our value utils::simpleValueFromString (strO, this->value); } } // // Write a value. // template void CObjectSimple::setValue (WriteType val) { STATIC_CHECK ((pNull != Tp),INCORRECT_USE_OF_setValue_FUNCTION_FOR_pNULL_TYPE); //kernelPrintDbg (debug::DBG_DBG, "setValue() type: " << Tp); // Check whether we can make the change this->canChange(); if (hasValidPdf (this)) { assert (hasValidRef (this)); // Create context in which the change occurs boost::shared_ptr context (this->_createContext()); // Change the value value = val; try { // notify observers and dispatch the change _objectChanged (context); }catch (PdfException&) { assert (!"Should not happen.. Condition must be included in CPdf::canChange()..."); throw; } }else { assert (!hasValidRef (this)); // Change the value value = val; } } // // Helper function // // // // template ::Object* CObjectSimple::_makeXpdfObject () const { //kernelPrintDbg (debug::DBG_DBG,"_makeXpdfObject"); return utils::simpleValueToXpdfObj (value); } // // // template void CObjectSimple::_objectChanged (boost::shared_ptr context) { kernelPrintDbg (debug::DBG_DBG, "CObjectSimple"); // Do not notify anything if we are not in a valid pdf if (!hasValidPdf (this)) return; assert (hasValidRef(this)); // Dispatch the change this->dispatchChange (); if (context) { // Return new value (mh wanted it this way) boost::shared_ptr newValue (this, EmptyDeallocator ()); // Fill them with correct values newValue->setPdf (this->getPdf()); newValue->setIndiRef (this->getIndiRef()); // Notify everybody about this change this->notifyObservers (newValue, context); }else { assert (!"Invalid context"); throw CObjInvalidOperation (); } } // // Clone method // template IProperty* CObjectSimple::doClone () const { kernelPrintDbg (debug::DBG_DBG,"CObjectSimple::doClone ()"); // Make new complex object // NOTE: We do not want to preserve any IProperty variable return new CObjectSimple (value); } //===================================================================================== } // namespace pdfobjects //===================================================================================== #endif // _COBJECTSIMPLEI_H