Revision e1cb2c92

View differences:

include/ExtendedAttribute.h
1
/* -------------------------------------------------------------------------- */
2
/* Copyright 2002-2016, OpenNebula Project, OpenNebula Systems                */
3
/*                                                                            */
4
/* Licensed under the Apache License, Version 2.0 (the "License"); you may    */
5
/* not use this file except in compliance with the License. You may obtain    */
6
/* a copy of the License at                                                   */
7
/*                                                                            */
8
/* http://www.apache.org/licenses/LICENSE-2.0                                 */
9
/*                                                                            */
10
/* Unless required by applicable law or agreed to in writing, software        */
11
/* distributed under the License is distributed on an "AS IS" BASIS,          */
12
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   */
13
/* See the License for the specific language governing permissions and        */
14
/* limitations under the License.                                             */
15
/* -------------------------------------------------------------------------- */
16

  
17
#ifndef EXTENDED_ATTRIBUTE_H_
18
#define EXTENDED_ATTRIBUTE_H_
19

  
20
#include <vector>
21
#include <map>
22

  
23
#include "Attribute.h"
24
#include "Template.h"
25

  
26
/**
27
 *  This class represents a generic attribute, it exposes the basic
28
 *  VectorAttribute interface and can be decorated with functionality
29
 *  for an specific class.
30
 *
31
 *  The attribute operates directly on the OriginalTemplate attribute. IT
32
 *  IS NOT CLONED OR COPIED
33
 */
34
class ExtendedAttribute: public Attribute
35
{
36
public:
37
    VectorAttribute * vector_attribute()
38
    {
39
        return va;
40
    }
41

  
42
    /* ---------------------------------------------------------------------- */
43
    /* VectorAttribute Interface                                              */
44
    /* ---------------------------------------------------------------------- */
45
    template<typename T>
46
    int vector_value(const std::string& name, T& value) const
47
    {
48
        return va->vector_value(name, value);
49
    }
50

  
51
    string vector_value(const std::string& name) const
52
    {
53
        return va->vector_value(name);
54
    }
55

  
56
    template<typename T>
57
    void replace(const std::string& name, T value)
58
    {
59
        va->replace(name, value);
60
    }
61

  
62
    void remove(const std::string& name)
63
    {
64
        va->remove(name);
65
    }
66

  
67

  
68
    void merge(VectorAttribute* vattr, bool replace)
69
    {
70
        va->merge(vattr, replace);
71
    }
72

  
73
protected:
74
    /**
75
     *  Creates the attribute with a reference to a VectorAttribute. The object
76
     *  is shared and WILL BE modified through this interface.
77
     *    @param va pointer to the VectorAttribute.
78
     */
79
    ExtendedAttribute(VectorAttribute *_va):
80
        Attribute(_va->name()) ,va(_va), id(-1) {};
81

  
82
    ExtendedAttribute(VectorAttribute *_va, int _id):
83
        Attribute(_va->name()) ,va(_va), id(_id) {};
84

  
85
    virtual ~ExtendedAttribute(){};
86

  
87
    /* ---------------------------------------------------------------------- */
88
    /* Attribute Interface                                                    */
89
    /* ---------------------------------------------------------------------- */
90
    string * marshall(const char * _sep = 0) const
91
    {
92
        return va->marshall(_sep);
93
    };
94

  
95
    string * to_xml() const
96
    {
97
        return va->to_xml();
98
    };
99

  
100
    void unmarshall(const std::string& sattr, const char * _sep = 0)
101
    {
102
        va->unmarshall(sattr, _sep);
103
    }
104

  
105
    AttributeType type()
106
    {
107
        return va->type();
108
    };
109

  
110
    Attribute* clone() const
111
    {
112
        return va->clone();
113
    };
114

  
115
    /* ---------------------------------------------------------------------- */
116
    /* ExtendedAttribute Interface                                            */
117
    /* ---------------------------------------------------------------------- */
118
    int get_id() const
119
    {
120
        return id;
121
    }
122

  
123
private:
124

  
125
    /* ---------------------------------------------------------------------- */
126
    /* ---------------------------------------------------------------------- */
127
    friend class ExtendedAttributeSet;
128

  
129
    /* ---------------------------------------------------------------------- */
130
    /* ---------------------------------------------------------------------- */
131
    /**
132
     *  The associated VectorAttribute
133
     */
134
    VectorAttribute * va;
135

  
136
    /**
137
     *  Set if the attribute can be addressed by an identifier, -1 otherwise
138
     */
139
    int id;
140
};
141

  
142
/**
143
 *  This class represents a set of ExtendedAttributes it provides fast
144
 *  access to individual elements (by ID) and implement collective operations
145
 */
