赤紫蘇2.リファレンス

 aka:sequence メンバ定義(単純型)


XML-Schemaの要素である<xs:sequence>は、クラスのメンバを用いて、定義します。

以下に例を示します。
struct fooには、std::string型のmember_ メンバがあります。これを、タグ名"member"でシリアライズできるようにします。

struct foo { // (デ)シリアライズされるクラス
 std::string member_;
};

namespace xiso {
 struct leaf<foo> {
  void model() {
    member("member", &foo::member_,);
};

namespace aka {
 template<class T, class L> class sequence;
}

struct fooの型情報をstruct leaf<foo>を用いて定義します。このクラスは、aka::sequence<>を継承します。
また、void leaf<foo>::model()メソッド内にて、タグ名"member"と、foo::member_を対応付けます。
加えて、ポインタ型の定義(ptrmember())、any型の定義(any())を併せて行うことができます。

メンバの定義

model()メソッド内で、用いられるmember()は、aka::sequence<>クラス内で定義され、以下の書式を持ちます。

template<class P, class V>
  member(const std::string &tagname, V P::* m);

一番基本的な書式です。tagnameに加えて、mを用いてメンバを定義します。

template<class P, class V, class VL>
  member(const std::string &tagname, V P::* m, const VL&);

上記の書式に加え、leafクラスを明示的に、指定できます。

template<class P, class V>
member(const std::string &tagname, V P::* m, int minOccurs, int maxOccurs);

メンバが配列(コンテナ)の場合に用います。上記の書式に加え、minOccurs、maxOccursで出現頻度を指定します。minOccursに指定できる値は、0以上の整数です。また、maxOccursに指定できる値は、1以上の整数、もしくは、上限無しを意味するaka::unboundedです。

template<class P, class V, class VL>
  member(const std::string &tagname, V P::* m, const VL&, int minOccurs, int maxOccurs);

配列(コンテナ)に対し、leafクラスを明示的に指定する場合に使用します。

memberの指定に後続して、デフォルト値を設定できます。

void set_default(const std::string &defval);
namespace xiso {
 struct leaf<foo> { 
  void model() { 
   member("member", &foo::member_,).set_default("default string");
  };
}

ポインタ型の使用

ポインタ型のメンバを持つことができます。ただし、aka::deep_ptr<>によって、定義されるスマートポインタを用いる必要があります。

出現頻度は、自動的に、minOccurs=0, maxOccurs=1と限定されます。

ポインタ型のメンバには、ptrmember()を用います。

template<class P, class V>
ptrmember(const std::string &tagname, V P::* m); 

この形式では、第一引数は、タグ名、第二引数は、メンバへのポインタとなります。

template<class P, class V, class VL>
ptrmember(const std::string &tagname, V P::* m, const VL&) 

また、二つ目の形式では、第三引数として、leafクラスを指定することができます。
このleafクラスは、deep_ptr<>が用いる値(deep_ptr<T>の場合、T型>)に対するleafとなります。


ホームに戻る 赤紫蘇2プロジェクトページへ SourceForge.jp