NAP
errorstate.h
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4 
5 #pragma once
6 
7 #include <utility/stringutils.h>
8 #include <vector>
9 #include <string>
10 
11 namespace nap
12 {
13  namespace utility
14  {
19  class ErrorState
20  {
21  public:
35  template<typename T>
36  bool check(bool successCondition, T&& errorMessage)
37  {
38  if (!successCondition)
39  mErrorList.emplace_back(std::forward<T>(errorMessage));
40  return successCondition;
41  }
42 
55  template <typename... Args>
56  bool check(bool successCondition, const char* format, Args&&... args)
57  {
58  return check(successCondition, stringFormat(format, std::forward<Args>(args)...));
59  }
60 
72  template<typename T>
73  void fail(T&& errorMessage)
74  {
75  mErrorList.emplace_back(std::forward<T>(errorMessage));
76  }
77 
89  template <typename... Args>
90  void fail(const char* format, Args&&... args)
91  {
92  fail(stringFormat(format, std::forward<Args>(args)...));
93  }
94 
99  const std::string toString() const;
100 
104  bool hasErrors() const { return !mErrorList.empty(); }
105 
106  private:
107  std::vector<std::string> mErrorList;
108  };
109 
110  }
111 }
nap::utility::ErrorState::check
bool check(bool successCondition, const char *format, Args &&... args)
Definition: errorstate.h:56
nap::utility::ErrorState::check
bool check(bool successCondition, T &&errorMessage)
Definition: errorstate.h:36
nap::utility::ErrorState
Definition: errorstate.h:19
nap::utility::ErrorState::fail
void fail(const char *format, Args &&... args)
Definition: errorstate.h:90
nap::utility::ErrorState::fail
void fail(T &&errorMessage)
Definition: errorstate.h:73
nap::utility::ErrorState::toString
const std::string toString() const
nap::utility::stringFormat
std::string stringFormat(const char *format, Args &&... args)
Definition: stringutils.h:259
nap::utility::ErrorState::hasErrors
bool hasErrors() const
Definition: errorstate.h:104
nap
Definition: templateapp.h:17