赤紫蘇2.リファレンス

aka:simplecontent

akaxiso2.0-beta1


aka:simplecontentは、xs:simpleContentに対応する赤紫蘇データモデルの要素です。

単純型を値として持つXML要素に対応します。また、単純型を拡張し、属性を持たせる用途にも使います。以下に例を示します。

<?xml version="1.0"?>
<example attribute="test">value</example>

<example>要素が、aka:simplecontentの例となります。単純型の値が、"value"となりますが、これに属性を与えています。

aka:simplecontent<>クラスの宣言は、以下のとおりです。

namespace aka {
  template<class T, class L=xiso::leaf<V> > class simlecontent;
}

class Tは値クラスの型です。Lはleafクラスであり、デフォルトとして、xiso::leaf<T>が割り当てられています。aka:simplecontent内で、単純型の値を定義するには、value()メソッドを用います。

template<class V, class P>
static void value(V P::* m);

属性の宣言については、11 属性をご参照ください。

例に示したXML文書に対応するaka:simplecontentの実装は、以下のとおりとなります。

struct example {
  std::string value_;
  std::string attribute_;
};

struct example_leaf : aka::simplecontent<example, example_leaf> {
  void model() {
    value(&example::value_);
    attribute("attribute", &example::attribute_);
  }
};

単純型の値として、固定値(fixed)を指定することもできます。

固定値を用いる場合には、value()メソッドの変わりに、以下のstruct fixed_value<>テンプレートクラスを用います。

template<class V>
struct fixed_value {
  fixed_value(const std::string &fixed);
  template<class VL>
  fixed_value(const std::string &fixed, const VL &);
};

はじめに挙げたXML文書例の、"value"が、固定値となる場合、実装例は以下のとおりです。

struct example {
  std::string attribute_;
};

struct example_leaf : aka::simplecontent<example, example_leaf> {
  void model() {
    fixed_value<std::string>("value");
    attribute("attribute", &example::attribute_);
  }
};


リファレンストップに戻る 赤紫蘇ホームページへ sourceforgeプロジェクトページへ