146
class ExtendedAttributeSet
147
{
148
protected:
149
    /**
150
     *  Creates the ExtenededAttribute set
151
     *    @param dispose elements upon set destruction
152
     */
153
    ExtendedAttributeSet(bool _dispose):dispose(_dispose){};
154

  
155
    virtual ~ExtendedAttributeSet();
156

  
157
    /* ---------------------------------------------------------------------- */
158
    /* Method to access attributes                                            */
159
    /* ---------------------------------------------------------------------- */
160
    /**
161
     *  @return attribute by id or 0 if not found
162
     */
163
    ExtendedAttribute * get_attribute(int id) const;
164

  
165
    /* ---------------------------------------------------------------------- */
166
    /* Iterators                                                              */
167
    /* ---------------------------------------------------------------------- */
168
    /**
169
     *  Generic iterator for the set. Wraps the STL iterator for map, can be
170
     *  used to iterate over the attributes
171
     */
172
    class AttributeIterator
173
    {
174
    public:
175
        AttributeIterator& operator=(const AttributeIterator& rhs)
176
        {
177
            map_it = rhs.map_it;
178
            return *this;
179
        }
180

  
181
        AttributeIterator& operator++()
182
        {
183
            ++map_it;
184
            return *this;
185
        }
186

  
187
        bool operator!=(const AttributeIterator& rhs)
188
        {
189
            return map_it != rhs.map_it;
190
        }
191

  
192
        AttributeIterator(){};
193
        AttributeIterator(const AttributeIterator& ait):map_it(ait.map_it){};
194
        AttributeIterator(const std::map<int,
195
                ExtendedAttribute *>::iterator& _map_it):map_it(_map_it){};
196

  
197
        virtual ~AttributeIterator(){};
198

  
199
    protected:
200
        std::map<int, ExtendedAttribute *>::iterator map_it;
201
    };
202

  
203
    AttributeIterator begin()
204
    {
205
        AttributeIterator it(a_set.begin());
206
        return it;
207
    }
208

  
209
    AttributeIterator end()
210
    {
211
        AttributeIterator it(a_set.end());
212
        return it;
213
    }
214

  
215
    typedef class AttributeIterator attribute_iterator;
216

  
217
    /* ---------------------------------------------------------------------- */
218
    /* Attribute map interface                                                */
219
    /* ---------------------------------------------------------------------- */
220
    /**
221
     *  Adds a new VirtualMachine attribute to the set
222
     */
223
    void add_attribute(ExtendedAttribute * a, int id)
224
    {
225
        a_set.insert(make_pair(id, a));
226
    }
227

  
228
    /**
229
     *  Init the attribute set from a vector
230
     *    @param id_name with the ID of the attribute
231
     *    @param auto_ids automatically generate ids for the attributes
232
     *    @param vas vector of attribute to use
233
     */
234
    void init_attribute_map(const std::string& id_name,
235
            std::vector<VectorAttribute *>& vas);
236
    /**
237
     *  Abstract method to create the VirtualMachineAttributes for this set
238
     */
239
    virtual ExtendedAttribute * attribute_factory(VectorAttribute * va,
240
            int id) const = 0;
241

  
242
    /* ---------------------------------------------------------------------- */
243
    /* ---------------------------------------------------------------------- */
244

  
245
    /**
246
     *  Map with the disk attributes
247
     */
248
    std::map<int, ExtendedAttribute *> a_set;
249

  
250
    /**
251
     *  Frees the VectorAttribute associated with each VirtualMachineAttribute
252
     *  upon object destruction
253
     */
254
    bool dispose;
255
};
256

  
257
#endif  /*VIRTUAL_MACHINE_ATTRIBUTE_H_*/
include/VirtualMachineAttribute.h
17 17
#ifndef VIRTUAL_MACHINE_ATTRIBUTE_H_
18 18
#define VIRTUAL_MACHINE_ATTRIBUTE_H_
19 19

  
20
#include <vector>
21
#include <map>
22

  
23
#include "Attribute.h"
24
#include "Template.h"
20
#include "ExtendedAttribute.h"
25 21

  
26 22
/**
27 23
 *  This class represents a generic VirtualMachine attribute, it exposes the
......
31 27
 *  The attribute operates directly on the VirtualMachineTemplate attribute. IT
32 28
 *  IS NOT CLONED OR COPIED
33 29
 */
