/*
....[@@@..[@@@..............[@.................. MUD++ is a written from
....[@..[@..[@..[@..[@..[@@@@@....[@......[@.... scratch multi-user swords and
....[@..[@..[@..[@..[@..[@..[@..[@@@@@..[@@@@@.. sorcery game written in C++.
....[@......[@..[@..[@..[@..[@....[@......[@.... This server is an ongoing
....[@......[@..[@@@@@..[@@@@@.................. development project.  All 
................................................ contributions are welcome. 
....Copyright(C).1995.Melvin.Smith.............. Enjoy. 
------------------------------------------------------------------------------
Melvin Smith (aka Fusion)         msmith@falcon.mercer.peachnet.edu 
MUD++ development mailing list    mudpp-list@spice.com
------------------------------------------------------------------------------
bit.h
*/

#ifndef _BIT_H
#define _BIT_H
#include <string.h>

#define BIT( num ) ( 1 << num )

struct bitType
{
	const char *name;
	int val;
};


inline void SET_BIT( unsigned long flags[], int bit )
{
	flags[bit / 32] |=  ( 1 << ( bit % 32 ) );
}

inline void CLEAR_BIT( unsigned long flags[], int bit )
{
	flags[bit / 32] &= ~( 1 << ( bit % 32 ) );
}

inline int IS_SET( const unsigned long flags[], int bit )
{
	return flags[bit / 32] &   ( 1 << ( bit % 32 ) );
}

inline void TOGGLE_BIT( unsigned long flags[], int bit )
{
	flags[bit / 32] ^=  ( 1 << ( bit % 32 ) );
}

const int NULLBIT		= 0;    // First bit unused in all bit fields.


inline const char * getBitName( const bitType bit_list[], int val )
{
	for( int i = 1; bit_list[i].name; i++ )
	{
		if( val == bit_list[i].val )
			return bit_list[i].name;
	}

	return "";
}


inline int getBit( const bitType bit_list[], const char * name )
{
	int len = strlen( name );

	for( int i = 1; bit_list[i].name; i++ )
	{
		if( *name != *bit_list[i].name )
			continue;

		if( !strncmp( name, bit_list[i].name, len ) )
			return bit_list[i].val;
	}

	return NULLBIT;
}

#endif