28 #include <type_traits>
55 bool match(
const Properties&,
const Ex::iterator&,
bool ignore_parent_rel=
false,
bool ignore_properties=
false)
const;
70 typedef std::pair<std::string, Ex::iterator>
kvpair_t;
159 virtual void latex(std::ostream&)
const;
161 virtual std::string
name()
const=0;
207 virtual std::string
name()
const
212 return std::string(
"Inherit");
221 virtual std::string
name()
const
223 return std::string(
"PropertyInherit");
245 typedef internal_property_map_t::iterator
iterator;
265 typedef std::multimap<nset_t::iterator, pat_prop_pair_t, nset_it_less>
property_map_t;
283 template<
class T>
const T*
get(Ex::iterator,
bool ignore_parent_rel=
false)
const;
284 template<
class T>
const T*
get(Ex::iterator,
int& serialnum,
bool doserial=
true,
bool ignore_parent_rel=
false)
const;
286 template<
class T>
const T*
get(Ex::iterator,
const std::string& label)
const;
287 template<
class T>
const T*
get(Ex::iterator,
int& serialnum,
const std::string& label,
bool doserial=
true)
const;
289 template<
class T>
const T*
get(Ex::iterator, Ex::iterator,
bool ignore_parent_rel=
false)
const;
290 template<
class T>
const T*
get(Ex::iterator, Ex::iterator,
int&,
int&,
bool ignore_parent_rel=
false)
const;
296 std::pair<const T*, const pattern *>
get_with_pattern(Ex::iterator,
int& serialnum,
297 const std::string& label,
298 bool doserial=
true,
bool ignore_parent_rel=
false)
const;
302 const std::string& label,
303 bool doserial=
true,
bool ignore_parent_rel=
false)
const;
307 template<
class T> Ex::iterator
head(Ex::iterator,
bool ignore_parent_rel=
false)
const;
338 return get<T>(it, tmp,
false, ignore_parent_rel);
342 const T*
Properties::get(Ex::iterator it,
int& serialnum,
bool doserial,
bool ignore_parent_rel)
const
344 auto ret = get_with_pattern<T>(it, serialnum,
"", doserial, ignore_parent_rel);
350 bool doserial,
bool ignore_parent_rel)
const
354 auto ret = get_with_pattern_ext<T>(it, *compptr, serialnum, label, doserial, ignore_parent_rel);
361 int& serialnum,
const std::string& label,
362 bool doserial,
bool ignore_parent_rel)
const
364 std::pair<const T*, const pattern *> ret;
371 std::pair<property_map_t::const_iterator, property_map_t::const_iterator> pit=
props.equal_range(it->name_only());
376 bool wildcards=
false;
381 bool ignore_properties=
false;
382 if(std::is_same<T, Accent>::value)
383 ignore_properties=
true;
386 property_map_t::const_iterator walk=pit.first;
387 while(walk!=pit.second) {
388 if(wildcards==(*walk).second.first->children_wildcard()) {
390 ret.first=
dynamic_cast<const T *
>((*walk).second.second);
392 if((*walk).second.first->match_ext(*
this, it, comp, ignore_parent_rel, ignore_properties)) {
393 ret.second=(*walk).second.first;
398 serialnum=
serial_number( (*walk).second.second, (*walk).second.first );
406 else if(
dynamic_cast<const Inherit<T> *
>((*walk).second.second))
411 if(!wildcards && !ret.first) {
420 if(std::is_same<T, LaTeXForm>::value)
424 if(!ret.first && inherits) {
426 Ex::sibling_iterator sib=it.begin();
427 while(sib!=it.end()) {
428 std::pair<const T*, const pattern *> tmp=get_with_pattern<T>((Ex::iterator)(sib), serialnum, label, doserial);
442 const T* Properties::get(Ex::iterator it,
const std::string& label)
const
445 return get<T>(it, tmp, label,
false);
449 const T* Properties::get(Ex::iterator it,
int& serialnum,
const std::string& label,
bool doserial)
const
451 auto ret=get_with_pattern<T>(it, serialnum, label, doserial,
false);
456 const T* Properties::get(Ex::iterator it1, Ex::iterator it2,
bool ignore_parent_rel)
const
459 return get<T>(it1,it2,tmp1,tmp2, ignore_parent_rel);
463 const T* Properties::get(Ex::iterator it1, Ex::iterator it2,
int& serialnum1,
int& serialnum2,
bool ignore_parent_rel)
const
469 bool inherits1=
false, inherits2=
false;
470 std::pair<property_map_t::const_iterator, property_map_t::const_iterator> pit1=props.equal_range(it1->name_only());
471 std::pair<property_map_t::const_iterator, property_map_t::const_iterator> pit2=props.equal_range(it2->name_only());
473 property_map_t::const_iterator walk1=pit1.first;
474 while(walk1!=pit1.second) {
475 if((*walk1).second.first->match(*
this, it1, ignore_parent_rel)) {
476 ret1=
dynamic_cast<const T *
>((*walk1).second.second);
478 property_map_t::const_iterator walk2=pit2.first;
479 while(walk2!=pit2.second) {
480 if((*walk2).second.first->match(*
this, it2, ignore_parent_rel)) {
481 ret2=
dynamic_cast<const T *
>((*walk2).second.second);
483 if(ret1==ret2 && walk1!=walk2) {
484 serialnum1=serial_number( (*walk1).second.second, (*walk1).second.first );
485 serialnum2=serial_number( (*walk2).second.second, (*walk2).second.first );
503 if(!found && (inherits1 || inherits2)) {
504 Ex::sibling_iterator sib1, sib2;
505 if(inherits1) sib1=it1.begin();
507 bool keepgoing1=
true;
509 bool keepgoing2=
true;
510 if(inherits2) sib2=it2.begin();
513 const T* tmp=get<T>((Ex::iterator)(sib1), (Ex::iterator)(sib2), serialnum1, serialnum2, ignore_parent_rel);
519 if(!inherits2 || ++sib2==it2.end())
523 if(!inherits1 || ++sib1==it1.end())
535 Ex::iterator Properties::head(Ex::iterator it,
bool ignore_parent_rel)
const
539 if(get<PropertyInherit>(dn, ignore_parent_rel)) {
A generic tree comparison class which will take into account index contractions and will also keep tr...
Definition: Compare.hh:192
Basic storage class for symbolic mathemematical expressions.
Definition: Storage.hh:142
If a property X derives from Inherit<Y>, and get<Y> is called on an object which has an X property (b...
Definition: Props.hh:204
virtual ~Inherit()
Definition: Props.hh:206
virtual std::string name() const
Definition: Props.hh:207
internal_property_map_t store
Definition: Props.hh:247
std::map< std::string, property *(*)()> internal_property_map_t
Definition: Props.hh:244
internal_property_map_t::iterator iterator
Definition: Props.hh:245
~registered_property_map_t()
Definition: Props.cc:175
Class holding a collection of properties attached to expressions.
Definition: Props.hh:237
void insert_list_prop(const std::vector< Ex > &, const list_property *)
Definition: Props.cc:435
Ex::iterator head(Ex::iterator, bool ignore_parent_rel=false) const
Definition: Props.hh:535
std::pair< pattern *, const property * > pat_prop_pair_t
Definition: Props.hh:256
std::string master_insert(Ex proptree, const property *thepropbase)
Register a property for the indicated Ex.
Definition: Props.cc:580
std::pair< const T *, const pattern * > get_with_pattern_ext(Ex::iterator, Ex_comparator &, int &serialnum, const std::string &label, bool doserial=true, bool ignore_parent_rel=false) const
Definition: Props.hh:360
pattern_map_t pats
Definition: Props.hh:280
registered_property_map_t registered_properties
Definition: Props.hh:255
bool check_label(const property *, const std::string &) const
Definition: Props.cc:643
std::multimap< const property *, pattern * > pattern_map_t
Definition: Props.hh:266
void register_property(property *(*)(), const std::string &name)
Registering properties.
Definition: Props.cc:180
std::multimap< nset_t::iterator, pat_prop_pair_t, nset_it_less > property_map_t
We keep two multi-maps: one from the pattern to the property (roughly) and one from the property to t...
Definition: Props.hh:265
bool has(const property *, Ex::iterator)
Definition: Props.cc:140
Ex_comparator * create_comparator() const
Definition: Props.cc:653
std::pair< const T *, const pattern * > get_with_pattern(Ex::iterator, int &serialnum, const std::string &label, bool doserial=true, bool ignore_parent_rel=false) const
General property finder, which will return not only the property but also the pattern which matched t...
Definition: Props.hh:349
void destroy_comparator(Ex_comparator *) const
Definition: Props.cc:658
const T * get(Ex::iterator, bool ignore_parent_rel=false) const
Normal search: given a pattern, get its property if any.
Definition: Props.hh:335
void insert_prop(const Ex &, const property *)
Definition: Props.cc:349
property_map_t props
The following two maps own the pointers to the properties and patterns stored in them; use clear() to...
Definition: Props.hh:279
int serial_number(const property *, const pattern *) const
Definition: Props.cc:530
void clear()
Definition: Props.cc:156
PropertyInherit is like Inherit<T> for all properties.
Definition: Props.hh:219
virtual std::string name() const
Definition: Props.hh:221
Arguments to properties get parsed into a keyval_t structure.
Definition: Props.hh:68
kvlist_t::const_iterator const_iterator
Definition: Props.hh:73
std::list< kvpair_t > kvlist_t
Definition: Props.hh:71
void push_back(const kvpair_t &)
Definition: Props.cc:217
const_iterator end() const
Definition: Props.cc:212
kvlist_t keyvals
Definition: Props.hh:85
kvlist_t::iterator iterator
Definition: Props.hh:74
const_iterator begin() const
Definition: Props.cc:207
std::pair< std::string, Ex::iterator > kvpair_t
Definition: Props.hh:70
kvpair_t value_type
Definition: Props.hh:75
void erase(iterator)
Definition: Props.cc:222
const_iterator find(const std::string &) const
Definition: Props.cc:185
std::string label
Definition: Props.hh:187
virtual bool parse(Kernel &, std::shared_ptr< Ex >, keyval_t &) override
Definition: Props.cc:320
Something cannot be both a list property and a normal property at the same time, so we can safely inh...
Definition: Props.hh:193
bool match(const Properties &, const Ex::iterator &, bool ignore_parent_rel=false, bool ignore_properties=false) const
Match a pattern to an expression.
Definition: Props.cc:43
bool match_ext(const Properties &, const Ex::iterator &, Ex_comparator &comp, bool ignore_parent_rel=false, bool ignore_properties=false) const
As match, but using a comparator object which is externally provided, so that the caller can use the ...
Definition: Props.cc:49
Ex obj
Definition: Props.hh:63
bool children_wildcard() const
Definition: Props.cc:132
pattern()
Definition: Props.cc:34
Base class for all properties, handling argument parsing and defining the interface.
Definition: Props.hh:127
virtual match_t equals(const property *) const
Definition: Props.cc:315
property(bool hidden=false)
Definition: Props.cc:228
virtual bool parse(Kernel &, keyval_t &keyvals)
Definition: Props.cc:243
virtual void latex(std::ostream &) const
Display the property on the stream.
Definition: Props.cc:305
bool parse_to_keyvals(const Ex &, keyval_t &)
Definition: Props.cc:279
virtual std::string unnamed_argument() const
Definition: Props.cc:310
bool parse_one_argument(Ex::iterator arg, keyval_t &keyvals)
Definition: Props.cc:259
bool hidden(void) const
Definition: Props.cc:238
bool hidden_
Definition: Props.hh:181
virtual ~property()
Definition: Props.hh:130
virtual std::string name() const =0
match_t
Definition: Props.hh:170
@ exact_match
Definition: Props.hh:170
@ no_match
Definition: Props.hh:170
@ id_match
Definition: Props.hh:170
virtual void validate(const Kernel &, const Ex &) const
Definition: Props.cc:255
Functions to handle the exchange properties of two or more symbols in a product.
Definition: Adjform.cc:83