![]() |
赤紫蘇2.リファレンス |
||
属性 |
|||
akaxiso2.0-beta2 | |||
|
|||
属性の定義 属性の定義は、aka:sequence、aka:allに対して行うことができます。leafクラス内の、void model()メソッド内で、以下のstruct attributeを使って定義します。値クラスのメンバが、属性値となります。 struct attritbute { template<class P, class V> attribute(const std::string &tagname, V P::*member); template<class P, class V, class VL> attribute(const std::string &tagname, V P::* member, const VL&); void set_default(const std::string &defval); void required(bool required); }; struct attributeのコンストラクタがattributeの定義に用いられます。 また、set_default()メソッド、required()メソッドを用いることで、デフォルト値の指定、出現頻度の指定をすることができます。 set_default()と、required()の使用は排他となります。これは、XMLスキーマの仕様に基づくものです。 固定値属性 固定値(fixed)の定義は、struct fixed_attribute<>テンプレートを用いて行います。 template<class V> struct fixed_attribute{ fixed_attribute(const std::string &tagname, const std::string &fixed_value); template<class VL> fixed_attribute(const std::string &tagname, const std::string &fixed_value, const VL &); }; 固定値の場合、値が決まっているため、クラスに対応するメンバを持つ必要がありません。固定値アトリビュートの定義は、staticなオブジェクトにより行われ、(デ)シリアライズの時のみ、使用されます。 ワイルドカードアトリビュート ワイルドカードアトリビュート(xs:anyAttribute)は、以下の形式で、指定します。 template<class P> void any_attribute(any_attributes P::*member); 例 以下に、aka:sequence型のstruct fooに対して、アトリビュートを定義した例を示します。 struct foo { std::string attribute_; std::string required_attr_; std::string default_attr_; aka::any_attribute any_attr_; }; struct foo_leaf { void model() { attribute("attribute", &foo::attribute_); // 通常の属性 attribute("required_attr", &foo::required_attr).required(true); // use="required" attribute("default_attr", &foo::default_attr).set_default("default_value"); // defaultが指定されている fixed_attribute<std::string>("fixed_attr", "fixed_attr_value"); // use="fixed", 固定値が指定されている。 any_attribute(foo::any_attr_); // ワイルドカードアトリビュート } }; |