libfoedus-core
FOEDUS Core Library
error_stack_batch.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2015, Hewlett-Packard Development Company, LP.
3  * This program is free software; you can redistribute it and/or modify it
4  * under the terms of the GNU General Public License as published by the Free
5  * Software Foundation; either version 2 of the License, or (at your option)
6  * any later version.
7  *
8  * This program is distributed in the hope that it will be useful, but WITHOUT
9  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11  * more details. You should have received a copy of the GNU General Public
12  * License along with this program; if not, write to the Free Software
13  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14  *
15  * HP designates this particular file as subject to the "Classpath" exception
16  * as provided by HP in the LICENSE.txt file that accompanied this code.
17  */
18 #ifndef FOEDUS_ERROR_STACK_BATCH_HPP_
19 #define FOEDUS_ERROR_STACK_BATCH_HPP_
20 #include <iosfwd>
21 #include <vector>
22 
23 #include "foedus/cxx11.hpp"
24 #include "foedus/error_stack.hpp"
25 
26 namespace foedus {
35  public:
38  ErrorStackBatch(const ErrorStackBatch &other) : error_batch_(other.error_batch_) {}
39 
42  error_batch_ = other.error_batch_;
43  return *this;
44  }
45 
46 #ifndef DISABLE_CXX11_IN_PUBLIC_HEADERS
47 
53  error_batch_ = std::move(other.error_batch_);
54  }
55 
61  error_batch_ = std::move(other.error_batch_);
62  return *this;
63  }
64 #endif // DISABLE_CXX11_IN_PUBLIC_HEADERS
65 
66  void clear() { error_batch_.clear(); }
67 
71  void push_back(const ErrorStack &error_stack) {
72  if (!error_stack.is_error()) {
73  return;
74  }
75  error_batch_.push_back(error_stack);
76  }
77 
78 #ifndef DISABLE_CXX11_IN_PUBLIC_HEADERS
79 
83  void emprace_back(ErrorStack &&error_stack) {
84  if (!error_stack.is_error()) {
85  return;
86  }
87  error_batch_.emplace_back(error_stack);
88  }
89 #endif // DISABLE_CXX11_IN_PUBLIC_HEADERS
90 
92  bool is_error() const { return !error_batch_.empty(); }
93 
98  template<class T>
99  void uninitialize_and_delete_all(std::vector< T* > *vec) {
100  while (!vec->empty()) {
101  if (vec->back()->is_initialized()) {
102 #ifndef DISABLE_CXX11_IN_PUBLIC_HEADERS
103  emprace_back(vec->back()->uninitialize());
104 #else // DISABLE_CXX11_IN_PUBLIC_HEADERS
105  push_back(vec->back()->uninitialize());
106 #endif // DISABLE_CXX11_IN_PUBLIC_HEADERS
107  }
108  delete vec->back();
109  vec->pop_back();
110  }
111  }
112 
117  ErrorStack summarize(const char* filename, const char* func, uint32_t linenum) const;
118 
119  friend std::ostream& operator<<(std::ostream& o, const ErrorStackBatch& obj);
120 
121  private:
125  std::vector<ErrorStack> error_batch_;
126 };
127 } // namespace foedus
128 
136 #define SUMMARIZE_ERROR_BATCH(x) x.summarize(__FILE__, __FUNCTION__, __LINE__)
137 
138 #endif // FOEDUS_ERROR_STACK_BATCH_HPP_
ErrorStackBatch & operator=(ErrorStackBatch &&other)
Move assignment that steals the internal std::vector without copying.
void emprace_back(ErrorStack &&error_stack)
If the given ErrorStack is an error, this method adds it to the end of this batch.
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
friend std::ostream & operator<<(std::ostream &o, const ErrorStackBatch &obj)
Brings error stacktrace information as return value of functions.
Definition: error_stack.hpp:81
ErrorStackBatch & operator=(const ErrorStackBatch &other)
Non-move assignment.
ErrorStackBatch(const ErrorStackBatch &other)
Non-move copy constructor.
Batches zero or more ErrorStack objects to represent in one ErrorStack.
ErrorStack summarize(const char *filename, const char *func, uint32_t linenum) const
Instantiate an ErrorStack object that summarizes all errors in this batch.
ErrorStackBatch(ErrorStackBatch &&other)
Move constructor that steals the internal std::vector without copying.
bool is_error() const
Returns whether there was any error.
void uninitialize_and_delete_all(std::vector< T * > *vec)
A convenience method to uninitialize and delete all Initializable objects in a vector, storing all errors in this batch.
void push_back(const ErrorStack &error_stack)
If the given ErrorStack is an error, this method adds it to the end of this batch.
bool is_error() const
Returns if this return code is not kErrorCodeOk.