Code Search for Developers
 
 
  

Align.h from redshed at Krugle


Show Align.h syntax highlighted

/****************************************************************************************
	Align.h $Revision: 10 $
		<http://rentzsch.com/align>
	
	Copyright © 1999-2002 Red Shed Software. All rights reserved.
	by Jonathan 'Wolf' Rentzsch (jon@redshed.net)
	
	************************************************************************************/

#ifndef		_Align_
#define		_Align_

/**************************
*	
*	Types
*	
**************************/
#pragma mark	(Types)

typedef	UInt8	Pad;
typedef	UInt16	Pad2;
typedef	UInt32	Pad4;
typedef	UInt32	Pad8[ 2 ];
typedef	UInt32	Pad16[ 4 ];

/**************************
*	
*	Interfaces
*	
**************************/
#pragma mark	-
#pragma mark	(Interfaces)

#ifdef		__cplusplus
extern	"C"	{
#endif	//	__cplusplus

	extern
	void
Align2(
	void	**ptr );

	extern
	void*
AlignDirect2(
	void	*ptr );

	extern
	void
Align4(
	void	**ptr );

	extern
	void*
AlignDirect4(
	void	*ptr );

	extern
	void
Align8(
	void	**ptr );

	extern
	void*
AlignDirect8(
	void	*ptr );

	extern
	void
Align16(
	void	**ptr );

	extern
	void*
AlignDirect16(
	void	*ptr );

	extern
	void
AlignX(
	void	**ptr,
	UInt32	alignment );

	extern
	void*
AlignXDirect(
	void	*ptr,
	UInt32	alignment );

	extern
	OSErr
NewAlignedPtr(
	UInt32	size,
	Boolean	fromSystemHeap,
	Boolean	clearMemory,
	UInt8	alignment,
	void	**ptr );

	extern
	Ptr
GetUnalignedPtr(
	void	*ptr );

	extern
	Boolean
IsAligned(
	void	*ptr,
	UInt8	alignment );

#ifdef	__cplusplus
}
#endif

/**************************
*	
*	DeclareAlignedVariable Macro
*	
**************************/
#pragma mark	-
#pragma mark	(DeclareAlignedVariable Macro)

#ifdef	__cplusplus
	#include	<new>
	#define	DeclareAlignedVariable( TYPE, NAME, ALIGNMENT )						\
				struct	Aligned##TYPE##NAME {									\
					Pad		padding[ ALIGNMENT ];								\
					char	value[sizeof(TYPE)];								\
				};																\
				struct Aligned##TYPE##NAME aligned##NAME;						\
				TYPE *NAME = (TYPE*) AlignXDirect( &aligned##NAME, ALIGNMENT );	\
				NAME = new ( NAME ) TYPE
#else
	#define	DeclareAlignedVariable( TYPE, NAME, ALIGNMENT )	\
				struct	Aligned##TYPE##NAME {				\
					Pad		padding[ ALIGNMENT ];			\
					TYPE	value;							\
				};											\
				struct Aligned##TYPE##NAME aligned##NAME;	\
				TYPE *NAME = (TYPE*) AlignXDirect( &aligned##NAME, ALIGNMENT )
#endif

/**************************
*	
*	ALIGN macro
*	
**************************/
#pragma mark	-
#pragma mark	(ALIGN macro)

#ifdef	__cplusplus
	#include	<new>
	#define		ALIGN( TYPE, NAME, ALIGNMENT )		\
		struct	Aligned##TYPE	{					\
			Pad##ALIGNMENT	padding;				\
			char			value[sizeof(TYPE)];	\
		};											\
		struct	Aligned##TYPE	aligned##NAME;		\
		TYPE					*NAME = (TYPE*) AlignDirect##ALIGNMENT( &aligned##NAME );	\
		NAME = new ( NAME ) TYPE
#else
	#define		ALIGN( TYPE, NAME, ALIGNMENT )	\
		struct	Aligned##TYPE	{				\
			Pad##ALIGNMENT	padding;			\
			TYPE			value;				\
		};										\
		struct	Aligned##TYPE	aligned##NAME;	\
		TYPE					*NAME = (TYPE*) AlignDirect##ALIGNMENT( &aligned##NAME )
#endif

#endif	//	_Align_



See more files for this project here

redshed

Code for Mac+WebObjects.

Project homepage: http://sourceforge.net/projects/redshed
Programming language(s): C,Java,Objective C
License: other

  Align.c
  Align.h
  Aligned.h