galdar496 / QiGameEngine

Realtime Game Engine designed with C++ and OpenGL.
http://qiengine.blogspot.com/
1 stars 0 forks source link

Create a return code to use for pretty much all functions that don't return a void as a status #25

Closed galdar496 closed 9 years ago

galdar496 commented 9 years ago
struct ReturnCode
{
   bool IsValid() const { return m_errorCode == 0; }
   ....
   uint32 m_errorCode;
};

each module can define its own error codes in some kind of large enum

galdar496 commented 9 years ago

The reasoning behind this is for code readability. Right now in the engine, either true or false is returned for many things. This is alright but doesn't really allow the calling code to make real decisions based on what happened (e.g. it failed but for a specific reason that we might be able to fix). Using an object like this will help with readability as well. Instead of the user saying, "is < 0 a pass or is 0 a pass" or whatever like you have to do with the C standard lib, you can just query they object with IsValid() and if it isn't, the error code can be checked and handled accordingly.

galdar496 commented 9 years ago
enum class ErrorCode
{
   kSuccess = 0,
};

struct Qi::Result
{
   public:

      bool IsValid() const { errorCode == Qi::kSuccess; }

      Qi::ErrorCode errorCode;
};

The ErrorCode enum could probably be made with some sweet X macro stuff but that might complicate things for an end user, have to think about developer ease vs. user ease.

galdar496 commented 9 years ago

8b94e66f4034b2178b393659b1d0135ccf1f09ad