multovl  1.3
Multiple overlaps of genomic regions
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
errors.hh
1 /* <LICENSE>
2 License for the MULTOVL multiple genomic overlap tools
3 
4 Copyright (c) 2007-2012, Dr Andras Aszodi,
5 Campus Science Support Facilities GmbH (CSF),
6 Dr-Bohr-Gasse 3, A-1030 Vienna, Austria, Europe.
7 All rights reserved.
8 
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are
11 met:
12 
13  * Redistributions of source code must retain the above copyright notice,
14  this list of conditions and the following disclaimer.
15  * Redistributions in binary form must reproduce the above copyright notice,
16  this list of conditions and the following disclaimer in the documentation
17  and/or other materials provided with the distribution.
18  * Neither the name of the Campus Science Support Facilities GmbH
19  nor the names of its contributors may be used to endorse
20  or promote products derived from this software without specific prior
21  written permission.
22 
23 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
24 AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
25 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
26 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
27 THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
30 USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
31 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 </LICENSE> */
35 #ifndef MULTOVL_ERRORS_HEADER
36 #define MULTOVL_ERRORS_HEADER
37 
38 // == Header errors.hh ==
39 
40 // -- Standard headers --
41 
42 #include <string>
43 #include <vector>
44 #include <iostream>
45 
46 namespace multovl {
47 
49 class Errors
50 {
51 public:
52 
56  explicit Errors(
57  const std::string& errprefix = "ERROR",
58  const std::string& warnprefix = "WARNING"
59  );
60 
63  void add_error(const std::string& msg);
64 
67  void add_warning(const std::string& msg);
68 
72  Errors& operator+=(const Errors& another);
73 
75  unsigned int error_count() const { return _errors.size(); }
76 
78  unsigned int warning_count() const { return _warnings.size(); }
79 
81  bool ok() const { return (error_count() == 0); }
82 
84  bool perfect() const { return (error_count() + warning_count() == 0); }
85 
87  std::string last_error() const { return (ok()? "" : _errors.back()); }
88 
92  std::ostream& print(std::ostream& outf, bool warnings=true) const;
93 
95  void clear();
96 
97 private:
98 
99  std::vector<std::string> _errors, _warnings;
100  std::string _errprefix, _warnprefix;
101 };
102 
103 } // namespace multovl
104 
105 #endif // MULTOVL_ERRORS_HEADER
void add_error(const std::string &msg)
void clear()
Tell the calling object to forget all errors and warnings seen so far.
void add_warning(const std::string &msg)
unsigned int error_count() const
Definition: errors.hh:75
Errors & operator+=(const Errors &another)
bool ok() const
Definition: errors.hh:81
unsigned int warning_count() const
Definition: errors.hh:78
std::ostream & print(std::ostream &outf, bool warnings=true) const
bool perfect() const
Definition: errors.hh:84
Errors(const std::string &errprefix="ERROR", const std::string &warnprefix="WARNING")
Simple facility to keep track of errors and warnings.
Definition: errors.hh:49
std::string last_error() const
Definition: errors.hh:87