Revision 4c8b82e2 include/Template.h

View differences:

include/Template.h
19 19

  
20 20
#include <iostream>
21 21
#include <map>
22
#include <set>
22 23
#include <vector>
24
#include <string>
23 25

  
24 26
#include <libxml/tree.h>
25 27
#include <libxml/parser.h>
......
55 57
        separator    = t.separator;
56 58
        xml_root     = t.xml_root;
57 59

  
58
        attributes.clear();
59

  
60 60
        for (it = t.attributes.begin() ; it != t.attributes.end() ; it++)
61 61
        {
62 62
            attributes.insert(make_pair(it->first,(it->second)->clone()));
......
404 404
    /**
405 405
     *  Merges another Template, adding the new attributes and
406 406
     *  replacing the existing ones
407
     *
408 407
     *    @param from_tmpl the template to be merged
409 408
     */
410 409
     void merge(const Template * from_tmpl);
411 410

  
412
     /**
413
      * Deletes all restricted attributes
414
      */
415
     virtual void remove_restricted();
416

  
417
     /**
418
      * Deletes all the attributes, except the restricted ones
419
      */
420
     virtual void remove_all_except_restricted();
421

  
422
     /**
423
      *  @return true if the template defines one or more restricted attributes
424
      */
425
     virtual bool has_restricted();
426

  
427
     /**
428
      *  @return true if template is empty
429
      */
430
     bool empty()
431
     {
432
         return attributes.empty();
433
     }
411
    /**
412
     *  Check if the template can be safely merge with a base template. If a
413
     *  restricted attribute is found it is check that it has the same value in
414
     *  base.
415
     *    @param rs_attr the first restricted attribute found with a different
416
     *    value in base
417
     *    @param base template used to check restricted values.
418
     *
419
     *    @return true if a restricted attribute with a different value is found
420
     *    in the template
421
     *
422
     *   The version of this method without base template just look for any
423
     *   restricted attribute.
424
     */
425
    virtual bool check_restricted(string& rs_attr, const Template& base)
426
    {
427
        return false;
428
    }
429

  
430
    virtual bool check_restricted(string& rs_attr)
431
    {
432
        return false;
433
    }
434

  
435
    /**
436
     *  Removes a restricted attribute from the template. For vector attributes
437
     *  only restricted sub attributes are removed.
438
     */
439
    virtual void remove_restricted(){};
440

  
441
    /**
442
     *  @return true if template is empty
443
     */
444
    bool empty()
445
    {
446
        return attributes.empty();
447
    }
434 448

  
435 449
protected:
436 450
    /**
437 451
     *  The template attributes
438 452
     */
439
    multimap<string,Attribute *>    attributes;
453
    multimap<string,Attribute *> attributes;
440 454

  
441 455
    /**
442 456
     *  Builds a SingleAttribute from the given node
......
455 469
    Attribute* vector_xml_att(const xmlNode * node);
456 470

  
457 471
    /**
458
     * Stores the attributes as restricted, these attributes will be used in
459
     * Template::check
460
     * @param rattrs Attributes to restrict
461
     * @param restricted_attributes The attributes will be stored here
472
     *  Parses a list of restricted attributes in the form ATTRIBUTE_NAME or
473
     *  ATTRIBUTE_NAME/SUBATTRIBUTE.
474
     *    @param ras list of restricted attributes
475
     *    @param rattr_m result list of attributes indexed by ATTRIBUTE_NAME.
476
     *    RAs are stored:
477
     *      {
478
     *        RESTRICTED_ATTR_NAME => [ RESTRICTED_SUB_ATTRIBUTES ],
479
     *        ...
480
     *      }
481
     *    If the RA is Single the sub attribute list will be empty.
462 482
     */
463
    static void set_restricted_attributes(
464
            vector<const SingleAttribute *>& rattrs,
465
            vector<string>& restricted_attributes);
483
    static void parse_restricted(const vector<const SingleAttribute *>& ras,
484
        std::map<std::string, std::set<std::string> >& rattr_m);
466 485

  
467 486
    /**
468
     *  Checks the template for RESTRICTED ATTRIBUTES
469
     *    @param rs_attr the first restricted attribute found if any
470
     *    @return true if a restricted attribute is found in the template
487
     *  Removes a restricted attribute from the template. For vector attributes
488
     *  only restricted sub attributes are removed.
471 489
     */
472
    bool check(string& rs_attr, const vector<string> &restricted_attributes);
490
    void remove_restricted(
491
            const std::map<std::string, std::set<std::string> >& ras);
473 492

  
474 493
    /**
475
     * Deletes all restricted attributes
476
     */
477
    void remove_restricted(const vector<string> &restricted_attributes);
478

  
479
    /**
480
     * Deletes all the attributes, except the restricted ones
494
     *  Check if the template can be safely merge with a base template. If a
495
     *  restricted attribute is found it is check that it has the same value in
496
     *  base.
497
     *    @param rs_attr the first restricted attribute found with a different
498
     *    value in base
499
     *    @param base template used to check restricted values.
500
     *    @param ras list of restricted attributes.
501
     *
502
     *    @return true if a restricted attribute with a different value is found
503
     *    in the template
481 504
     */
482
    void remove_all_except_restricted(const vector<string> &restricted_attributes);
505
    bool check_restricted(string& rs_attr, const Template& base,
506
           const std::map<std::string, std::set<std::string> >& ras);
483 507

  
508
    bool check_restricted(string& rs_attr,
509
           const std::map<std::string, std::set<std::string> >& ras);
484 510
    /**
485 511
     * Updates the xml root element name
486 512
     *

Also available in: Unified diff