2
2
Bear Engine - Editor library
4
Copyright (C) 2005-2009 Julien Jorge, Sebastien Angibaud
4
Copyright (C) 2005-2010 Julien Jorge, Sebastien Angibaud
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
136
136
/*----------------------------------------------------------------------------*/
138
* \brief Get the name of the class.
138
* \brief Set the description of the class.
139
* \param desc The description of the class.
141
void bf::item_class::set_description( const std::string& desc )
143
m_description = desc;
144
} // item_class::set_description()
146
/*----------------------------------------------------------------------------*/
148
* \brief Set the url where a documentation of the class can be found.
149
* \param url The url.
151
void bf::item_class::set_url( const std::string& url )
154
} // item_class::set_url()
156
/*----------------------------------------------------------------------------*/
158
* \brief Set the name of the class.
139
159
* \param class_name The name of the class.
141
161
void bf::item_class::set_class_name( const std::string& class_name )
261
281
std::string bf::item_class::get_default_value( const std::string& f ) const
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);
267
286
if ( it!=m_default_value.end() )
268
287
result = it->second;
288
307
/*----------------------------------------------------------------------------*/
309
* \brief Indicate that a field of the parent classes is defined by this class.
310
* \param f The name of the field.
312
void bf::item_class::add_removed_field( const std::string& f )
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() );
318
m_removed_fields.push_back(f);
319
} // item_class::add_removed_field()
321
/*----------------------------------------------------------------------------*/
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.
293
326
void bf::item_class::get_field_names_in_hierarchy
294
327
( std::list<std::string>& f ) const
296
std::transform( m_field.begin(), m_field.end(), std::front_inserter(f),
297
claw::const_pair_first<field_map_type::value_type>() );
299
const_super_class_iterator it;
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;
332
get_all_field_names_in_hierarchy(fields);
333
get_removed_fields_names_in_hierarchy(removed);
340
( fields.begin(), fields.end(), removed.begin(), removed.end(),
341
std::back_inserter(f) );
303
344
} // item_class::get_field_names_in_hierarchy()
305
346
/*----------------------------------------------------------------------------*/
320
361
/*----------------------------------------------------------------------------*/
322
* \brief Get the description of a field, given its name.
323
* \param field_name The name of the field.
325
const bf::type_field*
326
bf::item_class::search_field( const std::string& field_name ) const
328
field_map_type::const_iterator it = m_field.find(field_name);
329
const bf::type_field* result = NULL;
331
if ( it != m_field.end() )
335
const_super_class_iterator it_p;
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);
343
} // item_class::search_field()
363
* \brief Get the description of the class.
365
const std::string& bf::item_class::get_description() const
367
return m_description;
368
} // item_class::get_description()
370
/*----------------------------------------------------------------------------*/
372
* \brief Get the url of the documentation of the class.
374
const std::string& bf::item_class::get_url() const
377
} // item_class::get_url()
345
379
/*----------------------------------------------------------------------------*/
418
452
find_hierarchy( hierarchy );
420
454
for ( super_class = hierarchy.begin();
421
( super_class != hierarchy.end() ) && result; super_class++)
455
( super_class != hierarchy.end() ) && result; ++super_class)
423
457
field_iterator it;
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() )
510
544
void bf::item_class::copy( const item_class& that )
512
546
m_class_name = that.m_class_name;
547
m_description = that.m_description;
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;
519
556
field_map_type::const_iterator it;
522
559
m_field[it->first] = it->second->clone();
523
560
} // item_class::copy()
562
/*----------------------------------------------------------------------------*/
564
* \brief Get the description of a field, given its name.
565
* \param field_name The name of the field.
567
const bf::type_field*
568
bf::item_class::search_field( const std::string& field_name ) const
570
field_map_type::const_iterator it = m_field.find(field_name);
571
const bf::type_field* result = NULL;
573
if ( it != m_field.end() )
577
const_super_class_iterator it_p;
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);
585
} // item_class::search_field()
587
/*----------------------------------------------------------------------------*/
589
* \brief Get all the names of the fields whose values are set by this class and
591
* \param f (out) The names of the fields.
593
void bf::item_class::get_removed_fields_names_in_hierarchy
594
( std::list<std::string>& f ) const
597
( m_removed_fields.begin(), m_removed_fields.end(),
598
std::front_inserter(f) );
600
const_super_class_iterator it;
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()
606
/*----------------------------------------------------------------------------*/
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.
611
void bf::item_class::get_all_field_names_in_hierarchy
612
( std::list<std::string>& f ) const
614
std::transform( m_field.begin(), m_field.end(), std::front_inserter(f),
615
claw::const_pair_first<field_map_type::value_type>() );
617
const_super_class_iterator it;
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()