Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Result.h 1.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //
  2. // Created by robin on 8/9/15.
  3. //
  4. #ifndef RESULT_H
  5. #define RESULT_H
  6. # include <string>
  7. # include <vector>
  8. # include <iostream>
  9. template <class T> class Result
  10. {
  11. public:
  12. static const Result<T> ok(const T& data);
  13. static const Result<T> strerror();
  14. static const Result<T> error(const std::string& error);
  15. template <class U> static const Result<T> error(const Result<U>& other);
  16. T& getData();
  17. const bool isSuccess() const;
  18. const std::string& getError() const;
  19. bool operator !() const;
  20. operator bool() const;
  21. template<class U>
  22. friend std::ostream& operator<<(std::ostream& os, const Result<U>& res);
  23. const Result<T>& print() const;
  24. private:
  25. Result();
  26. T _data;
  27. std::string _error;
  28. bool _success;
  29. };
  30. typedef Result<bool> ResultBool;
  31. typedef Result<int> ResultInt;
  32. typedef Result<long> ResultLong;
  33. typedef Result<float> ResultFloat;
  34. typedef Result<double> ResultDouble;
  35. typedef Result<char> ResultChar;
  36. typedef Result<std::string> ResultString;
  37. # include "DBO/Result.hxx"
  38. #endif //RESULT_H