00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef VCSN_XML_CONTEXTS_RW_HXX
00019 # define VCSN_XML_CONTEXTS_RW_HXX
00020
00021 # include <vaucanson/xml/builders.hh>
00022
00023 namespace vcsn
00024 {
00025 namespace xml
00026 {
00030 template <typename T>
00031 SeriesSemiringHandler<T>::SeriesSemiringHandler (xercesc::SAX2XMLReader* parser,
00032 Handler& root,
00033 T& semiring)
00034 : Handler(parser, root),
00035 semiring_(semiring),
00036 ssemiringh_(0),
00037 monoidh_(0),
00038 unsuph_(parser, *this)
00039 {
00040 }
00041
00042 template <typename T>
00043 void
00044 SeriesSemiringHandler<T>::start (const XMLCh* const,
00045 const XMLCh* const localname,
00046 const XMLCh* const,
00047 const xercesc::Attributes& attrs)
00048 {
00049 if (xercesc::XMLString::equals(eq_.semiring, localname))
00050 {
00051 ssemiringh_ = builders::create_semiringh(semiring_.semiring(), attrs, parser_, *this);
00052 parser_->setContentHandler(ssemiringh_);
00053 }
00054 else if (xercesc::XMLString::equals(eq_.monoid, localname))
00055 {
00056 monoidh_ = builders::create_monoidh(const_cast <typename T::monoid_t&>(semiring_.monoid()), attrs, parser_, *this);
00057 parser_->setContentHandler(monoidh_);
00058 }
00059 else
00060 error::token(localname);
00061 }
00062
00063 template <typename T>
00064 void
00065 SeriesSemiringHandler<T>::end (const XMLCh* const,
00066 const XMLCh* const localname,
00067 const XMLCh* const)
00068 {
00069 if (xercesc::XMLString::equals(eq_.semiring, localname))
00070 parser_->setContentHandler(&root_);
00071 else
00072 error::token(localname);
00073 delete ssemiringh_;
00074 delete monoidh_;
00075 }
00076
00077 namespace builders
00078 {
00079 template <typename S, typename K, typename T>
00080 typename TRANStype::semiring_t*
00081 create_semiring (TRANStype&,
00082 const XMLCh* const,
00083 const xercesc::Attributes&)
00084 {
00085 typename TRANStype::semiring_t::monoid_t::alphabet_t at;
00086 typename TRANStype::semiring_t::monoid_t md(at);
00087 typename TRANStype::semiring_t::semiring_t ssg;
00088 typedef typename TRANStype::semiring_t semiring_t;
00089 semiring_t* semiring = new semiring_t(ssg, md);
00090
00091 return semiring;
00092 }
00093
00094 template <typename S, typename T>
00095 Handler*
00096 create_semiringh(TRANSsemiring& semiring,
00097 const xercesc::Attributes&,
00098 xercesc::SAX2XMLReader* parser,
00099 Handler& root)
00100 {
00101 return new SeriesSemiringHandler<TRANSsemiring >(parser, root, semiring);
00102 }
00103
00104 }
00105
00109 namespace builders
00110 {
00111 template <typename S, typename T>
00112 const char* get_semiring_operations(const vcsn::algebra::Series<S, T>&)
00113 {
00114 return "SHOULD not append";
00115 }
00116 }
00117
00118 namespace builders
00119 {
00120 template <typename S, typename K, typename T>
00121 void
00122 create_semiring_node(const TRANStype& aut,
00123 xercesc::DOMDocument* doc,
00124 xercesc::DOMElement* root)
00125 {
00126 xercesc::DOMElement* node = tools::create_element(doc, "semiring");
00127 tools::set_attribute(node, "type", "series");
00128 xercesc::DOMElement* semiringn = tools::create_element(doc, "semiring");
00129 xercesc::DOMElement* monoid = tools::create_element(doc, "monoid");
00130
00131 typedef typename TRANStype::semiring_elt_t::semiring_elt_t semiring_elt_t;
00132 semiring_elt_t semiring;
00133 tools::set_attribute(semiringn, "set", get_semiring_set(semiring.value()));
00134 tools::set_attribute(semiringn, "operations", get_semiring_operations(semiring.structure()));
00135
00136 tools::set_attribute(monoid, "type", "free");
00137 tools::set_attribute(monoid, "genDescrip", "enum");
00138 tools::set_attribute(monoid, "genKind", algebra::letter_traits<typename TRANStype::semiring_t::monoid_t::alphabet_t::letter_t>::kind());
00139 typedef typename TRANStype::semiring_t::monoid_t::alphabet_t::const_iterator alphabet_iterator;
00140 for_all_letters(l, aut.series().semiring().monoid().alphabet())
00141 {
00142 std::ostringstream letter;
00143 xercesc::DOMElement* gen = tools::create_element(doc, "monGen");
00144 letter << *l;
00145 tools::set_attribute(gen, "value", letter.str());
00146 monoid->appendChild(gen);
00147 }
00148 tools::set_attribute(monoid, "genSort", get_monoid_gen_sort(*(aut.series().semiring().monoid().alphabet().begin())));
00149 node->appendChild(semiringn);
00150 node->appendChild(monoid);
00151 root->appendChild(node);
00152 }
00153 }
00154
00159 SParamTRANS
00160 WeightHandler<TRANSseries >::WeightHandler (xercesc::SAX2XMLReader* parser,
00161 Handler& root,
00162 TRANSseries param)
00163 : RegexpHandler<TRANSseries >(parser, root, param),
00164 weighth_(0)
00165 {
00166 end_ = eq_.weight;
00167 }
00168
00169 SParamTRANS
00170 void
00171 WeightHandler<TRANSseries >::start (const XMLCh* const,
00172 const XMLCh* const localname,
00173 const XMLCh* const,
00174 const xercesc::Attributes&)
00175 {
00176
00177
00178 if (!(weighth_ = create_weighth(localname)))
00179 error::token(localname);
00180 else
00181 parser_->setContentHandler(weighth_);
00182 }
00183
00184 SParamTRANS
00185 void
00186 WeightHandler<TRANSseries >::end (const XMLCh* const,
00187 const XMLCh* const localname,
00188 const XMLCh* const)
00189 {
00190
00191 using namespace xercesc;
00192 if (XMLString::equals(end_, localname))
00193 {
00194 TRANSseries s = algebra::identity_as<typename TRANSseries::value_t>::of(param_.structure());
00195 typename TRANSseries::semiring_elt_t w(weighth_->series());
00196 param_ = param_ * w;
00197
00198 parser_->setContentHandler(&root_);
00199 delete weighth_;
00200 }
00201 else
00202 error::token(localname);
00203 }
00204
00205 SParamTRANS
00206 RegexpHandler<typename WeightHandler<TRANSseries >::series_set_elt_t>*
00207 WeightHandler<TRANSseries >::create_weighth (const XMLCh* const localname)
00208 {
00209 using namespace xercesc;
00210 series_set_elt_t elt(param_.structure().semiring());
00211
00212 if (XMLString::equals(eq_.monElmt, localname))
00213 return builders::create_monElmth(parser_, *this, algebra::identity_as<typename series_set_elt_t::value_t>::of(elt.structure()));
00214 else if (XMLString::equals(eq_.star, localname))
00215 return new StarHandler<series_set_elt_t>(parser_, *this, algebra::identity_as<typename series_set_elt_t::value_t>::of(elt.structure()));
00216 else if (XMLString::equals(eq_.leftExtMul, localname))
00217 return new ExtMulHandler<series_set_elt_t>(parser_, *this, algebra::identity_as<typename series_set_elt_t::value_t>::of(elt.structure()), true);
00218 else if (XMLString::equals(eq_.rightExtMul, localname))
00219 return new ExtMulHandler<series_set_elt_t>(parser_, *this, algebra::identity_as<typename series_set_elt_t::value_t>::of(elt.structure()), false);
00220 else if (XMLString::equals(eq_.sum, localname))
00221 return new SumHandler<series_set_elt_t>(parser_, *this, algebra::identity_as<typename series_set_elt_t::value_t>::of(elt.structure()));
00222 else if (XMLString::equals(eq_.product, localname))
00223 return new ProductHandler<series_set_elt_t>(parser_, *this, algebra::identity_as<typename series_set_elt_t::value_t>::of(elt.structure()));
00224 else if (XMLString::equals(eq_.one, localname))
00225 return new AtomHandler<series_set_elt_t>(parser_, *this, algebra::identity_as<typename series_set_elt_t::value_t>::of(elt.structure()), eq_.one);
00226 else if (XMLString::equals(eq_.zero, localname))
00227 return new AtomHandler<series_set_elt_t>(parser_, *this, algebra::zero_as<typename series_set_elt_t::value_t>::of(elt.structure()), eq_.zero);
00228 else
00229 return 0;
00230 }
00231
00232 namespace builders
00233 {
00234 SParamTRANS
00235 RegexpHandler<TRANSseries >*
00236 create_weighth(xercesc::SAX2XMLReader* parser,
00237 RegexpHandler<TRANSseries >& root,
00238 TRANSseries param,
00239 const xercesc::Attributes&)
00240 {
00241 return new WeightHandler<TRANSseries >(parser, root, param);
00242 }
00243 }
00244 }
00245 }
00246
00247 #endif // !VCSN_XML_CONTEXTS_RW_HXX