summaryrefslogtreecommitdiff
path: root/src/origexception.h
blob: c1b2871f9ed053d53e01f9bba534f63e8e0d0ade (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
 *  OrigException.h
 *
 *  Class that wraps around an exception that was thrown by PHP code,
 *  and that could - but not necessarily has to - be caught by C++
 *
 *  @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
 *  @copyright 2013 Copernica BV
 */

/**
 *  Set up namespace
 */
namespace Php {

/**
 *  Class definition
 */
class OrigException : public Value, public Exception
{
private:    
    /**
     *  Has the exception been restored by the C++ code so that it can be dealt by PHP?
     *  @var    boolean
     */
    bool _restored = false;
    
public:
    /**
     *  Constructor
     *  @param  zval
     */
    OrigException(struct _zval_struct *zval) : 
        Value(zval), Exception("OrigException") {}
    
    /**
     *  Copy constructor
     *  @param  exception
     */
    OrigException(const OrigException &exception) : 
        Value(exception), Exception("OrigException"), _restored(exception._restored) {}
    
    /**
     *  Move constructor
     *  @param  exception
     */
    OrigException(OrigException &&exception) :
        Value(std::move(exception)), Exception("OrigException"), _restored(exception._restored) 
    {
        // set other exception to restored so that it wont 
        // do anything on destruction
        exception._restored = true;
    }
    
    /**
     *  Destructor
     */
    virtual ~OrigException() throw();
    
    /**
     *  Process the exception
     * 
     *  This will restore the exception so that it can be further processed 
     *  in PHP code
     *  @internal
     */
    virtual void process() override
    {
        // mark exception as restored
        _restored = true;
    }
};

/**
 *  End of namespace
 */
}