featureSet.h

Engine/source/shaderGen/featureSet.h

More...

Classes:

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _FEATURESET_H_
 25#define _FEATURESET_H_
 26
 27#ifndef _TORQUE_STRING_H_
 28#include "core/util/str.h"
 29#endif
 30#ifndef _TVECTOR_H_
 31#include "core/util/tVector.h"
 32#endif
 33
 34class FeatureType;
 35
 36
 37//
 38class FeatureSet
 39{
 40protected:
 41
 42   struct FeatureInfo
 43   {      
 44      const FeatureType* type;
 45      S32 index;
 46   };
 47
 48   /// The list of featurs.   
 49   Vector<FeatureInfo> mFeatures;
 50
 51   /// A string representation of all the 
 52   /// features used for comparisons.
 53   String mDescription;
 54
 55   ///
 56   static S32 _typeCmp( const FeatureInfo* a, const FeatureInfo *b );
 57
 58   ///
 59   void _rebuildDesc();
 60
 61public:
 62
 63   FeatureSet()
 64   {
 65   }
 66
 67   FeatureSet( const FeatureSet &h )
 68      :  mFeatures( h.mFeatures ),
 69         mDescription( h.mDescription ) 
 70   {
 71   }
 72
 73   FeatureSet& operator=( const FeatureSet &h );
 74
 75   /// Equality operators.
 76   inline bool operator !=( const FeatureSet &h ) const { return h.getDescription() != getDescription(); }
 77   inline bool operator ==( const FeatureSet &h ) const { return h.getDescription() == getDescription(); }
 78
 79   bool operator []( const FeatureType &type ) const { return hasFeature( type ); }
 80
 81   /// Returns true if the feature set is empty.
 82   bool isEmpty() const { return mFeatures.empty(); }
 83
 84   /// Returns true if the feature set is not empty.
 85   bool isNotEmpty() const { return !mFeatures.empty(); }
 86
 87   /// Return the description string which uniquely identifies this feature set.
 88   const String& getDescription() const;
 89
 90   /// Returns the feature count.
 91   U32 getCount() const { return mFeatures.size(); }
 92
 93   /// Returns the feature at the index and optionally
 94   /// the feature index when it was added.
 95   const FeatureType& getAt( U32 index, S32 *outIndex = NULL ) const;
 96
 97   /// Returns true if this handle has this feature.
 98   bool hasFeature( const FeatureType &type, S32 index = -1 ) const;
 99
100   /// 
101   void setFeature( const FeatureType &type, bool set, S32 index = -1 );
102
103   /// 
104   void addFeature( const FeatureType &type, S32 index = -1 );
105
106   /// 
107   void removeFeature( const FeatureType &type );
108
109   ///
110   S32 getNextFeatureIndex( const FeatureType &type, S32 index ) const;
111
112   /// Removes features that are not in the input set.
113   void filter( const FeatureSet &features );
114
115   /// Removes features that are in the input set.
116   void exclude( const FeatureSet &features );
117
118   ///
119   void merge( const FeatureSet &features );
120
121   /// Clears all features.
122   void clear();
123
124   /// Default empty feature set.
125   static const FeatureSet EmptySet;
126
127};
128
129
130inline const String& FeatureSet::getDescription() const
131{
132   // Update the description if its empty and we have features.
133   if ( mDescription.isEmpty() && !mFeatures.empty() )
134      const_cast<FeatureSet*>(this)->_rebuildDesc();
135   
136   return mDescription;
137}
138
139#endif // _FEATURESET_H_
140