libfoedus-core
FOEDUS Core Library
fixed_error_stack.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_FIXED_ERROR_STACK_HPP_
19 #define FOEDUS_FIXED_ERROR_STACK_HPP_
20 
21 #include <stdint.h>
22 
23 #include <iosfwd>
24 
25 #include "foedus/assert_nd.hpp"
26 #include "foedus/cxx11.hpp"
27 #include "foedus/error_stack.hpp"
29 
30 namespace foedus {
31 
42  public:
46 
48  FixedErrorStack() : os_errno_(0), error_code_(kErrorCodeOk), stack_depth_(0) {}
50  explicit FixedErrorStack(const ErrorStack& src) { operator=(src); }
51 
54 
56  bool is_error() const { return error_code_ != kErrorCodeOk; }
57 
59  ErrorCode get_error_code() const { return error_code_; }
60 
62  const char* get_message() const { return get_error_message(error_code_); }
63 
65  const FixedErrorMessage& get_custom_message() const { return custom_message_; }
66 
68  uint16_t get_stack_depth() const { return stack_depth_; }
69 
71  uint32_t get_linenum(uint16_t stack_index) const {
72  ASSERT_ND(stack_index < stack_depth_);
73  return linenums_[stack_index];
74  }
75 
77  const FixedFileName& get_filename(uint16_t stack_index) const {
78  ASSERT_ND(stack_index < stack_depth_);
79  return filenames_[stack_index];
80  }
81 
83  const FixedFuncName& get_func(uint16_t stack_index) const {
84  ASSERT_ND(stack_index < stack_depth_);
85  return funcs_[stack_index];
86  }
87 
89  void output(std::ostream* ptr) const;
90 
91  void clear() { error_code_ = kErrorCodeOk; }
92 
98  ErrorStack to_error_stack() const;
99 
101  void from_error_stack(const ErrorStack& other);
102 
103  friend std::ostream& operator<<(std::ostream& o, const FixedErrorStack& obj);
104 
105  private:
107  FixedFileName filenames_[ErrorStack::kMaxStackDepth];
108 
110  FixedFuncName funcs_[ErrorStack::kMaxStackDepth];
111 
113  uint32_t linenums_[ErrorStack::kMaxStackDepth];
114 
116  FixedErrorMessage custom_message_;
117 
119  int os_errno_;
120 
122  ErrorCode error_code_;
123 
125  uint16_t stack_depth_;
126 };
127 
128 } // namespace foedus
129 #endif // FOEDUS_FIXED_ERROR_STACK_HPP_
FixedErrorStack(const ErrorStack &src)
Copy the content of the given ErrorStack.
const FixedFuncName & get_func(uint16_t stack_index) const
Returns the function name of the given stack position.
Root package of FOEDUS (Fast Optimistic Engine for Data Unification Services).
Definition: assert_nd.hpp:44
uint16_t get_stack_depth() const
Returns the depth of stack this error code has collected.
Brings error stacktrace information as return value of functions.
Definition: error_stack.hpp:81
assorted::FixedString< 124 > FixedFileName
FixedErrorStack()
Empty constructor.
bool is_error() const
Returns if this return code is not kErrorCodeOk.
0 means no-error.
Definition: error_code.hpp:87
assorted::FixedString< 508 > FixedErrorMessage
FixedErrorStack & operator=(const ErrorStack &src)
Assignment operator.
assorted::FixedString< 124 > FixedFuncName
ErrorStack to_error_stack() const
Instantiates an ErrorStack object based on this object.
void output(std::ostream *ptr) const
Describe this object to the given stream.
Maximum stack trace depth.
Definition: error_stack.hpp:86
const char * get_message() const
Returns the error message inferred by the error code.
Representation of ErrorStack that can be copied to other processes and even serialized to files...
friend std::ostream & operator<<(std::ostream &o, const FixedErrorStack &obj)
const FixedFileName & get_filename(uint16_t stack_index) const
Returns the file name of the given stack position.
uint32_t get_linenum(uint16_t stack_index) const
Returns the line number of the given stack position.
const char * get_error_message(ErrorCode code)
Returns the error messages corresponding to ErrorCode enum defined in error_code.xmacro.
Definition: error_code.hpp:120
ErrorCode get_error_code() const
Return the integer error code.
const FixedErrorMessage & get_custom_message() const
Returns the custom error message.
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...
Definition: assert_nd.hpp:72
void from_error_stack(const ErrorStack &other)
Convert ErrorStack to this object.
ErrorCode
Enum of error codes defined in error_code.xmacro.
Definition: error_code.hpp:85