
Adobe Acrobat SDK
Working with Acrobat Extended APIs
Developing Plug-ins and Applications
Creating agent constructors 228
//Constructor / destructor
DumpAllObjectsAgent(PDDoc hPDDoc);
virtual ~DumpAllObjectsAgent(void);
//Required methods
virtual void ConsAgentPostProcess(void);
virtual ASInt32 ObjFound(CosObj Obj, const PDFObjType*
pObjTypeHierarchy,
const ASUns32 SizeObjHierarchy,
TraversalStack Stack,CosObj* pObjToReturn);
};
Creating agent constructors
In order to write an
Agent
class derived from the
ConsultantAgentObj
base class, you must invoke the
base constructor in the derived classes construction list. The base constructor requires a constant array of
so-called objects of interest (of type
PDFObjType
) as well as the length of the array (as
ASUns32
) to be
passed as parameters. It is up to you as to where and how the array of types is stored; however, the storage
must persist, as the base class saves only a pointer to the data. This has important implications for
authoring agents; the derived class cannot initialize the data in its own constructor since the base
constructor is called first.
The following example shows an example constructor. In the Agent example the array types and array
length are static data members of the
Agent
class. In larger-scale systems it is better to create a host
object for the agent that is responsible for determining the proper objects to include in the array and for
passing them on to the
Agent
constructor. The list of object types is passed on to the consultant when
ConsultantRegisterAgent
is invoked.
Example 20.5
Creating agent constructors
//Define static const data to be passed to parent class constructor
const ASUns32 DumpAllObjectsAgent::s_iNumAgentObjects = 1;
const PDFObjType
DumpAllObjectsAgent::s_hAgentObjects[DumpAllObjectsAgent::
s_iNumAgentObjects] = {DT_ALL};
//Derived Agent class constructor */
DumpAllObjectsAgent::DumpAllObjectsAgent( PDDoc hPDDoc ) :
ConsultantAgentObj( &s_hAgentObjects[ 0 ], s_iNumAgentObjects )
{
Open Temporary File and Initialize Data Members ...}
}
Recognizing objects of interest
Agents register a list of objects with the consultant in which they are interested. When the consultant
classifies an object as any of the types the agent registered with, the consultant calls the
ObjFound
callback function, a virtual function in the
ConsultantAgentObj
base class.
●
The parameters the consultant passes to this function allow the function to set up a return value with
information about the current object, its parents, and the state of the consultant traversal stack.
●
The return value from the callback is an
OR
of bit flags that instruct the consultant on handling the
current object.