34
class VirtualMachineAttribute: public Attribute
30
class VirtualMachineAttribute: public ExtendedAttribute
35 31
{
36
public:
37
    /**
38
     *  Return the associated VectorAttribute to interface with vector attribute
39
     *  functions
40
     */
41
    VectorAttribute * vector_attribute()
42
    {
43
        return va;
44
    }
45

  
46
    /* ---------------------------------------------------------------------- */
47
    /* VectorAttribute Interface                                              */
48
    /* ---------------------------------------------------------------------- */
49
    template<typename T>
50
    int vector_value(const std::string& name, T& value) const
51
    {
52
        return va->vector_value(name, value);
53
    }
54

  
55
    string vector_value(const std::string& name) const
56
    {
57
        return va->vector_value(name);
58
    }
59

  
60
    template<typename T>
61
    void replace(const std::string& name, T value)
62
    {
63
        va->replace(name, value);
64
    }
65

  
66
    void remove(const std::string& name)
67
    {
68
        va->remove(name);
69
    }
70

  
71

  
72
    void merge(VectorAttribute* vattr, bool replace)
73
    {
74
        va->merge(vattr, replace);
75
    }
76

  
77 32
protected:
78 33
    /**
79 34
     *  Creates the attribute with a reference to a VectorAttribute. The object
......
81 36
     *    @param va pointer to the VectorAttribute.
82 37
     */
83 38
    VirtualMachineAttribute(VectorAttribute *_va):
84
        Attribute(_va->name()) ,va(_va), id(-1) {};
39
        ExtendedAttribute(_va){};
85 40

  
86 41
    VirtualMachineAttribute(VectorAttribute *_va, int _id):
87
        Attribute(_va->name()) ,va(_va), id(_id) {};
42
        ExtendedAttribute(_va, _id) {};
88 43

  
89 44
    virtual ~VirtualMachineAttribute(){};
90 45

  
91 46
    /* ---------------------------------------------------------------------- */
92
    /* Attribute Interface                                                    */
93
    /* ---------------------------------------------------------------------- */
94
    string * marshall(const char * _sep = 0) const
95
    {
96
        return va->marshall(_sep);
97
    };
98

  
99
    string * to_xml() const
100
    {
101
        return va->to_xml();
102
    };
103

  
104
    void unmarshall(const std::string& sattr, const char * _sep = 0)
105
    {
106
        va->unmarshall(sattr, _sep);
107
    }
108

  
109
    AttributeType type()
110
    {
111
        return va->type();
112
    };
113

  
114
    Attribute* clone() const
115
    {
116
        return va->clone();
117
    };
118

  
119
    /* ---------------------------------------------------------------------- */
120 47
    /* VirtualMachineAttribute Interface                                      */
121 48
    /* ---------------------------------------------------------------------- */
122 49
    /**
......
139 66
    {
140 67
        bool value;
141 68

  
142
        va->vector_value(flag, value);
69
        vector_value(flag, value);
143 70

  
144 71
        return value;
145 72
    }
146 73

  
147
    int get_id() const
148
    {
149
        return id;
150
    }
151

  
152 74
private:
153

  
154
    /* ---------------------------------------------------------------------- */
155
    /* ---------------------------------------------------------------------- */
156 75
    friend class VirtualMachineAttributeSet;
157

  
158
    /* ---------------------------------------------------------------------- */
159
    /* ---------------------------------------------------------------------- */
160
    /**
161
     *  The associated VectorAttribute
162
     */
163
    VectorAttribute * va;
164

  
165
    /**
166
     *  Set if the attribute can be addressed by an identifier, -1 otherwise
167
     */
168
    int id;
169 76
};
170 77

  
171 78
/**
172 79
 *  This class represents a set of VirtualMachineAttributes it provides fast
173 80
 *  access to individual elements (by ID) and implement collective operations
174 81
 */
