All of lore.kernel.org
 help / color / mirror / Atom feed
From: kupcevic@sourceware.org <kupcevic@sourceware.org>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] conga/ricci include/Variable.h common/Variable ...
Date: 26 Sep 2006 01:04:21 -0000	[thread overview]
Message-ID: <20060926010421.3511.qmail@sourceware.org> (raw)

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<String, Variable> _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<String, Variable>::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<String, Variable>::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<const String, Variable> p(var.name(), var);
   pair<map<const String, Variable>::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 @@
 	<TITLE>Variables</TITLE>
 	<META NAME="GENERATOR" CONTENT="OpenOffice.org 1.1.2  (Linux)">
 	<META NAME="CREATED" CONTENT="20060410;13011800">
-	<META NAME="CHANGED" CONTENT="20060412;18255000">
+	<META NAME="CHANGED" CONTENT="20060626;16203200">
 </HEAD>
 <BODY LANG="en-US" DIR="LTR">
 <P>&lt;var/&gt; represents a variable. <BR>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???). <BR>Besides
+constraints, conditionals can be present as well:<BR> - 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???.<BR>
+- 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???.</P>
+<P>Types: 
 </P>
-<P>Types:</P>
 <UL>
 	<LI><P>int</P>
 	<UL>
@@ -99,4 +105,4 @@
 <P><BR><BR>
 </P>
 </BODY>
-</HTML>
\ No newline at end of file
+</HTML>



                 reply	other threads:[~2006-09-26  1:04 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060926010421.3511.qmail@sourceware.org \
    --to=kupcevic@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.