~compiz-team/compiz/compiuz.fix_1042041

« back to all changes in this revision

Viewing changes to compizconfig/tests/compizconfig_ccs_list_wrapper.h.moved

  • Committer: Sam Spilsbury
  • Date: 2012-09-22 03:59:35 UTC
  • mfrom: (3324.3.40 compiz.fix_1042537)
  • Revision ID: sam.spilsbury@canonical.com-20120922035935-p78el5ak2xn39tpz
MergeĀ lp:~compiz-team/compiz/compiz.fix_1043527.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Compiz configuration system library
3
 
 *
4
 
 * Copyright (C) 2012 Canonical Ltd.
5
 
 *
6
 
 * This library is free software; you can redistribute it and/or
7
 
 * modify it under the terms of the GNU Lesser General Public
8
 
 * License as published by the Free Software Foundation; either
9
 
 * version 2.1 of the License, or (at your option) any later version.
10
 
 
11
 
 * This library is distributed in the hope that it will be useful,
12
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 
 * Lesser General Public License for more details.
15
 
 
16
 
 * You should have received a copy of the GNU Lesser General Public
17
 
 * License along with this library; if not, write to the Free Software
18
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19
 
 *
20
 
 * Authored By:
21
 
 * Sam Spilsbury <sam.spilsbury@canonical.com>
22
 
 */
23
 
#ifndef _COMPIZCONFIG_CCS_LIST_WRAPPER_H
24
 
#define _COMPIZCONFIG_CCS_LIST_WRAPPER_H
25
 
 
26
 
#include <ccs-defs.h>
27
 
#include <ccs-setting-types.h>
28
 
 
29
 
#include <boost/shared_ptr.hpp>
30
 
#include <boost/noncopyable.hpp>
31
 
 
32
 
typedef struct _CCSSettingValueList * CCSSettingValueList;
33
 
typedef struct _CCSSetting CCSSetting;
34
 
typedef union _CCSSettingInfo CCSSettingInfo;
35
 
typedef struct _CCSSettingValue CCSSettingValue;
36
 
 
37
 
namespace compiz
38
 
{
39
 
    namespace config
40
 
    {
41
 
        template <typename ListType, typename DataType>
42
 
        class CCSListWrapper :
43
 
            boost::noncopyable
44
 
        {
45
 
            public:
46
 
 
47
 
                virtual ~CCSListWrapper () {}
48
 
 
49
 
                virtual CCSListWrapper<ListType, DataType> & append (const DataType &) = 0;
50
 
                virtual CCSListWrapper<ListType, DataType> & remove (const DataType &) = 0;
51
 
 
52
 
                virtual operator const ListType & () const = 0;
53
 
                virtual operator ListType & () = 0;
54
 
        };
55
 
 
56
 
        namespace impl
57
 
        {
58
 
            namespace cc = compiz::config;
59
 
            namespace cci = compiz::config::impl;
60
 
 
61
 
            typedef enum _ListStorageType
62
 
            {
63
 
                Shallow = 0,
64
 
                Deep = 1
65
 
            } ListStorageType;
66
 
 
67
 
            template <typename ListType, typename DataType>
68
 
            class CCSListWrapper :
69
 
                public cc::CCSListWrapper <ListType, DataType>
70
 
            {
71
 
                public:
72
 
 
73
 
                    typedef ListType (*ListTypeFreeFunc) (ListType, Bool);
74
 
                    typedef ListType (*ListTypeAppendFunc) (ListType, DataType);
75
 
                    typedef ListType (*ListTypeRemoveFunc) (ListType, DataType, Bool);
76
 
 
77
 
                    CCSListWrapper (const ListType &list,
78
 
                                    ListTypeFreeFunc freeFunc,
79
 
                                    ListTypeAppendFunc appendFunc,
80
 
                                    ListTypeRemoveFunc removeFunc,
81
 
                                    ListStorageType  storageType) :
82
 
                        mList (list),
83
 
                        mFree (freeFunc),
84
 
                        mAppend (appendFunc),
85
 
                        mRemove (removeFunc),
86
 
                        mStorageType (storageType)
87
 
                    {
88
 
                    };
89
 
 
90
 
                    cc::CCSListWrapper<ListType, DataType> & append (DataType const &data)
91
 
                    {
92
 
                        mList = (*mAppend) (mList, data);
93
 
                        return *this;
94
 
                    }
95
 
 
96
 
                    cc::CCSListWrapper<ListType, DataType> & remove (DataType const &data)
97
 
                    {
98
 
                        Bool freeObj = (mStorageType == Deep);
99
 
                        mList = (*mRemove) (mList, data, freeObj);
100
 
                        return *this;
101
 
                    }
102
 
 
103
 
                    operator const ListType & () const
104
 
                    {
105
 
                        return mList;
106
 
                    }
107
 
 
108
 
                    operator ListType & ()
109
 
                    {
110
 
                        return mList;
111
 
                    }
112
 
 
113
 
                    ~CCSListWrapper ()
114
 
                    {
115
 
                        Bool freeObj = (mStorageType == Deep);
116
 
 
117
 
                        (*mFree) (mList, freeObj);
118
 
                    }
119
 
 
120
 
                private:
121
 
 
122
 
                    ListType           mList;
123
 
                    ListTypeFreeFunc   mFree;
124
 
                    ListTypeAppendFunc mAppend;
125
 
                    ListTypeRemoveFunc mRemove;
126
 
                    ListStorageType    mStorageType;
127
 
            };
128
 
 
129
 
            class PrivateCCSSettingValueListWrapper;
130
 
 
131
 
            class CCSSettingValueListWrapper :
132
 
                public compiz::config::CCSListWrapper <CCSSettingValueList, CCSSettingValue *>
133
 
            {
134
 
                public:
135
 
 
136
 
                    typedef boost::shared_ptr <CCSSettingValueListWrapper> Ptr;
137
 
                    typedef compiz::config::CCSListWrapper <CCSSettingValueList, CCSSettingValue *> InternalWrapper;
138
 
                    typedef compiz::config::impl::CCSListWrapper <CCSSettingValueList, CCSSettingValue *> InternalWrapperImpl;
139
 
 
140
 
                    CCSSettingValueListWrapper (CCSSettingValueList                      list,
141
 
                                                ListStorageType                          storageType,
142
 
                                                CCSSettingType                           type,
143
 
                                                const boost::shared_ptr <CCSSettingInfo> &listInfo,
144
 
                                                const boost::shared_ptr <CCSSetting>     &settingReference);
145
 
 
146
 
                    CCSSettingType type ();
147
 
 
148
 
                    InternalWrapper & append (CCSSettingValue * const &value);
149
 
                    InternalWrapper & remove (CCSSettingValue * const &value);
150
 
                    operator const CCSSettingValueList & () const;
151
 
                    operator CCSSettingValueList & ();
152
 
                    const boost::shared_ptr <CCSSetting> & setting ();
153
 
 
154
 
                private:
155
 
 
156
 
                    boost::shared_ptr <PrivateCCSSettingValueListWrapper> priv;
157
 
            };
158
 
        }
159
 
    }
160
 
}
161
 
 
162
 
 
163
 
 
164
 
#endif