1 #ifndef __XMPIterator_hpp__
2 #define __XMPIterator_hpp__
3 
4 // =================================================================================================
5 // Copyright 2002-2007 Adobe Systems Incorporated
6 // All Rights Reserved.
7 //
8 // NOTICE:  Adobe permits you to use, modify, and distribute this file in accordance with the terms
9 // of the Adobe license agreement accompanying it.
10 // =================================================================================================
11 
12 #include "XMP_Environment.h"
13 #include "XMP_Const.h"
14 #include "XMPMeta.hpp"
15 
16 // =================================================================================================
17 
18 struct IterNode;
19 typedef std::vector < IterNode >	IterOffspring;
20 typedef IterOffspring::iterator		IterPos;
21 
22 typedef std::pair < IterPos, IterPos > IterPosPair;
23 typedef std::vector < IterPosPair >	IterPosStack;
24 
25 enum {	// Values for the visitStage field, used to decide how to proceed past a node.
26 	kIter_BeforeVisit		= 0,	// Have not visited this node at all.
27 	kIter_VisitSelf			= 1,	// Have visited this node and returned its value/options portion.
28 	kIter_VisitQualifiers	= 2,	// In the midst of visiting this node's qualifiers.
29 	kIter_VisitChildren		= 3		// In the midst of visiting this node's children.
30 };
31 
32 struct IterNode {
33 
34 	XMP_OptionBits	options;
35 	XMP_VarString	fullPath;
36 	size_t			leafOffset;
37 	IterOffspring	children, qualifiers;
38 	XMP_Uns8		visitStage;
39 	#if 0	// *** XMP_DebugBuild
40 		XMP_StringPtr	_pathPtr, _leafPtr;	// *** Not working, need operator=?
41 	#endif
42 
IterNodeIterNode43 	IterNode() : options(0), leafOffset(0), visitStage(kIter_BeforeVisit)
44 	{
45 		#if 0	// *** XMP_DebugBuild
46 			_pathPtr = _leafPtr = 0;
47 		#endif
48 	};
49 
IterNodeIterNode50 	IterNode ( XMP_OptionBits _options, const XMP_VarString& _fullPath, size_t _leafOffset )
51 			 : options(_options), fullPath(_fullPath), leafOffset(_leafOffset), visitStage(kIter_BeforeVisit)
52 	{
53 		#if 0	// *** XMP_DebugBuild
54 			_pathPtr = fullPath.c_str();
55 			_leafPtr = _pathPtr + leafOffset;
56 		#endif
57 	};
58 
59 };
60 
61 struct IterInfo {
62 
63 	XMP_OptionBits	options;
64 	const XMPMeta *	xmpObj;
65 	XMP_VarString	currSchema;
66 	IterPos			currPos, endPos;
67 	IterPosStack	ancestors;
68 	IterNode 		tree;
69 	#if 0	// *** XMP_DebugBuild
70 		XMP_StringPtr	_schemaPtr;	// *** Not working, need operator=?
71 	#endif
72 
IterInfoIterInfo73 	IterInfo() : options(0), xmpObj(0)
74 	{
75 		#if 0	// *** XMP_DebugBuild
76 			_schemaPtr = 0;
77 		#endif
78 	};
79 
IterInfoIterInfo80 	IterInfo ( XMP_OptionBits _options, const XMPMeta * _xmpObj ) : options(_options), xmpObj(_xmpObj)
81 	{
82 		#if 0	// *** XMP_DebugBuild
83 			_schemaPtr = 0;
84 		#endif
85 	};
86 
87 };
88 
89 // =================================================================================================
90 
91 class XMPIterator {
92 public:
93 
94 	static bool
95 	Initialize();	// ! For internal use only!
96 
97 	static void
98 	Terminate() RELEASE_NO_THROW;	// ! For internal use only!
99 
100 	static void
101 	Unlock ( XMP_OptionBits options );
102 
103 	XMPIterator ( const XMPMeta & xmpObj,	// Construct a property iterator.
104 				  XMP_StringPtr	  schemaNS,
105 				  XMP_StringPtr	  propName,
106 				  XMP_OptionBits  options );
107 
108 	XMPIterator	( XMP_StringPtr	 schemaNS,	// Construct a table iterator.
109 				  XMP_StringPtr	 propName,
110 				  XMP_OptionBits options );
111 
112 	virtual ~XMPIterator() RELEASE_NO_THROW;
113 
114 	bool
115 	Next ( XMP_StringPtr *  schemaNS,
116 		   XMP_StringLen *  nsSize,
117 		   XMP_StringPtr *  propPath,
118 		   XMP_StringLen *  pathSize,
119 		   XMP_StringPtr *  propValue,
120 		   XMP_StringLen *  valueSize,
121 		   XMP_OptionBits * propOptions );
122 
123 	void
124 	Skip ( XMP_OptionBits options );
125 
126 	void
127 	UnlockIter ( XMP_OptionBits options );
128 
129 	// ! Expose so that wrappers and file static functions can see the data.
130 
131 	XMP_Int32 clientRefs;	// ! Must be signed to allow decrement from 0.
132 	IterInfo info;
133 
134 private:
135 
136 	// ! These are hidden on purpose:
XMPIterator()137 	XMPIterator() : clientRefs(0)
138 		{ XMP_Throw ( "Call to hidden constructor", kXMPErr_InternalFailure ); };
XMPIterator(const XMPIterator &)139 	XMPIterator ( const XMPIterator & /* original */ ) : clientRefs(0)
140 		{ XMP_Throw ( "Call to hidden constructor", kXMPErr_InternalFailure ); };
operator =(const XMPIterator &)141 	void operator= ( const XMPIterator & /* rhs */ )
142 		{ XMP_Throw ( "Call to hidden operator=", kXMPErr_InternalFailure ); };
143 
144 };
145 
146 // =================================================================================================
147 
148 #endif	// __XMPIterator_hpp__
149