175
class VirtualMachineAttributeSet
82
class VirtualMachineAttributeSet : public ExtendedAttributeSet
176 83
{
177 84
protected:
178 85
    /**
179 86
     *  Creates the VirtualMachineAttribute set
180 87
     *    @param dispose elements upon set destruction
181 88
     */
182
    VirtualMachineAttributeSet(bool _dispose):dispose(_dispose){};
89
    VirtualMachineAttributeSet(bool _dispose):ExtendedAttributeSet(_dispose){};
183 90

  
184
    virtual ~VirtualMachineAttributeSet();
91
    virtual ~VirtualMachineAttributeSet(){};
185 92

  
186 93
    /* ---------------------------------------------------------------------- */
187 94
    /* Methods to access attributes                                           */
......
189 96
    /**
190 97
     *  @return attribute by id or 0 if not found
191 98
     */
192
    VirtualMachineAttribute * get_attribute(int id) const;
99
    VirtualMachineAttribute * get_attribute(int id) const
100
    {
101
        return static_cast<VirtualMachineAttribute *>(get_attribute(id));
102
    }
193 103

  
194 104
    /**
195 105
     *  @return attribute with the given flag set or 0 if not found
......
217 127
    VirtualMachineAttribute * clear_flag(const string& flag_name);
218 128

  
219 129
    /* ---------------------------------------------------------------------- */
220
    /* Iterators                                                              */
221
    /* ---------------------------------------------------------------------- */
222
    /**
223
     *  Generic iterator for the set. Wraps the STL iterator for map, can be
224
     *  used to iterate over the attributes
225
     */
226
    class AttributeIterator
227
    {
228
    public:
229
        AttributeIterator& operator=(const AttributeIterator& rhs)
230
        {
231
            map_it = rhs.map_it;
232
            return *this;
233
        }
234

  
235
        AttributeIterator& operator++()
236
        {
237
            ++map_it;
238
            return *this;
239
        }
240

  
241
        bool operator!=(const AttributeIterator& rhs)
242
        {
243
            return map_it != rhs.map_it;
244
        }
245

  
246
        AttributeIterator(){};
247
        AttributeIterator(const AttributeIterator& ait):map_it(ait.map_it){};
248
        AttributeIterator(const std::map<int,
249
                VirtualMachineAttribute *>::iterator& _map_it):map_it(_map_it){};
250

  
251
        virtual ~AttributeIterator(){};
252

  
253
    protected:
254
        std::map<int, VirtualMachineAttribute *>::iterator map_it;
255
    };
256

  
257
    AttributeIterator begin()
258
    {
259
        AttributeIterator it(a_set.begin());
260
        return it;
261
    }
262

  
263
    AttributeIterator end()
264
    {
265
        AttributeIterator it(a_set.end());
266
        return it;
267
    }
268

  
269
    typedef class AttributeIterator attribute_iterator;
270

  
271
    /* ---------------------------------------------------------------------- */
272 130
    /* Attribute map interface                                                */
273 131
    /* ---------------------------------------------------------------------- */
274 132
    /**
275
     *  Adds a new VirtualMachine attribute to the set
276
     */
277
    void add_attribute(VirtualMachineAttribute * a, int id)
278
    {
279
        a_set.insert(make_pair(id, a));
280
    }
281

  
282
    /**
283
     *  Init the attribute set from a vector
284
     *    @param id_name with the ID of the attribute
285
     *    @param auto_ids automatically generate ids for the attributes
286
     *    @param vas vector of attribute to use
287
     */
288
    void init_attribute_map(const std::string& id_name,
289
            std::vector<VectorAttribute *>& vas);
290
    /**
291 133
     *  Abstract method to create the VirtualMachineAttributes for this set
292 134
     */
293
    virtual VirtualMachineAttribute * attribute_factory(VectorAttribute * va,
135
    virtual ExtendedAttribute * attribute_factory(VectorAttribute * va,
294 136
            int id) const = 0;
295

  
296
    /* ---------------------------------------------------------------------- */
297
    /* ---------------------------------------------------------------------- */
298

  
299
    /**
300
     *  Map with the disk attributes
301
     */
302
    std::map<int, VirtualMachineAttribute *> a_set;
303

  
304
    /**
305
     *  Frees the VectorAttribute associated with each VirtualMachineAttribute
306
     *  upon object destruction
307
     */
308
    bool dispose;
309 137
};
310 138

  
311 139
#endif  /*VIRTUAL_MACHINE_ATTRIBUTE_H_*/
include/VirtualMachineDisk.h
379 379

  
380 380
    DiskIterator begin()
381 381
    {
382
        DiskIterator it(VirtualMachineAttributeSet::begin());
382
        DiskIterator it(ExtendedAttributeSet::begin());
383 383
        return it;
384 384
    }
385 385

  
386 386
    DiskIterator end()
387 387
    {
388
        DiskIterator it(VirtualMachineAttributeSet::end());
388
        DiskIterator it(ExtendedAttributeSet::end());
389 389
        return it;
390 390
    }
391 391

  
include/VirtualMachineNic.h
200 200

  
201 201
    NicIterator begin()
202 202
    {
203
        NicIterator it(VirtualMachineAttributeSet::begin());
203
        NicIterator it(ExtendedAttributeSet::begin());
204 204
        return it;
205 205
    }
206 206

  
207 207
    NicIterator end()
208 208
    {
209
        NicIterator it(VirtualMachineAttributeSet::end());
209
        NicIterator it(ExtendedAttributeSet::end());
210 210
        return it;
211 211
    }
212 212

  
src/common/ExtendedAttribute.cc
1
/* -------------------------------------------------------------------------- */
2
/* Copyright 2002-2016, OpenNebula Project, OpenNebula Systems                */
3
/*                                                                            */
4
/* Licensed under the Apache License, Version 2.0 (the "License"); you may    */
5
/* not use this file except in compliance with the License. You may obtain    */
6
/* a copy of the License at                                                   */
7
/*                                                                            */
8
/* http://www.apache.org/licenses/LICENSE-2.0                                 */
9
/*                                                                            */
10
/* Unless required by applicable law or agreed to in writing, software        */
11
/* distributed under the License is distributed on an "AS IS" BASIS,          */
12
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   */
13
/* See the License for the specific language governing permissions and        */
14
/* limitations under the License.                                             */
15
/* -------------------------------------------------------------------------- */
16

  
17
#include "ExtendedAttribute.h"
18

  
19
/* -------------------------------------------------------------------------- */
20
/* -------------------------------------------------------------------------- */
21

  
22
ExtendedAttributeSet::~ExtendedAttributeSet()
23
{
24
    std::map<int, ExtendedAttribute *>::iterator it;
25

  
26
    for (it = a_set.begin(); it != a_set.end(); ++it)
27
    {
28
        if ( dispose )
29
        {
30
            delete it->second->va;
31
        }
32

  
33
        delete it->second;
34
    }
35
};
36

  
37
/* -------------------------------------------------------------------------- */
38
/* -------------------------------------------------------------------------- */
39

  
40
ExtendedAttribute * ExtendedAttributeSet::get_attribute(int id) const
41
{
42
    std::map<int, ExtendedAttribute*>::const_iterator it = a_set.find(id);
43

  
44
    if ( it == a_set.end() )
45
    {
46
        return 0;
47
    }
48

  
49
    return it->second;
50
}
51

  
52
/* -------------------------------------------------------------------------- */
53
/* -------------------------------------------------------------------------- */
54

  
55
void ExtendedAttributeSet::init_attribute_map(const std::string& id_name,
56
        std::vector<VectorAttribute *>& vas)
57
{
58
    std::vector<VectorAttribute *>::iterator it;
59
    int id, auto_id;
60

  
61
    for (it = vas.begin(), auto_id = 0; it != vas.end(); ++it, ++auto_id)
62
    {
63
        if (id_name.empty())
64
        {
65
            id = auto_id;
66
        }
67
        else if ( (*it)->vector_value(id_name, id) != 0 )
68
        {
69
            continue;
70
        }
71

  
72
        ExtendedAttribute * a = attribute_factory(*it, id);
73

  
74
        a_set.insert(make_pair(id, a));
75
    }
76
};
77

  
src/common/SConstruct
24 24
source_files=[
25 25
    'ActionManager.cc',
26 26
    'Attribute.cc',
27
    'ExtendedAttribute.cc',
27 28
    'mem_collector.c',
28 29
    'NebulaUtil.cc'
29 30
]
src/vm/VirtualMachineAttribute.cc
19 19
/* -------------------------------------------------------------------------- */
20 20
/* -------------------------------------------------------------------------- */
21 21

  
22
VirtualMachineAttributeSet::~VirtualMachineAttributeSet()
22
VirtualMachineAttribute * VirtualMachineAttributeSet::get_attribute(
23
        const string& flag) const
23 24
{
24
    std::map<int, VirtualMachineAttribute *>::iterator it;
25
    std::map<int, ExtendedAttribute*>::const_iterator it;
25 26

  
26
    for (it = a_set.begin(); it != a_set.end(); ++it)
27
    VirtualMachineAttribute * vma;
28

  
29
    for( it = a_set.begin(); it != a_set.end(); ++it)
27 30
    {
28
        if ( dispose )
31
        vma = static_cast<VirtualMachineAttribute *>(it->second);
32

  
33
        if ( vma->is_flag(flag) == true )
29 34
        {
30
            delete it->second->va;
35
            return vma;
31 36
        }
32

  
33
        delete it->second;
34
    }
35
};
36

  
37
/* -------------------------------------------------------------------------- */
38
/* -------------------------------------------------------------------------- */
39

  
40
VirtualMachineAttribute * VirtualMachineAttributeSet::get_attribute(int id) const
41
{
42
    std::map<int, VirtualMachineAttribute*>::const_iterator it = a_set.find(id);
43

  
44
    if ( it == a_set.end() )
45
    {
46
        return 0;
47 37
    }
48 38

  
49
    return it->second;
39
    return 0;
50 40
}
51 41

  
52 42
/* -------------------------------------------------------------------------- */
53 43
/* -------------------------------------------------------------------------- */
54 44

  
55
VirtualMachineAttribute * VirtualMachineAttributeSet::get_attribute(
56
        const string& flag) const
45
int VirtualMachineAttributeSet::set_flag(int a_id, const string& flag_name)
57 46
{
58
    std::map<int, VirtualMachineAttribute*>::const_iterator it;
47
    VirtualMachineAttribute * va = get_attribute(a_id);
59 48

  
60
    for( it = a_set.begin(); it != a_set.end(); ++it)
49
    if ( va == 0 )
61 50
    {
62
        if ( it->second->is_flag(flag) == true )
63
        {
64
            return it->second;
65
        }
51
        return -1;
66 52
    }
67 53

  
54
    va->set_flag(flag_name);
55

  
68 56
    return 0;
69 57
}
70 58

  
......
74 62
VirtualMachineAttribute * VirtualMachineAttributeSet::remove_attribute(
75 63
        const string& flag)
76 64
{
77
    std::map<int, VirtualMachineAttribute*>::const_iterator it;
65
    std::map<int, ExtendedAttribute*>::const_iterator it;
66

  
67
    VirtualMachineAttribute * vma;
78 68
    VirtualMachineAttribute * tmp = 0;
79 69

  
80 70
    for( it = a_set.begin(); it != a_set.end(); ++it)
81 71
    {
82
        if ( it->second->is_flag(flag) == true )
72
        vma = static_cast<VirtualMachineAttribute *>(it->second);
73

  
74
        if ( vma->is_flag(flag) == true )
83 75
        {
84
            tmp = it->second;
76
            tmp = vma;
85 77
            a_set.erase(it);
86 78
        }
87 79
    }
......
92 84
/* -------------------------------------------------------------------------- */
93 85
/* -------------------------------------------------------------------------- */
94 86

  
95
void VirtualMachineAttributeSet::init_attribute_map(const std::string& id_name,
96
        std::vector<VectorAttribute *>& vas)
97
{
98
    std::vector<VectorAttribute *>::iterator it;
99
    int id, auto_id;
100

  
101
    for (it = vas.begin(), auto_id = 0; it != vas.end(); ++it, ++auto_id)
102
    {
103
        if (id_name.empty())
104
        {
105
            id = auto_id;
106
        }
107
        else if ( (*it)->vector_value(id_name, id) != 0 )
108
        {
109
            continue;
110
        }
111

  
112
        VirtualMachineAttribute * a = attribute_factory(*it, id);
113

  
114
        a_set.insert(make_pair(id, a));
115
    }
116
};
117

  
118
/* -------------------------------------------------------------------------- */
119
/* -------------------------------------------------------------------------- */
120

  
121
int VirtualMachineAttributeSet::set_flag(int a_id, const string& flag_name)
122
{
123
    VirtualMachineAttribute * va = get_attribute(a_id);
124

  
125
    if ( va == 0 )
126
    {
127
        return -1;
128
    }
129

  
130
    va->set_flag(flag_name);
131

  
132
    return 0;
133
}
134

  
135
/* -------------------------------------------------------------------------- */
136
/* -------------------------------------------------------------------------- */
137

  
138 87
VirtualMachineAttribute * VirtualMachineAttributeSet::clear_flag(
139 88
        const string& flag)
140 89
{
141
    std::map<int, VirtualMachineAttribute*>::iterator it;
90
    std::map<int, ExtendedAttribute *>::iterator it;
91

  
92
    VirtualMachineAttribute * vma;
142 93

  
143 94
    for( it = a_set.begin(); it != a_set.end(); ++it)
144 95
    {
145
        if ( it->second->is_flag(flag) == true )
96
        vma = static_cast<VirtualMachineAttribute *>(it->second);
97

  
98
        if ( vma->is_flag(flag) == true )
146 99
        {
147
            it->second->clear_flag(flag);
100
            vma->clear_flag(flag);
148 101

  
149
            return it->second;
102
            return vma;
150 103
        }
151 104
    }
152 105

  

Also available in: Unified diff