BOSS 7.0.3
BESIII Offline Software System
Loading...
Searching...
No Matches
InstallArea/include/TrkBase/TrkBase/TrkErrCode.h
Go to the documentation of this file.
1//--------------------------------------------------------------------------
2// File and Version Information:
3// $Id: TrkErrCode.h,v 1.1.1.1 2005/04/21 06:01:42 zhangy Exp $
4//
5// Description:
6// Encapsulate error/success status of tracking operations.
7// Either failure() or success() will be non-zero, but not both.
8// Failure => no valid answer available.
9// Success => a valid answer has been
10// provided, even if it wasn't exactly what you asked for. The
11// value of failure() or success() distinguishes different
12// failure/success modes. A string describing the success/failure
13// mode can also be provided, and printed by the user.
14//
15// Note that if this string is provided by the called function,
16// it _must_ be a pointer to a statically stored string (which includes
17// string literals). E.g.
18// TrkErrCode err;
19// err.setFailure(10,"Forgot to tie my shoelaces.");
20// return err;
21// is valid.
22//
23// Several codes have predefined meanings and strings; strings
24// supplied for them will be ignored. Strings for codes >= 10
25// can be supplied by users. Predefined:
26// failure = 1 -- "Arithmetic error."
27// = 2 -- "Failed to converge."
28// = 3 -- "Failed because parallel."
29// = 4-9 -- reserved until I think of some more standard codes
30// success = 1 -- "Normal completion."
31// = 2 -- "Didn't converge."
32// = 3 -- "Parallel"
33// = 4-9 -- reserved
34//
35// Environment:
36// Software developed for the BaBar Detector at the SLAC B-Factory.
37//
38// Authors: (Steve Schaffner) -- initial implementation stolen from A. Snyder
39//
40//------------------------------------------------------------------------
41#ifndef TRKERRCODE_HH
42#define TRKERRCODE_HH
43
44#include <iosfwd>
45#include <string>
46
47// Class interface //
49public:
50
52
53 TrkErrCode(TrkSuccess=succeed, int code=1, const char* str=0);
55
56 // Copy constructors
57 TrkErrCode(const TrkErrCode&);
59
60 // access
61 int failure() const {return _failure;}
62 int success() const {return _success;}
63 const std::string& message() const
64 {
65 return (_string != 0) ? *_string : _nullStr;
66 }
67 void print(std::ostream& ostr) const;
68
69 // set
70 void setMessage(const char* str = 0) {
71 if (_string != 0) delete _string;
72 if (str != 0) {
73 _string= new std::string(str);
74 }
75 else {
76 _string = 0;
77 }
78 }
79 void setFailure(int i, const char* str = 0)
80 {
81 setMessage(str);
82 _failure=(i==0?1:i); _success=0;
83 }
84 void setSuccess(int i, const char* str = 0) {
85 setMessage(str);
86 _success=(i==0?1:i); _failure=0;
87 }
88
89
90private:
91 // Data
92 int _failure;
93 int _success;
94 std::string* _string;
95 static std::string _nullStr;
96};
97
98std::ostream& operator<<(std::ostream& os, const TrkErrCode& trkerr);
99
100#endif
101
std::ostream & operator<<(std::ostream &os, const TrkErrCode &trkerr)
void print(std::ostream &ostr) const
TrkErrCode & operator=(const TrkErrCode &)
Definition: TrkErrCode.cxx:56
const std::string & message() const
void setSuccess(int i, const char *str=0)
void setFailure(int i, const char *str=0)