~ubuntu-branches/ubuntu/trusty/plee-the-bear/trusty-proposed

« back to all changes in this revision

Viewing changes to bear-factory/bear-editor/src/bf/code/item_class.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Julien Jorge, Julien Jorge
  • Date: 2010-11-17 20:13:34 UTC
  • mfrom: (6.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20101117201334-o4dp7uq437to7oxb
Tags: 0.5.1-1
[ Julien Jorge ]
* New upstream release (Closes: #565062, #546514).
* Add armhf architecture (Closes: #604689).
* Remove patches integrated upstream: rpath-editors.diff, rpath-game.diff,
  editors-menu-section.diff.
* Bump the Standard-Version, no changes.
* Update my email address.
* Set build dependency of libclaw to 1.6.0.
* Add the missing ${misc:Depends} in debian/control.
* List gettext translations in bear-factory.install and plee-the-bear.install.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
  Bear Engine - Editor library
3
3
 
4
 
  Copyright (C) 2005-2009 Julien Jorge, Sebastien Angibaud
 
4
  Copyright (C) 2005-2010 Julien Jorge, Sebastien Angibaud
5
5
 
6
6
  This program is free software; you can redistribute it and/or modify it
7
7
  under the terms of the GNU General Public License as published by the
135
135
 
136
136
/*----------------------------------------------------------------------------*/
137
137
/**
138
 
 * \brief Get the name of the class.
 
138
 * \brief Set the description of the class.
 
139
 * \param desc The description of the class.
 
140
 */
 
141
void bf::item_class::set_description( const std::string& desc )
 
142
{
 
143
  m_description = desc;
 
144
} // item_class::set_description()
 
145
 
 
146
/*----------------------------------------------------------------------------*/
 
147
/**
 
148
 * \brief Set the url where a documentation of the class can be found.
 
149
 * \param url The url.
 
150
 */
 
151
void bf::item_class::set_url( const std::string& url )
 
152
{
 
153
  m_url = url;
 
154
} // item_class::set_url()
 
155
 
 
156
/*----------------------------------------------------------------------------*/
 
157
/**
 
158
 * \brief Set the name of the class.
139
159
 * \param class_name The name of the class.
140
160
 */
141
161
void bf::item_class::set_class_name( const std::string& class_name )
206
226
 
207
227
  for (it=super_class_begin(); !result && (it!=super_class_end()); ++it )
208
228
    result = (it->get_class_name() == super_class);
209
 
       
 
229
 
210
230
  return result;
211
231
} // item_class::add_super_class()
212
232
 
261
281
std::string bf::item_class::get_default_value( const std::string& f ) const
262
282
{
263
283
  std::string result;
264
 
  std::map<std::string, std::string>::const_iterator it =
265
 
    m_default_value.find(f);
 
284
  string_map_type::const_iterator it = m_default_value.find(f);
266
285
 
267
286
  if ( it!=m_default_value.end() )
268
287
    result = it->second;
287
306
 
288
307
/*----------------------------------------------------------------------------*/
289
308
/**
 
309
 * \brief Indicate that a field of the parent classes is defined by this class.
 
310
 * \param f The name of the field.
 
311
 */
 
312
void bf::item_class::add_removed_field( const std::string& f )
 
313
{
 
314
  CLAW_PRECOND( has_field(f) );
 
315
  CLAW_PRECOND( std::find( m_removed_fields.begin(), m_removed_fields.end(), f )
 
316
                == m_removed_fields.end() );
 
317
 
 
318
  m_removed_fields.push_back(f);
 
319
} // item_class::add_removed_field()
 
320
 
 
321
/*----------------------------------------------------------------------------*/
 
322
/**
290
323
 * \brief Get all the names of the fields of this class and its super classes.
291
324
 * \param f (out) The names of the fields.
292
325
 */
293
326
void bf::item_class::get_field_names_in_hierarchy
294
327
( std::list<std::string>& f ) const
295
328
{
296
 
  std::transform( m_field.begin(), m_field.end(), std::front_inserter(f),
297
 
                  claw::const_pair_first<field_map_type::value_type>() );
298
 
 
299
 
  const_super_class_iterator it;
300
 
 
301
 
  for ( it=super_class_begin(); it!=super_class_end(); ++it )
302
 
    it->get_field_names_in_hierarchy(f);
 
329
  std::list<std::string> fields;
 
330
  std::list<std::string> removed;
 
331
 
 
332
  get_all_field_names_in_hierarchy(fields);
 
333
  get_removed_fields_names_in_hierarchy(removed);
 
334
 
 
335
  fields.sort();
 
336
  removed.sort();
 
337
  f.clear();
 
338
 
 
339
  std::set_difference
 
340
    ( fields.begin(), fields.end(), removed.begin(), removed.end(),
 
341
      std::back_inserter(f) );
 
342
 
 
343
  f.unique();
303
344
} // item_class::get_field_names_in_hierarchy()
304
345
 
305
346
/*----------------------------------------------------------------------------*/
319
360
 
320
361
/*----------------------------------------------------------------------------*/
321
362
/**
322
 
 * \brief Get the description of a field, given its name.
323
 
 * \param field_name The name of the field.
324
 
 */
325
 
const bf::type_field*
326
 
bf::item_class::search_field( const std::string& field_name ) const
327
 
{
328
 
  field_map_type::const_iterator it = m_field.find(field_name);
329
 
  const bf::type_field* result = NULL;
330
 
 
331
 
  if ( it != m_field.end() )
332
 
    result = it->second;
333
 
  else
334
 
    {
335
 
      const_super_class_iterator it_p;
336
 
 
337
 
      for ( it_p=super_class_begin();
338
 
            (result == NULL) && it_p!=super_class_end(); ++it_p )
339
 
        result = it_p->search_field(field_name);
340
 
    }
341
 
 
342
 
  return result;
343
 
} // item_class::search_field()
 
363
 * \brief Get the description of the class.
 
364
 */
 
365
const std::string& bf::item_class::get_description() const
 
366
{
 
367
  return m_description;
 
368
} // item_class::get_description()
 
369
 
 
370
/*----------------------------------------------------------------------------*/
 
371
/**
 
372
 * \brief Get the url of the documentation of the class.
 
373
 */
 
374
const std::string& bf::item_class::get_url() const
 
375
{
 
376
  return m_url;
 
377
} // item_class::get_url()
344
378
 
345
379
/*----------------------------------------------------------------------------*/
346
380
/**
418
452
  find_hierarchy( hierarchy );
419
453
 
420
454
  for ( super_class = hierarchy.begin();
421
 
        ( super_class != hierarchy.end() ) && result; super_class++)
 
455
        ( super_class != hierarchy.end() ) && result; ++super_class)
422
456
    {
423
457
      field_iterator it;
424
458
 
425
459
      for ( it = (*super_class)->field_begin();
426
 
            ( it != (*super_class)->field_end() ) && result; it++ )
 
460
            ( it != (*super_class)->field_end() ) && result; ++it )
427
461
        if ( fields.find(it->get_name()) != fields.end() )
428
462
          {
429
463
            result = false;
510
544
void bf::item_class::copy( const item_class& that )
511
545
{
512
546
  m_class_name     = that.m_class_name;
 
547
  m_description    = that.m_description;
 
548
  m_url            = that.m_url;
513
549
  m_category       = that.m_category;
514
550
  m_color          = that.m_color;
515
551
  m_fixable        = that.m_fixable;
516
552
  m_super_classes  = that.m_super_classes;
517
553
  m_default_value  = that.m_default_value;
 
554
  m_removed_fields = that.m_removed_fields;
518
555
 
519
556
  field_map_type::const_iterator it;
520
557
 
522
559
    m_field[it->first] = it->second->clone();
523
560
} // item_class::copy()
524
561
 
 
562
/*----------------------------------------------------------------------------*/
 
563
/**
 
564
 * \brief Get the description of a field, given its name.
 
565
 * \param field_name The name of the field.
 
566
 */
 
567
const bf::type_field*
 
568
bf::item_class::search_field( const std::string& field_name ) const
 
569
{
 
570
  field_map_type::const_iterator it = m_field.find(field_name);
 
571
  const bf::type_field* result = NULL;
 
572
 
 
573
  if ( it != m_field.end() )
 
574
    result = it->second;
 
575
  else
 
576
    {
 
577
      const_super_class_iterator it_p;
 
578
 
 
579
      for ( it_p=super_class_begin();
 
580
            (result == NULL) && it_p!=super_class_end(); ++it_p )
 
581
        result = it_p->search_field(field_name);
 
582
    }
 
583
 
 
584
  return result;
 
585
} // item_class::search_field()
 
586
 
 
587
/*----------------------------------------------------------------------------*/
 
588
/**
 
589
 * \brief Get all the names of the fields whose values are set by this class and
 
590
 *        its super classes.
 
591
 * \param f (out) The names of the fields.
 
592
 */
 
593
void bf::item_class::get_removed_fields_names_in_hierarchy
 
594
( std::list<std::string>& f ) const
 
595
{
 
596
  std::copy
 
597
    ( m_removed_fields.begin(), m_removed_fields.end(),
 
598
      std::front_inserter(f) );
 
599
 
 
600
  const_super_class_iterator it;
 
601
 
 
602
  for ( it=super_class_begin(); it!=super_class_end(); ++it )
 
603
    it->get_removed_fields_names_in_hierarchy(f);
 
604
} // item_class::get_removed_fields_names_in_hierarchy()
 
605
 
 
606
/*----------------------------------------------------------------------------*/
 
607
/**
 
608
 * \brief Get all the names of the fields of this class and its super classes.
 
609
 * \param f (out) The names of the fields.
 
610
 */
 
611
void bf::item_class::get_all_field_names_in_hierarchy
 
612
( std::list<std::string>& f ) const
 
613
{
 
614
  std::transform( m_field.begin(), m_field.end(), std::front_inserter(f),
 
615
                  claw::const_pair_first<field_map_type::value_type>() );
 
616
 
 
617
  const_super_class_iterator it;
 
618
 
 
619
  for ( it=super_class_begin(); it!=super_class_end(); ++it )
 
620
    it->get_all_field_names_in_hierarchy(f);
 
621
} // item_class::get_all_field_names_in_hierarchy()