Sfoglia il codice sorgente

base: port all existing codebase to safe enums where absolutely required.

undefined
Sam Hocevar 10 anni fa
parent
commit
99db2f0c11
3 ha cambiato i file con 12 aggiunte e 20 eliminazioni
  1. +2
    -2
      src/light.h
  2. +5
    -10
      src/lol/math/geometry.h
  3. +5
    -8
      src/utils.h

+ 2
- 2
src/light.h Vedi File

@@ -34,9 +34,9 @@ struct LightType
}
m_value;

static char const *GetName(Value v)
String ToString()
{
switch (v)
switch (m_value)
{
case Directional:
return "<Directional>";


+ 5
- 10
src/lol/math/geometry.h Vedi File

@@ -296,16 +296,11 @@ bool TestRayVsPlane(const TV &ray_p0, const TV &ray_p1,
}

/* A safe enum for Primitive edge face. */
struct PlaneIntersection
{
DEF_VALUE
ADD_VALUE(Back)
ADD_VALUE(Front)
ADD_VALUE(Plane)
END_E_VALUE

LOL_DECLARE_ENUM_METHODS(PlaneIntersection)
};
LOL_SAFE_ENUM(PlaneIntersection,
Back,
Front,
Plane,
);

//Point/Plane : Normal must be given normalized.
template <typename TV>


+ 5
- 8
src/utils.h Vedi File

@@ -59,19 +59,16 @@ template< class T > inline int GetRandom(Array<T> src)
return (r_total > .0f)?(r_j):(-1);
}

//Gets the value for the given safe-enum, considering you have implemented what follows :
//NEEDS : Contructor(Value)
//NEEDS : static char const *GetName(Value v)
//NEEDS : T::Max
template< class T > inline T FindValue(const char* name)
// Gets the value for the given LOL_SAFE_ENUM type.
template<class T> inline T FindValue(const char* name)
{
String n = name;
n.ToLower();
for (int i = 0; i < T::Max; ++i)
{
String s = T::GetName(typename T::Value(i));
if (s.ToLower().IndexOf(n.C()) > -1)
return T(typename T::Value(i));
String s = T(i).ToString().ToLower();
if (s == n)
return T(i);
}
return T::Max;
}


Caricamento…
Annulla
Salva