2005/5/10

     
 

CfgScript Properties Type

artefaktur

| Any Type | Basic Types | Object Types | Array Types | Enum Type | Props Type |

Property provides an hierarchical string indexed container.


Content of this chapter:

   The Props class
   PropsLiteral
   Samples



 The Props class

The  acdk::cfgscript::Props class implements the basic structures as dictionaries in CfgScript.
Although designed for usage in CfgScript, the Props class is also very handy to be used directly in C++ as an enhanced property class.


Props myprops = new Props();
myprops.set("first", 1);
myprops.set("second", new StringBuffer("asdf"));

The same can be expressed in more easier way:


Props myprops = new Props();
myprops.first =  1;
myprops.second =  new StringBuffer("asdf");

The implementation of local variables and member variables CfgScript classes are implemented as Props.
Inside a script the variable __props represents all local defined variables:

// demonstration that local variables are just
// entries in the __props Props
int i = 43;
{
  // local variable
  int i = 42;
  // local variable
  String s = "Hallo";
  __script.assertTest(__props.i == i); // always true
  __script.assertTest(i  == __props.get("i"));// always true
  // accessing the parent scope 
  __script.assertTest(43 == __props.getParentProps().i);
}

C++ DMI Note:
Props overload the peek and poke (reading and writing object member) to access directly the contained property values, whereas the keys are mapped as object members.

 PropsLiteral

PropsLiteral
: '{' [ PropsLiterals ] '}'
;

PropsLiterals
: PropsLiteralValue [ ',' PropsLiterals ]
;

PropsLiteralValue
: Identifier ':'  Expression
;


 Samples


Props props  = {
  a: 1, // contains atomar type
  b: [ 42, 43 ], // contains an array
  
  c: { 
    d: "ACDK",
    e: [ "a", "b", "c" ],
    f: "${a.b}",
    g: "${place.getLocation()}"
  } // contains a substructur
};
out.println(props.asCfgScriptLiteral("Test"));