23#ifndef GINAC_CONTAINER_H
24#define GINAC_CONTAINER_H
42template <
template <
class T,
class = std::allocator<T>>
class C>
72template <
template <
class T,
class = std::allocator<T>>
class C>
102 container(exvector::const_iterator b, exvector::const_iterator e)
116 bool info(
unsigned inf)
const override {
return inherited::info(inf); }
118 size_t nops()
const override {
return this->
seq.size(); }
119 ex op(
size_t i)
const override;
125 inherited::read_archive(
n, sym_lst);
128 auto range =
n.find_property_range(
"seq",
"seq");
129 this->
reserve(this->
seq, range.end - range.begin);
132 n.find_ex_by_loc(i, e, sym_lst);
133 this->
seq.emplace_back(e);
140 inherited::archive(
n);
141 for (
auto & i : this->
seq) {
149 STLT *newcont =
nullptr;
152 newcont->push_back(i->conjugate());
155 ex x = i->conjugate();
161 for (const_iterator j=this->
seq.begin(); j!=i; ++j) {
162 newcont->push_back(*j);
164 newcont->push_back(
x);
181 cont.push_back(i->real_part());
192 cont.push_back(i->imag_part());
209 char closebracket,
unsigned this_precedence,
210 unsigned upper_precedence = 0)
const;
214 void sort_(std::random_access_iterator_tag)
226 typename STLT::iterator p = std::unique(this->
seq.begin(), this->seq.end(),
ex_is_equal());
227 this->
seq.erase(p, this->
seq.end());
240 const_iterator
end()
const {
return this->
seq.end();}
241 const_reverse_iterator
rbegin()
const {
return this->
seq.rbegin();}
242 const_reverse_iterator
rend()
const {
return this->
seq.rend();}
253template <
template <
class T,
class = std::allocator<T>>
class C>
256 setflag(get_default_flags());
259template <
template <
class T,
class = std::allocator<T>>
class C>
263 printseq(
c, get_open_delim(),
',', get_close_delim(), precedence(), precedence()+1);
266template <
template <
class T,
class = std::allocator<T>>
class C>
269 c.s << std::string(level,
' ') << class_name() <<
" @" <<
this
270 << std::hex <<
", hash=0x" << hashvalue <<
", flags=0x" << flags << std::dec
271 <<
", nops=" <<
nops()
275 i->print(
c, level +
c.delta_indent);
278 c.s << std::string(level +
c.delta_indent,
' ') <<
"=====" << std::endl;
281template <
template <
class T,
class = std::allocator<T>>
class C>
284 printseq(
c,
'[',
',',
']', precedence(), precedence()+1);
287template <
template <
class T,
class = std::allocator<T>>
class C>
291 printseq(
c,
'(',
',',
')', precedence(), precedence()+1);
294template <
template <
class T,
class = std::allocator<T>>
class C>
304template <
template <
class T,
class = std::allocator<T>>
class C>
309 ensure_if_modifiable();
310 typename STLT::iterator it = this->seq.begin();
315template <
template <
class T,
class = std::allocator<T>>
class C>
327 if (!subsed.empty()) {
328 ex result(thiscontainer(subsed));
330 return ex_to<basic>(result).subs_one_level(
m,
options);
342template <
template <
class T,
class = std::allocator<T>>
class C>
349 it2 = o.
seq.begin(), it2end = o.
seq.end();
351 while (it1 != it1end && it2 != it2end) {
352 int cmpval = it1->compare(*it2);
358 return (it1 == it1end) ? (it2 == it2end ? 0 : -1) : 1;
361template <
template <
class T,
class = std::allocator<T>>
class C>
367 if (this->seq.size() != o.
seq.size())
370 const_iterator it1 = this->seq.begin(), it1end = this->seq.end(), it2 = o.
seq.begin();
371 while (it1 != it1end) {
372 if (!it1->is_equal(*it2))
381template <
template <
class T,
class = std::allocator<T>>
class C>
384 ensure_if_modifiable();
385 this->seq.push_front(b);
390template <
template <
class T,
class = std::allocator<T>>
class C>
393 ensure_if_modifiable();
394 this->seq.push_back(b);
399template <
template <
class T,
class = std::allocator<T>>
class C>
402 ensure_if_modifiable();
403 this->seq.pop_front();
408template <
template <
class T,
class = std::allocator<T>>
class C>
411 ensure_if_modifiable();
412 this->seq.pop_back();
417template <
template <
class T,
class = std::allocator<T>>
class C>
420 ensure_if_modifiable();
426template <
template <
class T,
class = std::allocator<T>>
class C>
429 ensure_if_modifiable();
430 sort_(
typename std::iterator_traits<typename STLT::iterator>::iterator_category());
441template <
template <
class T,
class = std::allocator<T>>
class C>
444 ensure_if_modifiable();
450template <
template <
class T,
class = std::allocator<T>>
class C>
452 char closebracket,
unsigned this_precedence,
453 unsigned upper_precedence)
const
455 if (this_precedence <= upper_precedence)
458 if (!this->seq.empty()) {
461 while (it != itend) {
462 it->print(
c, this_precedence);
466 it->print(
c, this_precedence);
469 if (this_precedence <= upper_precedence)
473template <
template <
class T,
class = std::allocator<T>>
class C>
485 STLT s(this->seq.begin(), cit);
486 this->reserve(s, this->seq.size());
489 s.push_back(subsed_ex);
Archiving of GiNaC expressions.
Assertion macro definition.
#define GINAC_ASSERT(X)
Assertion macro for checking invariances.
This class stores all properties needed to record/retrieve the state of one object of class basic (or...
std::vector< property >::const_iterator archive_node_cit
void add_ex(const std::string &name, const ex &value)
Add property of type "ex" to node.
This class is the ABC (abstract base class) of GiNaC's class hierarchy.
const basic & setflag(unsigned f) const
Set some status_flags.
virtual int compare_same_type(const basic &other) const
Returns order relation between two objects of same type.
Helper template for encapsulating the reserve() mechanics of STL containers.
container_storage(In b, In e)
static void reserve(STLT &, size_t)
container_storage(std::initializer_list< ex > il)
container_storage(size_t n, const ex &e)
Wrapper template for making GiNaC classes out of STL containers.
const_reverse_iterator rend() const
container(exvector::const_iterator b, exvector::const_iterator e)
static unsigned get_default_flags()
Specialization of container::get_default_flags() for lst.
STLT subschildren(const exmap &m, unsigned options=0) const
container(std::initializer_list< ex > il)
ex real_part() const override
const_reverse_iterator rbegin() const
bool is_equal_same_type(const basic &other) const override
Returns true if two objects of same type are equal.
virtual void printseq(const print_context &c, char openbracket, char delim, char closebracket, unsigned this_precedence, unsigned upper_precedence=0) const
Print sequence of contained elements.
const_iterator end() const
container & prepend(const ex &b)
Add element at front.
STLT::const_iterator const_iterator
ex conjugate() const override
void read_archive(const archive_node &n, lst &sym_lst) override
Load (deserialize) the object from an archive node.
const_iterator begin() const
void archive(archive_node &n) const override
Archive the object.
bool info(unsigned inf) const override
Information about the object.
size_t nops() const override
Number of operands/members.
void do_print_python_repr(const print_python_repr &c, unsigned level) const
container & remove_last()
Remove last element.
virtual ex thiscontainer(STLT &&v) const
Similar to duplicate(), but with a preset sequence (which gets pilfered).
STLT::const_reverse_iterator const_reverse_iterator
void sort_(std::random_access_iterator_tag)
container_storage< C >::STLT STLT
ex op(size_t i) const override
Return operand/member at position i.
container & sort()
Sort elements.
void sort_(std::input_iterator_tag)
unsigned precedence() const override
Return relative operator precedence (for parenthezing output).
container & unique()
Remove adjacent duplicate elements.
void do_print(const print_context &c, unsigned level) const
container & remove_all()
Remove all elements.
ex subs(const exmap &m, unsigned options=0) const override
Substitute a set of objects by arbitrary expressions.
ex & let_op(size_t i) override
Return modifiable operand/member at position i.
static char get_close_delim()
Specialization of container::get_close_delim() for lst.
container & remove_first()
Remove first element.
virtual ex thiscontainer(const STLT &v) const
Similar to duplicate(), but with a preset sequence.
void do_print_tree(const print_tree &c, unsigned level) const
static char get_open_delim()
Specialization of container::get_open_delim() for lst.
container & append(const ex &b)
Add element at back.
void do_print_python(const print_python &c, unsigned level) const
ex imag_part() const override
Lightweight wrapper for GiNaC's symbolic objects.
ex subs(const exmap &m, unsigned options=0) const
Base class for print_contexts.
Context for python-parsable output.
Context for python pretty-print output.
Context for tree-like output for debugging.
Definition of optimizing macros.
Interface to GiNaC's light-weight expression handles.
std::map< ex, ex, ex_is_less > exmap
bool are_ex_trivially_equal(const ex &e1, const ex &e2)
Compare two objects of class quickly without doing a deep tree traversal.
bool is_a(const basic &obj)
Check if obj is a T, including base classes.
size_t nops(const ex &thisex)
Definition of helper classes for expression output.
#define GINAC_DECLARE_REGISTERED_CLASS(classname, supername)
Macro for inclusion in the declaration of each registered class.