VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gexception.cpp
Go to the documentation of this file.
1 //
2 // Copyright (C) 2017 Graeme Walker
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // ===
17 //
18 // gexception.cpp
19 //
20 
21 #include "gdef.h"
22 #include "gexception.h"
23 
24 G::Exception::Exception( const char * what ) :
25  m_what(what?what:"")
26 {
27 }
28 
29 G::Exception::Exception( const std::string & what ) :
30  m_what(what)
31 {
32 }
33 
34 G::Exception::Exception( const char * what , const std::string & more ) :
35  m_what(what)
36 {
37  append( more ) ;
38 }
39 
40 G::Exception::Exception( const std::string & what , const std::string & more ) :
41  m_what(what)
42 {
43  append( more ) ;
44 }
45 
46 G::Exception::Exception( const std::string & what , const std::string & more1 , const std::string & more2 ) :
47  m_what(what)
48 {
49  append( more1 ) ;
50  append( more2 ) ;
51 }
52 
53 G::Exception::Exception( const std::string & what , const std::string & more1 , const std::string & more2 , const std::string & more3 ) :
54  m_what(what)
55 {
56  append( more1 ) ;
57  append( more2 ) ;
58  append( more3 ) ;
59 }
60 
62 {
63 }
64 
65 const char * G::Exception::what() const g__noexcept
66 {
67  return m_what.c_str() ;
68 }
69 
70 void G::Exception::append( const char * more )
71 {
72  if( more != nullptr && *more != '\0' )
73  {
74  m_what += std::string(": ") ;
75  m_what += std::string(more) ;
76  }
77 }
78 
79 void G::Exception::append( const std::string & more )
80 {
81  if( !more.empty() )
82  {
83  m_what += std::string(": ") ;
84  m_what += std::string(more) ;
85  }
86 }
87 
88 void G::Exception::prepend( const char * context )
89 {
90  if( context != nullptr && *context != '\0' )
91  {
92  m_what = std::string(context) + ": " + m_what ;
93  }
94 }
95 
96 /// \file gexception.cpp
virtual const char * what() const g__noexcept override
Override from std::exception.
Definition: gexception.cpp:65
Exception(const char *what)
Constructor.
Definition: gexception.cpp:24
void prepend(const char *context)
Prepends context to the what string.
Definition: gexception.cpp:88
virtual ~Exception() g__noexcept
Destructor.
Definition: gexception.cpp:61
void append(const char *more)
Appends 'more' to the what string.
Definition: gexception.cpp:70