libfoedus-core
FOEDUS Core Library
foedus::ErrorStackBatch Class Reference

Batches zero or more ErrorStack objects to represent in one ErrorStack. More...

Detailed Description

Batches zero or more ErrorStack objects to represent in one ErrorStack.

This batching is useful in a context that might observe multiple errors while it can return only one ErrorStack object; e.g., Initializable::uninitialize().

Definition at line 34 of file error_stack_batch.hpp.

#include <error_stack_batch.hpp>

Public Member Functions

 ErrorStackBatch ()
 
 ErrorStackBatch (const ErrorStackBatch &other)
 Non-move copy constructor. More...
 
ErrorStackBatchoperator= (const ErrorStackBatch &other)
 Non-move assignment. More...
 
 ErrorStackBatch (ErrorStackBatch &&other)
 Move constructor that steals the internal std::vector without copying. More...
 
ErrorStackBatchoperator= (ErrorStackBatch &&other)
 Move assignment that steals the internal std::vector without copying. More...
 
void clear ()
 
void push_back (const ErrorStack &error_stack)
 If the given ErrorStack is an error, this method adds it to the end of this batch. More...
 
void emprace_back (ErrorStack &&error_stack)
 If the given ErrorStack is an error, this method adds it to the end of this batch. More...
 
bool is_error () const
 Returns whether there was any error. More...
 
template<class T >
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. More...
 
ErrorStack summarize (const char *filename, const char *func, uint32_t linenum) const
 Instantiate an ErrorStack object that summarizes all errors in this batch. More...
 

Friends

std::ostream & operator<< (std::ostream &o, const ErrorStackBatch &obj)
 

Constructor & Destructor Documentation

foedus::ErrorStackBatch::ErrorStackBatch ( )
inline

Definition at line 36 of file error_stack_batch.hpp.

36 {}
foedus::ErrorStackBatch::ErrorStackBatch ( const ErrorStackBatch other)
inline

Non-move copy constructor.

Definition at line 38 of file error_stack_batch.hpp.

38 : error_batch_(other.error_batch_) {}
foedus::ErrorStackBatch::ErrorStackBatch ( ErrorStackBatch &&  other)
inline

Move constructor that steals the internal std::vector without copying.

This is more efficient than non-move copy constructor, but provided only when C++11 is supported.

Definition at line 52 of file error_stack_batch.hpp.

52  {
53  error_batch_ = std::move(other.error_batch_);
54  }

Member Function Documentation

void foedus::ErrorStackBatch::clear ( )
inline

Definition at line 66 of file error_stack_batch.hpp.

66 { error_batch_.clear(); }
void foedus::ErrorStackBatch::emprace_back ( ErrorStack &&  error_stack)
inline
bool foedus::ErrorStackBatch::is_error ( ) const
inline

Returns whether there was any error.

Definition at line 92 of file error_stack_batch.hpp.

Referenced by summarize().

92 { return !error_batch_.empty(); }

Here is the caller graph for this function:

ErrorStackBatch& foedus::ErrorStackBatch::operator= ( const ErrorStackBatch other)
inline

Non-move assignment.

Definition at line 41 of file error_stack_batch.hpp.

41  {
42  error_batch_ = other.error_batch_;
43  return *this;
44  }
ErrorStackBatch& foedus::ErrorStackBatch::operator= ( ErrorStackBatch &&  other)
inline

Move assignment that steals the internal std::vector without copying.

This is more efficient, but provided only when C++11 is supported.

Definition at line 60 of file error_stack_batch.hpp.

60  {
61  error_batch_ = std::move(other.error_batch_);
62  return *this;
63  }
void foedus::ErrorStackBatch::push_back ( const ErrorStack error_stack)
inline

If the given ErrorStack is an error, this method adds it to the end of this batch.

Definition at line 71 of file error_stack_batch.hpp.

References foedus::ErrorStack::is_error().

Referenced by uninitialize_and_delete_all().

71  {
72  if (!error_stack.is_error()) {
73  return;
74  }
75  error_batch_.push_back(error_stack);
76  }

Here is the call graph for this function:

Here is the caller graph for this function:

ErrorStack foedus::ErrorStackBatch::summarize ( const char *  filename,
const char *  func,
uint32_t  linenum 
) const

Instantiate an ErrorStack object that summarizes all errors in this batch.

Consider using SUMMARIZE_ERROR_BATCH(batch).

Definition at line 24 of file error_stack_batch.cpp.

References is_error(), foedus::kErrorCodeBatchedError, and foedus::kRetOk.

25  {
26  if (!is_error()) {
27  return kRetOk;
28  } else if (error_batch_.size() == 1) {
29  return error_batch_[0];
30  } else {
31  // there were multiple errors. we must batch them.
32  std::stringstream message;
33  for (size_t i = 0; i < error_batch_.size(); ++i) {
34  if (i > 0) {
35  message << std::endl;
36  }
37  message << "Error[" << i << "]:" << error_batch_[i];
38  }
39  return ErrorStack(filename, func, linenum, kErrorCodeBatchedError, message.str().c_str());
40  }
41 }
0x0004 : "GENERAL: More than one errors observed" .
Definition: error_code.hpp:108
bool is_error() const
Returns whether there was any error.
const ErrorStack kRetOk
Normal return value for no-error case.

Here is the call graph for this function:

template<class T >
void foedus::ErrorStackBatch::uninitialize_and_delete_all ( std::vector< T * > *  vec)
inline

A convenience method to uninitialize and delete all Initializable objects in a vector, storing all errors in this batch.

Definition at line 99 of file error_stack_batch.hpp.

References emprace_back(), and push_back().

Referenced by foedus::thread::ThreadGroup::uninitialize_once(), foedus::memory::NumaNodeMemory::uninitialize_once(), and foedus::log::LogManagerPimpl::uninitialize_once().

99  {
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  }
void emprace_back(ErrorStack &&error_stack)
If the given ErrorStack is an error, this method adds it to the end of 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.

Here is the call graph for this function:

Here is the caller graph for this function:

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  o,
const ErrorStackBatch obj 
)
friend

Definition at line 43 of file error_stack_batch.cpp.

43  {
44  o << SUMMARIZE_ERROR_BATCH(obj);
45  return o;
46 }
#define SUMMARIZE_ERROR_BATCH(x)
This macro calls ErrorStackBatch::summarize() with automatically provided parameters.

The documentation for this class was generated from the following files: