summaryrefslogtreecommitdiff
path: root/XMPCore/source/XMPIterator.hpp
blob: de68667fce4468344b2a512239712d7bf32bdca2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#ifndef __XMPIterator_hpp__
#define __XMPIterator_hpp__

// =================================================================================================
// Copyright 2003 Adobe
// All Rights Reserved.
//
// NOTICE:  Adobe permits you to use, modify, and distribute this file in accordance with the terms
// of the Adobe license agreement accompanying it. 
// =================================================================================================

#include "public/include/XMP_Environment.h"
#include "public/include/XMP_Const.h"
#include "XMPCore/source/XMPMeta.hpp"

// =================================================================================================

struct IterNode;
typedef std::vector < IterNode >	IterOffspring;
typedef IterOffspring::iterator		IterPos;

typedef std::pair < IterPos, IterPos > IterPosPair;
typedef std::vector < IterPosPair >	IterPosStack;

enum {	// Values for the visitStage field, used to decide how to proceed past a node.
	kIter_BeforeVisit		= 0,	// Have not visited this node at all.
	kIter_VisitSelf			= 1,	// Have visited this node and returned its value/options portion.
	kIter_VisitQualifiers	= 2,	// In the midst of visiting this node's qualifiers.
	kIter_VisitChildren		= 3		// In the midst of visiting this node's children.
};

struct IterNode {

	XMP_OptionBits	options;
	XMP_VarString	fullPath;
	size_t			leafOffset;
	IterOffspring	children, qualifiers;
	XMP_Uns8		visitStage;
	#if 0	// *** XMP_DebugBuild
		XMP_StringPtr	_pathPtr, _leafPtr;	// *** Not working, need operator=?
	#endif

	IterNode() : options(0), leafOffset(0), visitStage(kIter_BeforeVisit)
	{
		#if 0	// *** XMP_DebugBuild
			_pathPtr = _leafPtr = 0;
		#endif
	};

	IterNode ( XMP_OptionBits _options, const XMP_VarString& _fullPath, size_t _leafOffset )
			 : options(_options), fullPath(_fullPath), leafOffset(_leafOffset), visitStage(kIter_BeforeVisit)
	{
		#if 0	// *** XMP_DebugBuild
			_pathPtr = fullPath.c_str();
			_leafPtr = _pathPtr + leafOffset;
		#endif
	};

};

struct IterInfo {

	XMP_OptionBits	options;
	const XMPMeta *	xmpObj;
	XMP_VarString	currSchema;
	IterPos			currPos, endPos;
	IterPosStack	ancestors;
	IterNode 		tree;
	#if 0	// *** XMP_DebugBuild
		XMP_StringPtr	_schemaPtr;	// *** Not working, need operator=?
	#endif

	IterInfo() : options(0), xmpObj(0)
	{
		#if 0	// *** XMP_DebugBuild
			_schemaPtr = 0;
		#endif
	};

	IterInfo ( XMP_OptionBits _options, const XMPMeta * _xmpObj ) : options(_options), xmpObj(_xmpObj)
	{
		#if 0	// *** XMP_DebugBuild
			_schemaPtr = 0;
		#endif
	};

};

// =================================================================================================

class XMPIterator {
public:
	
	static bool
	Initialize();	// ! For internal use only!
	
	static void
	Terminate() RELEASE_NO_THROW;	// ! For internal use only!

	XMPIterator ( const XMPMeta & xmpObj,	// Construct a property iterator.
				  XMP_StringPtr	  schemaNS,
				  XMP_StringPtr	  propName,
				  XMP_OptionBits  options );

	XMPIterator	( XMP_StringPtr	 schemaNS,	// Construct a table iterator.
				  XMP_StringPtr	 propName,
				  XMP_OptionBits options );

	virtual ~XMPIterator() RELEASE_NO_THROW;

	virtual bool
	Next ( XMP_StringPtr *  schemaNS,
		   XMP_StringLen *  nsSize,
		   XMP_StringPtr *  propPath,
		   XMP_StringLen *  pathSize,
		   XMP_StringPtr *  propValue,
		   XMP_StringLen *  valueSize,
		   XMP_OptionBits * propOptions );

	virtual void
	Skip ( XMP_OptionBits options );

	// ! Expose so that wrappers and file static functions can see the data.

	XMP_Int32 clientRefs;	// ! Must be signed to allow decrement from 0.
	XMP_ReadWriteLock lock;

	IterInfo info;

private:

	// ! These are hidden on purpose:
	XMPIterator() : clientRefs(0)
		{ XMP_Throw ( "Call to hidden constructor", kXMPErr_InternalFailure ); };
	XMPIterator ( const XMPIterator & /* original */ ) : clientRefs(0)
		{ XMP_Throw ( "Call to hidden constructor", kXMPErr_InternalFailure ); };
	void operator= ( const XMPIterator & /* rhs */ )
		{ XMP_Throw ( "Call to hidden operator=", kXMPErr_InternalFailure ); };

};

// =================================================================================================

#endif	// __XMPIterator_hpp__