You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Result.hxx 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // Created by robin on 8/9/15.
  3. //
  4. #include <iostream>
  5. #include "Result.h"
  6. template<class T>
  7. Result<T>::Result()
  8. {
  9. }
  10. template<class T>
  11. Result<T>::Result(const T &data)
  12. : _data(data)
  13. {
  14. }
  15. template<class T>
  16. Result<T>::~Result()
  17. {
  18. }
  19. template<class T>
  20. Result<T> &Result<T>::ok(const T &data)
  21. {
  22. _data = data;
  23. return *this;
  24. }
  25. template<class T>
  26. T &Result<T>::getData()
  27. {
  28. return _data;
  29. }
  30. template<class T>
  31. bool Result<T>::isSuccess() const
  32. {
  33. return _error.empty();
  34. }
  35. template<class T>
  36. const std::vector<std::string>& Result<T>::getWarnings() const
  37. {
  38. return _warnings;
  39. }
  40. template<class T>
  41. Result<T>& Result<T>::addWarning(const std::string &warning)
  42. {
  43. _warnings.push_back(warning);
  44. return *this;
  45. }
  46. template<class T>
  47. bool Result<T>::operator!() const
  48. {
  49. return !isSuccess();
  50. }
  51. template<class T>
  52. Result<T>::operator bool() const
  53. {
  54. return isSuccess();
  55. }
  56. template<class T>
  57. Result<T> &Result<T>::error(const std::string &error)
  58. {
  59. _error = error;
  60. return *this;
  61. }
  62. template<class T>
  63. const std::string &Result<T>::getError() const
  64. {
  65. return _error;
  66. }
  67. template<class T>
  68. const Result<T>& Result<T>::print() const
  69. {
  70. for (auto warning : _warnings)
  71. std::cerr << "WARNING: " << warning << std::endl;
  72. if (!isSuccess())
  73. std::cerr << "ERROR: " << _error << std::endl;
  74. return *this;
  75. }