summaryrefslogtreecommitdiff
path: root/include/properties.h
blob: cb8b38e0237d949f7584689ff916ca5713924714 (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
/**
 *  Properties.h
 *
 *  The properties of a class are accessible using the protected _properties
 *  member. This is a class that implements the [] operator, so that all 
 *  properties can be accessed using ["name"].
 *
 *  @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
 *  @copyright 2013 Copernica BV
 */

/**
 *  Namespace
 */
namespace Php {

/**
 *  Class properties
 */
class Properties
{
public:
    /**
     *  Destructor
     */
    virtual ~Properties() {}
    
    /**
     *  Get access to a property by name
     *  @param  name
     *  @return HashMember
     */
    HashMember<std::string> operator[](const char *name) 
    { 
        // map to value
        return _value[name];
    }
    
    /**
     *  Another way to get access to a property
     *  @param  name
     *  @return HashMember
     */
    HashMember<std::string> operator[](const std::string &name)
    {
        // map to value
        return _value[name];
    }

private:
    /**
     *  Private constructor - outside users are not supposed to instantiate this object
     *  @param  zval
     */
    Properties(struct _zval_struct *zval) : _value(zval) {}
    
    /**
     *  The value object
     *  @var    Value
     */
    Value _value;
    
    /**
     *  Only the base class can create properties
     */
    friend class Base;
};

/**
 *  End of namespace
 */
}