Changeset - r23683:f8c34c3a28f0
[Not reviewed]
master
0 1 0
Charles Pigott - 5 years ago 2019-04-22 21:57:55
charlespigott@googlemail.com
Remove: (Simple)TinyEnumT
1 file changed with 0 insertions and 104 deletions:
0 comments (0 inline, 0 general)
src/core/enum_type.hpp
Show inline comments
 
@@ -46,8 +46,6 @@
 
 *  we will create specialization derived from MakeEnumPropsT<>.
 
 *  i.e.:
 
 *    template <> struct EnumPropsT<Track> : MakeEnumPropsT<Track, byte, TRACK_BEGIN, TRACK_END, INVALID_TRACK> {};
 
 *  followed by:
 
 *    typedef TinyEnumT<Track> TrackByte;
 
 */
 
template <typename Tenum_t> struct EnumPropsT;
 

	
 
@@ -72,106 +70,4 @@ struct MakeEnumPropsT {
 
	static const uint num_bits = Tnum_bits;   ///< Number of bits for storing the enum in command parameters
 
};
 

	
 

	
 

	
 
/**
 
 * In some cases we use byte or uint16 to store values that are defined as enum. It is
 
 *  necessary in order to control the sizeof() such values. Some compilers make enum
 
 *  the same size as int (4 or 8 bytes instead of 1 or 2). As a consequence the strict
 
 *  compiler type - checking causes errors like:
 
 *     'HasPowerOnRail' : cannot convert parameter 1 from 'byte' to 'RailType' when
 
 *  u->u.rail.railtype is passed as argument or type RailType. In such cases it is better
 
 *  to teach the compiler that u->u.rail.railtype is to be treated as RailType.
 
 */
 
template <typename Tenum_t> struct TinyEnumT;
 

	
 
/** The general declaration of TinyEnumT<> (above) */
 
template <typename Tenum_t>
 
struct TinyEnumT {
 
	typedef Tenum_t enum_type;                      ///< expose our enumeration type (i.e. Trackdir) to outside
 
	typedef EnumPropsT<Tenum_t> Props;              ///< make easier access to our enumeration properties
 
	typedef typename Props::storage storage_type;   ///< small storage type
 
	static const enum_type begin = Props::begin;    ///< enum beginning (i.e. TRACKDIR_BEGIN)
 
	static const enum_type end = Props::end;        ///< enum end (i.e. TRACKDIR_END)
 
	static const enum_type invalid = Props::invalid;///< invalid value (i.e. INVALID_TRACKDIR)
 

	
 
	storage_type m_val;  ///< here we hold the actual value in small (i.e. byte) form
 

	
 
	/** Cast operator - invoked then the value is assigned to the Tenum_t type */
 
	inline operator enum_type () const
 
	{
 
		return (enum_type)m_val;
 
	}
 

	
 
	/** Assignment operator (from Tenum_t type) */
 
	inline TinyEnumT& operator = (enum_type e)
 
	{
 
		m_val = (storage_type)e;
 
		return *this;
 
	}
 

	
 
	/** Assignment operator (from Tenum_t type) */
 
	inline TinyEnumT& operator = (uint u)
 
	{
 
		m_val = (storage_type)u;
 
		return *this;
 
	}
 

	
 
	/** postfix ++ operator on tiny type */
 
	inline TinyEnumT operator ++ (int)
 
	{
 
		TinyEnumT org = *this;
 
		if (++m_val >= end) m_val -= (storage_type)(end - begin);
 
		return org;
 
	}
 

	
 
	/** prefix ++ operator on tiny type */
 
	inline TinyEnumT& operator ++ ()
 
	{
 
		if (++m_val >= end) m_val -= (storage_type)(end - begin);
 
		return *this;
 
	}
 
};
 

	
 

	
 
/** Template of struct holding enum types (on most archs, enums are stored in an int32). No math operators are provided. */
 
template <typename enum_type, typename storage_type>
 
struct SimpleTinyEnumT {
 
	storage_type m_val;  ///< here we hold the actual value in small (i.e. byte) form
 

	
 
	/** Cast operator - invoked then the value is assigned to the storage_type */
 
	inline operator enum_type () const
 
	{
 
		return (enum_type)this->m_val;
 
	}
 

	
 
	/** Assignment operator (from enum_type) */
 
	inline SimpleTinyEnumT &operator = (enum_type e)
 
	{
 
		this->m_val = (storage_type)e;
 
		return *this;
 
	}
 

	
 
	/** Assignment operator (from general uint) */
 
	inline SimpleTinyEnumT &operator = (uint u)
 
	{
 
		this->m_val = (storage_type)u;
 
		return *this;
 
	}
 

	
 
	/** Bit math (or) assignment operator (from enum_type) */
 
	inline SimpleTinyEnumT &operator |= (enum_type e)
 
	{
 
		this->m_val = (storage_type)((enum_type)this->m_val | e);
 
		return *this;
 
	}
 

	
 
	/** Bit math (and) assignment operator (from enum_type) */
 
	inline SimpleTinyEnumT &operator &= (enum_type e)
 
	{
 
		this->m_val = (storage_type)((enum_type)this->m_val & e);
 
		return *this;
 
	}
 
};
 

	
 
#endif /* ENUM_TYPE_HPP */
0 comments (0 inline, 0 general)