File: FileHandler.h

package info (click to toggle)
exempi 2.6.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,780 kB
  • sloc: cpp: 79,791; sh: 4,606; ansic: 538; makefile: 383
file content (101 lines) | stat: -rw-r--r-- 3,348 bytes parent folder | download | duplicates (2)
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
// =================================================================================================
// Copyright Adobe
// Copyright 2011 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. 
// =================================================================================================

#ifndef PLUGINHANDLER_H
#define PLUGINHANDLER_H
#include "Module.h"

namespace XMP_PLUGIN
{

/** @struct CheckFormat
 *  @brief Record of byte sequences.
 *
 *  It is a static information of the file handler provided in the resource file, if the format 
 *  can be identified by one or more sequences of fixed bytes at a fixed location within the format.
 */
struct CheckFormat
{
	XMP_Int64 mOffset;
	XMP_Uns32 mLength;
	std::string mByteSeq;

	CheckFormat(): mOffset( 0 ), mLength( 0 ) { }
	
	inline void clear()
	{
		mOffset = 0; mLength = 0; mByteSeq.clear(); 
	}
	
	inline bool empty() 
	{ 
		return ( mLength == 0 || mByteSeq.empty() );
	}	
};

/** @class FileHandler
 *  @brief File handler exposed through plugin architecture.
 *
 *  At the initialization time of XMPFiles only static information from all the avalbale plugins
 *  is populated by creating instance of this class FileHandler. It's loaded later when it's actually 
 *  required to get information from the format.
 */
class FileHandler
{
public:
	
	FileHandler(std::string & uid, XMP_OptionBits handlerFlags, FileHandlerType type, ModuleSharedPtr module):
	  mVersion(0), mUID(uid), mHandlerFlags(handlerFlags), mSerializeOption(0), mOverwrite(false), mType(type), mModule(module) {}

	virtual ~FileHandler(){}

	inline double getVersion() const { return mVersion; }
	inline void setVersion( double version ) { mVersion = version; }

	inline const std::string& getUID() const { return mUID; }
	inline XMP_OptionBits getHandlerFlags() const { return mHandlerFlags; }
	inline void setHandlerFlags( XMP_OptionBits flags ) { mHandlerFlags = flags; }
	
	inline XMP_OptionBits getSerializeOption() const { return mSerializeOption; }
	inline void setSerializeOption( XMP_OptionBits option ) { mSerializeOption = option; }

	inline bool getOverwriteHandler() const { return mOverwrite; }
	inline void setOverwriteHandler( bool overwrite ) { mOverwrite = overwrite; }
	
	inline FileHandlerType getHandlerType() const { return mType; }
	inline void setHandlerType( FileHandlerType type ) { mType = type; }

	inline bool load() { return mModule->load(); }
	inline ModuleSharedPtr getModule() const { return mModule; }

	inline void addCheckFormat( const CheckFormat & checkFormat ) { mCheckFormatVec.push_back( checkFormat ); }
	inline XMP_Uns32 getCheckFormatSize() const { return (XMP_Uns32) mCheckFormatVec.size(); }
	inline CheckFormat getCheckFormat( XMP_Uns32 index ) const 
	{
		CheckFormat checkFormat;
		if( index < mCheckFormatVec.size() )
			checkFormat = mCheckFormatVec[index];
		return checkFormat;
	}
	
private:
	typedef std::vector<CheckFormat> CheckFormatVec;

	CheckFormatVec				mCheckFormatVec;
	double						mVersion;
	std::string					mUID;
	XMP_OptionBits				mHandlerFlags;
	XMP_OptionBits				mSerializeOption;
	bool						mOverwrite;
	FileHandlerType				mType;
	ModuleSharedPtr				mModule;
};

} //namespace XMP_PLUGIN
#endif //PLUGINHANDLER_H