Browse Source

Trade: cut Type enum out of AbstractMaterialData class.

Now named MaterialType. It's easier to type this:

    auto t = Trade::MaterialType::Phong;

Than this overlong name, which is moreover ambiguous due to subclassing:

    auto t = Trade::AbstractMaterialData::Type::Phong;
        // or should I use rather Trade::PhongMaterialData::Type::Phong?
pull/23/head
Vladimír Vondruš 13 years ago
parent
commit
b1bfdbbc86
  1. 8
      src/Trade/AbstractMaterialData.cpp
  2. 24
      src/Trade/AbstractMaterialData.h
  3. 2
      src/Trade/PhongMaterialData.h
  4. 4
      src/Trade/Test/AbstractMaterialDataTest.cpp

8
src/Trade/AbstractMaterialData.cpp

@ -28,18 +28,18 @@
namespace Magnum { namespace Trade {
AbstractMaterialData::AbstractMaterialData(Type type): _type(type) {}
AbstractMaterialData::AbstractMaterialData(MaterialType type): _type(type) {}
AbstractMaterialData::~AbstractMaterialData() {}
Debug operator<<(Debug debug, const AbstractMaterialData::Type value) {
Debug operator<<(Debug debug, const MaterialType value) {
switch(value) {
#define _c(value) case AbstractMaterialData::Type::value: return debug << "Trade::AbstractMaterialData::Type::" #value;
#define _c(value) case MaterialType::value: return debug << "Trade::MaterialType::" #value;
_c(Phong)
#undef _c
}
return debug << "Trade::AbstractMaterialData::Type::(unknown)";
return debug << "Trade::MaterialType::(unknown)";
}
}}

24
src/Trade/AbstractMaterialData.h

@ -25,7 +25,7 @@
*/
/** @file
* @brief Class Magnum::Trade::AbstractMaterialData
* @brief Class @ref Magnum::Trade::AbstractMaterialData, enum @ref Magnum::Trade::MaterialType
*/
#include "magnumVisibility.h"
@ -33,6 +33,15 @@
namespace Magnum { namespace Trade {
/**
@brief Material type
@see @ref AbstractMaterialData::type()
*/
enum class MaterialType: UnsignedByte {
Phong /**< Phong shading */
};
/**
@brief Base for material data
@ -40,16 +49,11 @@ Subclasses provide access to parameters for given material type.
*/
class MAGNUM_EXPORT AbstractMaterialData {
public:
/** @brief Material type */
enum class Type: UnsignedByte {
Phong /**< Phong shading */
};
/**
* @brief Constructor
* @param type Material type
*/
explicit AbstractMaterialData(Type type);
explicit AbstractMaterialData(MaterialType type);
/** @brief Destructor */
virtual ~AbstractMaterialData() = 0;
@ -67,14 +71,14 @@ class MAGNUM_EXPORT AbstractMaterialData {
AbstractMaterialData& operator=(AbstractMaterialData&&) = default;
/** @brief Material type */
Type type() const { return _type; }
MaterialType type() const { return _type; }
private:
Type _type;
MaterialType _type;
};
/** @debugoperator{Magnum::Trade::AbstractMaterialData} */
Debug MAGNUM_EXPORT operator<<(Debug debug, AbstractMaterialData::Type value);
Debug MAGNUM_EXPORT operator<<(Debug debug, MaterialType value);
}}

2
src/Trade/PhongMaterialData.h

@ -71,7 +71,7 @@ class MAGNUM_EXPORT PhongMaterialData: public AbstractMaterialData {
* Colors and textures should be specified using member functions based
* on what flags are set.
*/
explicit PhongMaterialData(Flags flags, Float shininess): AbstractMaterialData(Type::Phong), _shininess(shininess), _flags(flags) {}
explicit PhongMaterialData(Flags flags, Float shininess): AbstractMaterialData(MaterialType::Phong), _shininess(shininess), _flags(flags) {}
/** @brief Material flags */
Flags flags() const { return _flags; }

4
src/Trade/Test/AbstractMaterialDataTest.cpp

@ -43,8 +43,8 @@ AbstractMaterialDataTest::AbstractMaterialDataTest() {
void AbstractMaterialDataTest::debug() {
std::ostringstream out;
Debug(&out) << AbstractMaterialData::Type::Phong;
CORRADE_COMPARE(out.str(), "Trade::AbstractMaterialData::Type::Phong\n");
Debug(&out) << MaterialType::Phong;
CORRADE_COMPARE(out.str(), "Trade::MaterialType::Phong\n");
}
}}}

Loading…
Cancel
Save