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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
|
// Copyright (C) 2003 Dominique Devriese <devriese@kde.org>
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
// 02110-1301, USA.
#include "object_calcer.h"
#include "object_holder.h"
#include "object_imp.h"
#include "object_type.h"
#include "../misc/coordinate.h"
#include "common.h"
#include <algorithm>
#include <set>
void ObjectTypeCalcer::calc( const KigDocument& doc )
{
Args a;
a.reserve( mparents.size() );
std::transform( mparents.begin(), mparents.end(),
std::back_inserter( a ), std::mem_fun( &ObjectCalcer::imp ) );
ObjectImp* n = mtype->calc( a, doc );
delete mimp;
mimp = n;
}
ObjectTypeCalcer::ObjectTypeCalcer( const ObjectType* type,
const std::vector<ObjectCalcer*>& parents, bool sort )
: mparents( ( sort )?type->sortArgs( parents ):parents ), mtype( type ), mimp( 0 )
{
std::for_each( mparents.begin(), mparents.end(),
std::bind2nd( std::mem_fun( &ObjectCalcer::addChild ), this ) );
}
ObjectCalcer::~ObjectCalcer()
{
}
ObjectConstCalcer::ObjectConstCalcer( ObjectImp* imp )
: mimp( imp )
{
}
ObjectConstCalcer::~ObjectConstCalcer()
{
delete mimp;
}
const ObjectImp* ObjectConstCalcer::imp() const
{
return mimp;
}
void ObjectConstCalcer::calc( const KigDocument& )
{
}
std::vector<ObjectCalcer*> ObjectConstCalcer::parents() const
{
// we have no parents..
return std::vector<ObjectCalcer*>();
}
void ObjectCalcer::ref()
{
++refcount;
}
void ObjectCalcer::deref()
{
if ( --refcount <= 0 ) delete this;
}
void intrusive_ptr_add_ref( ObjectCalcer* p )
{
p->ref();
}
void intrusive_ptr_release( ObjectCalcer* p )
{
p->deref();
}
const ObjectImp* ObjectTypeCalcer::imp() const
{
return mimp;
}
std::vector<ObjectCalcer*> ObjectTypeCalcer::parents() const
{
return mparents;
}
void ObjectCalcer::addChild( ObjectCalcer* c )
{
mtqchildren.push_back( c );
ref();
}
void ObjectCalcer::delChild( ObjectCalcer* c )
{
std::vector<ObjectCalcer*>::iterator i = std::find( mtqchildren.begin(), mtqchildren.end(), c );
assert( i != mtqchildren.end() );
mtqchildren.erase( i );
deref();
}
ObjectTypeCalcer::~ObjectTypeCalcer()
{
std::for_each( mparents.begin(), mparents.end(),
std::bind2nd( std::mem_fun( &ObjectCalcer::delChild ), this ) );
delete mimp;
}
const ObjectType* ObjectTypeCalcer::type() const
{
return mtype;
}
ObjectPropertyCalcer::ObjectPropertyCalcer( ObjectCalcer* tqparent, int propid )
: mimp( 0 ), mtqparent( tqparent ), mpropid( propid )
{
// Some weird C++ thing prevents me from calling protected members
// of ObjectCalcer on mtqparent.. This is an ugly workaround..
( mtqparent->*&ObjectCalcer::addChild )( this );
//mtqparent->addChild( this );
}
ObjectPropertyCalcer::~ObjectPropertyCalcer()
{
// Some weird C++ thing prevents me from calling protected members
// of ObjectCalcer on mtqparent.. This is an ugly workaround..
( mtqparent->*&ObjectCalcer::delChild )( this );
//mtqparent->delChild( this );
delete mimp;
}
const ObjectImp* ObjectPropertyCalcer::imp() const
{
return mimp;
}
std::vector<ObjectCalcer*> ObjectPropertyCalcer::parents() const
{
std::vector<ObjectCalcer*> ret;
ret.push_back( mtqparent );
return ret;
}
void ObjectPropertyCalcer::calc( const KigDocument& doc )
{
ObjectImp* n = mtqparent->imp()->property( mpropid, doc );
delete mimp;
mimp = n;
}
ObjectImp* ObjectConstCalcer::switchImp( ObjectImp* newimp )
{
ObjectImp* ret = mimp;
mimp = newimp;
return ret;
}
std::vector<ObjectCalcer*> ObjectCalcer::tqchildren() const
{
return mtqchildren;
}
const ObjectImpType* ObjectPropertyCalcer::impRequirement(
ObjectCalcer*, const std::vector<ObjectCalcer*>& ) const
{
return mtqparent->imp()->impRequirementForProperty( mpropid );
}
const ObjectImpType* ObjectConstCalcer::impRequirement(
ObjectCalcer*, const std::vector<ObjectCalcer*>& ) const
{
assert( false );
return ObjectImp::stype();
}
const ObjectImpType* ObjectTypeCalcer::impRequirement(
ObjectCalcer* o, const std::vector<ObjectCalcer*>& os ) const
{
Args args;
args.reserve( mparents.size() );
std::transform(
os.begin(), os.end(),
std::back_inserter( args ),
std::mem_fun( &ObjectCalcer::imp ) );
assert( std::find( args.begin(), args.end(), o->imp() ) != args.end() );
return mtype->impRequirement( o->imp(), args );
}
int ObjectPropertyCalcer::propId() const
{
return mpropid;
}
void ObjectConstCalcer::setImp( ObjectImp* newimp )
{
delete switchImp( newimp );
}
void ObjectTypeCalcer::setParents( const std::vector<ObjectCalcer*> np )
{
std::for_each( np.begin(), np.end(),
std::bind2nd( std::mem_fun( &ObjectCalcer::addChild ), this ) );
std::for_each( mparents.begin(), mparents.end(),
std::bind2nd( std::mem_fun( &ObjectCalcer::delChild ), this ) );
mparents = np;
}
void ObjectTypeCalcer::setType( const ObjectType* t )
{
mtype = t;
}
bool ObjectCalcer::canMove() const
{
return false;
}
bool ObjectCalcer::isFreelyTranslatable() const
{
return false;
}
Coordinate ObjectCalcer::moveReferencePoint() const
{
assert( false );
return Coordinate::invalidCoord();
}
void ObjectCalcer::move( const Coordinate&, const KigDocument& )
{
assert( false );
}
bool ObjectTypeCalcer::canMove() const
{
return mtype->canMove( *this );
}
bool ObjectTypeCalcer::isFreelyTranslatable() const
{
return mtype->isFreelyTranslatable( *this );
}
Coordinate ObjectTypeCalcer::moveReferencePoint() const
{
return mtype->moveReferencePoint( *this );
}
void ObjectTypeCalcer::move( const Coordinate& to, const KigDocument& doc )
{
// we need to check if type can in fact move, because this check is
// not done for us in all circumstances ( e.g. LineABType::move uses
// move on its parents to move them ), and the ObjectType's depend
// on move only being called if canMove() returns true..
if ( mtype->canMove( *this ) )
mtype->move( *this, to, doc );
}
ObjectCalcer* ObjectPropertyCalcer::tqparent() const
{
return mtqparent;
}
ObjectCalcer::ObjectCalcer()
: refcount( 0 )
{
}
std::vector<ObjectCalcer*> ObjectCalcer::movableParents() const
{
return std::vector<ObjectCalcer*>();
}
std::vector<ObjectCalcer*> ObjectTypeCalcer::movableParents() const
{
return mtype->movableParents( *this );
}
bool ObjectConstCalcer::isDefinedOnOrThrough( const ObjectCalcer* ) const
{
return false;
}
bool ObjectPropertyCalcer::isDefinedOnOrThrough( const ObjectCalcer* o ) const
{
return o == mtqparent &&
mtqparent->imp()->isPropertyDefinedOnOrThroughThisImp( propId() );
}
bool ObjectTypeCalcer::isDefinedOnOrThrough( const ObjectCalcer* o ) const
{
Args args;
args.reserve( mparents.size() );
std::transform(
mparents.begin(), mparents.end(),
std::back_inserter( args ),
std::mem_fun( &ObjectCalcer::imp ) );
if ( std::find( args.begin(), args.end(), o->imp() ) == args.end() )
return false;
return mtype->isDefinedOnOrThrough( o->imp(), args );
}
|