Revision e1cb2c92 src/vm/VirtualMachineAttribute.cc
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