summaryrefslogtreecommitdiff
path: root/source/Endian.h
blob: a78501d95fe86229cc05fc8b28d6dd2752137e1d (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
/**************************************************************************
*
* Copyright Adobe
* Copyright 2020 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 _Endian_h_
#define _Endian_h_ 1

#include "public/include/XMP_Environment.h"	// ! This must be the first include.
#include "public/include/XMP_Const.h"
#include "source/EndianUtils.hpp"

class IEndian
{
public:
	virtual ~IEndian() {};

	virtual XMP_Uns16	getUns16	( const void* value ) const	= 0;
	virtual XMP_Uns32	getUns32	( const void* value ) const	= 0;
	virtual XMP_Uns64	getUns64	( const void* value ) const	= 0;
	virtual float		getFloat	( const void* value ) const	= 0;
	virtual double		getDouble	( const void* value ) const	= 0;

	virtual void	putUns16	( XMP_Uns16 value, void* dest ) const	= 0;
	virtual void	putUns32	( XMP_Uns32 value, void* dest ) const	= 0;
	virtual void	putUns64	( XMP_Uns64 value, void* dest ) const	= 0;
	virtual void	putFloat	( float value, void* dest ) const	= 0;
	virtual void	putDouble	( double value, void* dest ) const	= 0;
};


class LittleEndian : public IEndian
{
private:
	// Private Constructors / operators to prevent direkt creation
	LittleEndian() {};
	LittleEndian( const LittleEndian& ) {};
	LittleEndian& operator=( const LittleEndian& ) { return *this; };

public:
	// Singleton Factory
	static const LittleEndian& getInstance()
	{
		// Singleton instance (on Stack)
		static LittleEndian instance;

		return instance;
	}

	virtual XMP_Uns16	getUns16	( const void* value ) const		{ return GetUns16LE( value ); }
	virtual XMP_Uns32	getUns32	( const void* value ) const		{ return GetUns32LE( value ); }
	virtual XMP_Uns64	getUns64	( const void* value ) const		{ return GetUns64LE( value ); }
	virtual float		getFloat	( const void* value ) const		{ return GetFloatLE( value ); }
	virtual double		getDouble	( const void* value ) const		{ return GetDoubleLE( value ); }

	virtual void	putUns16	( XMP_Uns16 value, void* dest ) const	{ PutUns16LE( value, dest ); }
	virtual void	putUns32	( XMP_Uns32 value, void* dest ) const	{ PutUns32LE( value, dest ); }
	virtual void	putUns64	( XMP_Uns64 value, void* dest ) const	{ PutUns64LE( value, dest ); }
	virtual void	putFloat	( float value, void* dest ) const		{ PutFloatLE( value, dest ); }
	virtual void	putDouble	( double value, void* dest ) const		{ PutDoubleLE( value, dest ); }
}; // LittleEndian


class BigEndian : public IEndian
{
private:
	// Private Constructors / operators to prevent direkt creation
	BigEndian() {};
	BigEndian( const BigEndian& ) {};
	BigEndian& operator=( const BigEndian& ) { return *this; };

public:
	// Singleton Factory
	static const BigEndian& getInstance()
	{
		// Singleton instance (on Stack)
		static BigEndian instance;

		return instance;
	}

	virtual XMP_Uns16	getUns16	( const void* value ) const		{ return GetUns16BE( value ); }
	virtual XMP_Uns32	getUns32	( const void* value ) const		{ return GetUns32BE( value ); }
	virtual XMP_Uns64	getUns64	( const void* value ) const		{ return GetUns64BE( value ); }
	virtual float		getFloat	( const void* value ) const		{ return GetFloatBE( value ); }
	virtual double		getDouble	( const void* value ) const		{ return GetDoubleBE( value ); }

	virtual void	putUns16	( XMP_Uns16 value, void* dest ) const	{ PutUns16BE( value, dest ); }
	virtual void	putUns32	( XMP_Uns32 value, void* dest ) const	{ PutUns32BE( value, dest ); }
	virtual void	putUns64	( XMP_Uns64 value, void* dest ) const	{ PutUns64BE( value, dest ); }
	virtual void	putFloat	( float value, void* dest ) const		{ PutFloatBE( value, dest ); }
	virtual void	putDouble	( double value, void* dest ) const		{ PutDoubleBE( value, dest ); }
}; // BigEndian

#endif