summaryrefslogtreecommitdiff
path: root/include/flag.h
blob: beb79ba2efd03e69ee46b3fb67ed51452f983f1f (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/**
 *  flag.h
 *
 *  flag clases for the safe transfer of a Zend flag to a Zend functions
 *
 *  @author Valeriy_Dmitriev <ufabiz@gmail.com>
 */

#ifndef PHPCPP_FLAG_INCLUDE_C_H_
#define PHPCPP_FLAG_INCLUDE_C_H_

/**
 *  Namespace Php
 */
namespace Php {


    /**
     *  class FlagTemplate 
     *  Designed for the safe transfer of a Zend flag to a Zend functions
     */
    template <class AccT>
    class FlagTemplate
    {
    public:
        /**
         *  Constructor
         */
        FlagTemplate(const AccT &zflag);

        /**
         *  Copy constructor
         *  @param  FlagTemplate      The FlagTemplate to copy
         */
        FlagTemplate(const FlagTemplate &flags) : _val(flags._val) {}
        
        /**
         *  Move constructor
         *  @param  FlagTemplate      The FlagTemplate to move
         */
        FlagTemplate(FlagTemplate &&flags) : _val(std::move(flags._val)){}

        /**
         *  Assignment operator
         */
        FlagTemplate &operator=(const FlagTemplate &flags) {
            if (this != &flags) {
                _val = flags._val;
            }
            return *this;
        }

        /**
         *  Move operator
         */
        FlagTemplate &operator=(FlagTemplate &&flags) {
            if (this != &flags) {
                _val = std::move(flags._val);
            }
            return *this;
        }

        /**
         *  Bitwise OR assignment operator
         */
        FlagTemplate &operator|=(const FlagTemplate &flags) {
            _val |= flags._val;
            return *this;
        }

        /**
         *  Bitwise OR operator
         */
        FlagTemplate operator|(const FlagTemplate &flags) {
            return FlagTemplate (_val | flags._val);
        }

        /**
         *  Cast to a int
         *  @return int
         */
        operator int () const {
            return _val;
        }

        /**
         *  Destructor
         */
        ~FlagTemplate () {}

    private:

        /**
         *  Private constructor
         *  @param  int val
         */
        FlagTemplate(const int &val) :_val(val) {}

        /**
         *  Private constructor
         *  @param  void
         */
        FlagTemplate() {}

        /**
         *  value of flag
         */
        int _val;
    };
    
    /**
     *  class FlagClass 
     *  For the safe transfer of a Zend Class flags to a Zend functions
     */
    typedef FlagTemplate<Zend::AccClass> FlagClass;
    /**
     *  class FlagClass 
     *  For the safe transfer of a Zend access types for methods and propertyes
     */
    typedef FlagTemplate<Zend::AccMemb> FlagMemb;
    

    /**
     *  factory function
     */
    FlagClass Flag(const Zend::AccClass &zflag);
    FlagMemb  Flag(const Zend::AccMemb &zflag);


/**
 *  End of namespace Php
 */
}

#endif  /* PHPCPP_FLAG_INCLUDE_C_H_ */