Apache Qpid - AMQP Messaging for Java JMS, C++, Python, Ruby, and .NET Apache Qpid Documentation
ExceptionHolder.h
Go to the documentation of this file.
1 #ifndef QPID_EXCEPTIONHOLDER_H
2 #define QPID_EXCEPTIONHOLDER_H
3 
4 /*
5  *
6  * Licensed to the Apache Software Foundation (ASF) under one
7  * or more contributor license agreements. See the NOTICE file
8  * distributed with this work for additional information
9  * regarding copyright ownership. The ASF licenses this file
10  * to you under the Apache License, Version 2.0 (the
11  * "License"); you may not use this file except in compliance
12  * with the License. You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing,
17  * software distributed under the License is distributed on an
18  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19  * KIND, either express or implied. See the License for the
20  * specific language governing permissions and limitations
21  * under the License.
22  *
23  */
24 
25 #include <boost/shared_ptr.hpp>
26 
27 
28 namespace qpid {
29 namespace sys {
30 
31 struct Raisable {
32  virtual ~Raisable() {};
33  virtual void raise() const=0;
34  virtual std::string what() const=0;
35 };
36 
41 class ExceptionHolder : public Raisable {
42  public:
44  // Use default copy & assign.
45 
47  template <class Ex> ExceptionHolder(Ex* ex) { wrap(ex); }
48  template <class Ex> ExceptionHolder& operator=(Ex* ex) { wrap(ex); return *this; }
49 
50  void raise() const { if (wrapper.get()) wrapper->raise() ; }
51  std::string what() const { return wrapper.get() ? wrapper->what() : std::string(); }
52  bool empty() const { return !wrapper.get(); }
53  operator bool() const { return !empty(); }
54  void reset() { wrapper.reset(); }
55 
56  private:
57  template <class Ex> struct Wrapper : public Raisable {
58  Wrapper(Ex* ptr) : exception(ptr) {}
59  void raise() const { throw *exception; }
60  std::string what() const { return exception->what(); }
61  boost::shared_ptr<Ex> exception;
62  };
63  template <class Ex> void wrap(Ex* ex) { wrapper.reset(new Wrapper<Ex>(ex)); }
64  boost::shared_ptr<Raisable> wrapper;
65 };
66 
67 
68 }} // namespace qpid::sys
69 
70 
71 #endif
std::string what() const
ExceptionHolder(Ex *ex)
Take ownership of ex.
ExceptionHolder & operator=(Ex *ex)
This file was automatically generated from the AMQP specification.
Definition: Address.h:27
virtual std::string what() const =0
Holder for exceptions.

Qpid C++ API Reference
Generated on Sat Feb 7 2015 for Qpid C++ Client API by doxygen 1.8.9.1