From mboxrd@z Thu Jan 1 00:00:00 1970 From: kupcevic@sourceware.org Date: 26 Sep 2006 01:04:21 -0000 Subject: [Cluster-devel] conga/ricci include/Variable.h common/Variable ... Message-ID: <20060926010421.3511.qmail@sourceware.org> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit CVSROOT: /cvs/cluster Module name: conga Changes by: kupcevic at sourceware.org 2006-09-26 01:04:21 Modified files: ricci/include : Variable.h ricci/common : Variable.cpp ricci/modules/storage: Props.h Props.cpp ricci/docs : variables.html Log message: ricci: add bool conditionals for variables Patches: http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/include/Variable.h.diff?cvsroot=cluster&r1=1.3&r2=1.4 http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/common/Variable.cpp.diff?cvsroot=cluster&r1=1.7&r2=1.8 http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/storage/Props.h.diff?cvsroot=cluster&r1=1.2&r2=1.3 http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/storage/Props.cpp.diff?cvsroot=cluster&r1=1.2&r2=1.3 http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/docs/variables.html.diff?cvsroot=cluster&r1=1.4&r2=1.5 --- conga/ricci/include/Variable.h 2006/08/10 22:53:07 1.3 +++ conga/ricci/include/Variable.h 2006/09/26 01:04:20 1.4 @@ -183,6 +183,16 @@ XMLObject xml() const; + + void set_conditional_bool_if(const String& bool_name); + String get_conditional_bool_if() const + { return _cond_bool_if; } + + void set_conditional_bool_ifnot(const String& bool_name); + String get_conditional_bool_ifnot() const + { return _cond_bool_ifnot; } + + // values getters and setters void set_value(long long value); @@ -217,6 +227,9 @@ bool _mutable; + String _cond_bool_if; + String _cond_bool_ifnot; + Validator _validator; }; // class Variable --- conga/ricci/common/Variable.cpp 2006/08/10 22:53:07 1.7 +++ conga/ricci/common/Variable.cpp 2006/09/26 01:04:20 1.8 @@ -45,9 +45,11 @@ _mutable = (xml.get_attr("mutable") == "true"); + // _validator = Validator(xml); // incoming constraints are not to be trusted anyhow - // _validator = Validator(xml); // incoming limits are not to be trusted anyhow - + // conditionals + _cond_bool_if = xml.get_attr("if_bool"); + _cond_bool_ifnot = xml.get_attr("ifnot_bool"); String type(xml.get_attr("type")); if (type == VARIABLE_INT) { @@ -239,6 +241,22 @@ {} +void +Variable::set_conditional_bool_if(const String& bool_name) +{ + if (name() == bool_name) + throw String("circular conditional: ") + bool_name; + _cond_bool_if = bool_name; +} + +void +Variable::set_conditional_bool_ifnot(const String& bool_name) +{ + if (name() == bool_name) + throw String("circular conditional: ") + bool_name; + _cond_bool_ifnot = bool_name; +} + long long Variable::get_int() const @@ -356,7 +374,9 @@ Variable::equal(const Variable& var) const { if (type() != var.type() || - name() != var.name()) + name() != var.name() || + get_conditional_bool_if() != var.get_conditional_bool_if() || + get_conditional_bool_ifnot() != var.get_conditional_bool_ifnot()) return false; switch (var.type()) { case Integer: @@ -391,7 +411,10 @@ if (name() != var.name()) throw String("different variable names"); if (type() != var.type()) - throw String("different variable types"); + throw String("invalid variable type"); + if (get_conditional_bool_if() != var.get_conditional_bool_if() || + get_conditional_bool_ifnot() != var.get_conditional_bool_ifnot()) + throw String("invalid bool conditional"); switch (var.type()) { case Integer: @@ -419,7 +442,7 @@ { XMLObject xml(VARIABLE_TAG); - xml.set_attr("name", _name); + xml.set_attr("name", name()); xml.set_attr("mutable", (_mutable)?"true":"false"); int i = 0; @@ -490,6 +513,11 @@ if (_mutable) _validator.export_params(xml); + if (!_cond_bool_if.empty()) + xml.set_attr("if_bool", _cond_bool_if); + if (!_cond_bool_ifnot.empty()) + xml.set_attr("ifnot_bool", _cond_bool_ifnot); + return xml; } --- conga/ricci/modules/storage/Props.h 2006/08/10 22:53:09 1.2 +++ conga/ricci/modules/storage/Props.h 2006/09/26 01:04:20 1.3 @@ -40,10 +40,11 @@ Props(const XMLObject&); virtual ~Props(); - const Variable& get(const String& name) const; - Variable& get(const String& name); + const Variable get(const String& name) const; void set(const Variable& var); + bool is_active(const Variable& var) const; + void validate() const; void validate(const Props& props) const; // validate props against *this @@ -55,6 +56,8 @@ std::map _vars; + void _set(const Variable& var); + }; --- conga/ricci/modules/storage/Props.cpp 2006/08/10 22:53:09 1.2 +++ conga/ricci/modules/storage/Props.cpp 2006/09/26 01:04:20 1.3 @@ -42,7 +42,7 @@ iter++) { try { Variable var(*iter); - set(var); + _set(var); } catch ( ... ) {} } } @@ -51,34 +51,55 @@ {} -const Variable& +const Variable Props::get(const String& name) const { map::const_iterator iter = _vars.find(name); if (iter == _vars.end()) - throw String("Props: no such variable") + name; + throw String("Props: no such variable ") + name; return iter->second; } -Variable& -Props::get(const String& name) +void +Props::set(const Variable& var) { - map::iterator iter = _vars.find(name); - if (iter == _vars.end()) - throw String("Props: no such variable - ") + name; - return iter->second; + // check conditionals + String c(var.get_conditional_bool_if()); + if (!c.empty()) + if (get(c).type() != Boolean) + throw String("non-boolean variable used as bool condition for variable ") + var.name(); + c = var.get_conditional_bool_ifnot(); + if (!c.empty()) + if (get(c).type() != Boolean) + throw String("non-boolean variable used as bool condition for variable ") + var.name(); + + // insert new variable + _set(var); } void -Props::set(const Variable& var) +Props::_set(const Variable& var) { pair p(var.name(), var); pair::iterator, bool> i = _vars.insert(p); - if (i.second == false) i.first->second = var; } +bool +Props::is_active(const Variable& var) const +{ + String c(var.get_conditional_bool_if()); + if (!c.empty()) + if (!get(c).get_bool()) + return false; + c = var.get_conditional_bool_ifnot(); + if (!c.empty()) + if (get(c).get_bool() == true) + return false; + return true; +} + void Props::validate() const { @@ -92,13 +113,15 @@ iter != _vars.end(); iter++) { const Variable& v1 = iter->second; - const Variable& v2 = props.get(iter->first); - if (v1.mutabl()) { - if (! v1.validate(v2) ) - throw ValidationError(); - } else { - if ( ! v1.equal(v2) ) - throw ValidationError(); + if (props.is_active(v1)) { + const Variable v2(props.get(iter->first)); + if (v1.mutabl()) { + if (! v1.validate(v2)) + throw ValidationError(); + } else { + if (! v1.equal(v2)) + throw ValidationError(); + } } } } --- conga/ricci/docs/variables.html 2006/07/12 18:27:26 1.4 +++ conga/ricci/docs/variables.html 2006/09/26 01:04:20 1.5 @@ -5,15 +5,21 @@ Variables - +

<var/> represents a variable.
It has ???name???, ???type??? and ???mutable??? attributes. Optionally, dependent on ???type???, it might have ???value??? attribute as well. If variable is ???mutable???, -it will have constraints (constraints depend on ???type???). +it will have constraints (constraints depend on ???type???).
Besides +constraints, conditionals can be present as well:
- If a variable +has an if_bool=???bool_var_name??? attribute, it is to be used only if +boolean variable named ???bool_var_name??? is set to ???true???.
+- If a variable has an ifnot_bool=???bool_var_name??? attribute, it is to +be used only if boolean variable named ???bool_var_name??? is set to +???false???.

+

Types:

-

Types:

  • int

      @@ -99,4 +105,4 @@



      - \ No newline at end of file +