X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=ginac%2Farchive.cpp;h=2ae5162c60f533015322f65745fc1fd638463de0;hp=566c0c1319f80800a5ec6c05ae836646ad4e5567;hb=c3a7dda76e171bbd1e1418b3dab56df49920f721;hpb=9413cd14faaf2980de3884915e22a5beda068ecc diff --git a/ginac/archive.cpp b/ginac/archive.cpp index 566c0c13..2ae5162c 100644 --- a/ginac/archive.cpp +++ b/ginac/archive.cpp @@ -3,7 +3,7 @@ * Archiving of GiNaC expressions. */ /* - * GiNaC Copyright (C) 1999-2016 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2020 Johannes Gutenberg University Mainz, Germany * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -43,7 +43,7 @@ void archive::archive_ex(const ex &e, const char *name) // Add root node ID to list of archived expressions archived_ex ae = archived_ex(atomize(name), id); - exprs.push_back(ae); + exprs.emplace_back(ae); } @@ -357,17 +357,17 @@ bool archive_node::has_same_ex_as(const archive_node &other) const } archive_node::archive_node_cit - archive_node::find_first(const std::string &name) const -{ +archive_node::find_first(const std::string &name) const +{ archive_atom name_atom = a.atomize(name); for (auto i=props.begin(); i!=props.end(); ++i) if (i->name == name_atom) return i; - return props.end();; + return props.end(); } archive_node::archive_node_cit - archive_node::find_last(const std::string &name) const +archive_node::find_last(const std::string &name) const { archive_atom name_atom = a.atomize(name); for (auto i=props.end(); i!=props.begin();) { @@ -378,26 +378,43 @@ archive_node::archive_node_cit return props.end(); } +archive_node::archive_node_cit_range +archive_node::find_property_range(const std::string &name1, const std::string &name2) const +{ + archive_atom name1_atom = a.atomize(name1), + name2_atom = a.atomize(name2); + archive_node_cit_range range = {props.end(), props.end()}; + for (auto i=props.begin(); i!=props.end(); ++i) { + if (i->name == name1_atom && range.begin == props.end()) { + range.begin = i; + } + if (i->name == name2_atom && range.begin != props.end()) { + range.end = i + 1; + } + } + return range; +} + void archive_node::add_bool(const std::string &name, bool value) { - props.push_back(property(a.atomize(name), PTYPE_BOOL, value)); + props.emplace_back(property(a.atomize(name), PTYPE_BOOL, value)); } void archive_node::add_unsigned(const std::string &name, unsigned value) { - props.push_back(property(a.atomize(name), PTYPE_UNSIGNED, value)); + props.emplace_back(property(a.atomize(name), PTYPE_UNSIGNED, value)); } void archive_node::add_string(const std::string &name, const std::string &value) { - props.push_back(property(a.atomize(name), PTYPE_STRING, a.atomize(value))); + props.emplace_back(property(a.atomize(name), PTYPE_STRING, a.atomize(value))); } void archive_node::add_ex(const std::string &name, const ex &value) { // Recursively create an archive_node and add its ID to the properties of this node archive_node_id id = a.add_node(archive_node(a, value)); - props.push_back(property(a.atomize(name), PTYPE_NODE, id)); + props.emplace_back(property(a.atomize(name), PTYPE_NODE, id)); } @@ -455,8 +472,7 @@ bool archive_node::find_string(const std::string &name, std::string &ret, unsign return false; } -void archive_node::find_ex_by_loc(archive_node_cit loc, ex &ret, lst &sym_lst) - const +void archive_node::find_ex_by_loc(archive_node_cit loc, ex &ret, lst &sym_lst) const { ret = a.get_node(loc->value).unarchive(sym_lst); } @@ -515,9 +531,9 @@ void archive_node::get_properties(propinfovector &v) const ++a; } if (!found) - v.push_back(property_info(type, name)); + v.emplace_back(property_info(type, name)); i++; - } + } } static synthesize_func find_factory_fcn(const std::string& name)