From: Christian Bauer Date: Mon, 24 Jan 2000 20:53:56 +0000 (+0000) Subject: - renamed archive::dump() to archive::printraw() for consistency with the X-Git-Tag: release_0-5-0~46 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=a331d1fd814315cd934c4f0ebf0cf485dc52fe96 - renamed archive::dump() to archive::printraw() for consistency with the other classes - implemented archiving for the following classes: color, idx, coloridx, isospin - non-crational numbers are now stored in an integer-decoded format in archives --- diff --git a/Makefile.in b/Makefile.in index 4f1c9d61..0bef6006 100644 --- a/Makefile.in +++ b/Makefile.in @@ -354,7 +354,7 @@ distdir: $(DISTFILES) @for file in $(DISTFILES); do \ d=$(srcdir); \ if test -d $$d/$$file; then \ - cp -pr $$d/$$file $(distdir)/$$file; \ + cp -pr $$/$$file $(distdir)/$$file; \ else \ test -f $(distdir)/$$file \ || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ diff --git a/check/Makefile.in b/check/Makefile.in index 1d2a0069..bcb32424 100644 --- a/check/Makefile.in +++ b/check/Makefile.in @@ -248,7 +248,7 @@ distdir: $(DISTFILES) @for file in $(DISTFILES); do \ d=$(srcdir); \ if test -d $$d/$$file; then \ - cp -pr $$d/$$file $(distdir)/$$file; \ + cp -pr $$/$$file $(distdir)/$$file; \ else \ test -f $(distdir)/$$file \ || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ diff --git a/config.h.in b/config.h.in index c229c73a..f4d7fb17 100644 --- a/config.h.in +++ b/config.h.in @@ -42,6 +42,9 @@ /* Define if you have the header file. */ #undef HAVE_READLINE_READLINE_H +/* Define if you have the header file. */ +#undef HAVE_SSTREAM + /* Define if you have the header file. */ #undef HAVE_STDEXCEPT diff --git a/configure b/configure index d7eb4390..f0c1bb80 100755 --- a/configure +++ b/configure @@ -2411,7 +2411,7 @@ else fi -for ac_hdr in iostream vector map string list typeinfo iterator strstream stdexcept algorithm +for ac_hdr in iostream vector map string list typeinfo iterator stdexcept algorithm do ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 @@ -2452,23 +2452,63 @@ else fi done +for ac_hdr in sstream strstream +do +ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` +echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 +echo "configure:2460: checking for $ac_hdr" >&5 +if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.$ac_ext < +EOF +ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" +{ (eval echo configure:2470: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` +if test -z "$ac_err"; then + rm -rf conftest* + eval "ac_cv_header_$ac_safe=yes" +else + echo "$ac_err" >&5 + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + eval "ac_cv_header_$ac_safe=no" +fi +rm -f conftest* +fi +if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then + echo "$ac_t""yes" 1>&6 + ac_tr_hdr=HAVE_`echo $ac_hdr | sed 'y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%'` + cat >> confdefs.h <&6 +fi +done + for ac_hdr in cln/cln.h do ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 -echo "configure:2462: checking for $ac_hdr" >&5 +echo "configure:2502: checking for $ac_hdr" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:2472: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:2512: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then rm -rf conftest* @@ -2495,17 +2535,17 @@ for ac_hdr in cln.h do ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 -echo "configure:2499: checking for $ac_hdr" >&5 +echo "configure:2539: checking for $ac_hdr" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:2509: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:2549: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then rm -rf conftest* @@ -2540,7 +2580,7 @@ done echo $ac_n "checking for doublefactorial in -lcln""... $ac_c" 1>&6 -echo "configure:2544: checking for doublefactorial in -lcln" >&5 +echo "configure:2584: checking for doublefactorial in -lcln" >&5 saved_LIBS="${LIBS}" if eval "test \"`echo '$''{'ginac_cv_lib_cln_link'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -2549,14 +2589,14 @@ else case "${ac_cv_header_CLN_cln_h}" in "yes") cat > conftest.$ac_ext < int main() { doublefactorial(2); ; return 0; } EOF -if { (eval echo configure:2560: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:2600: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* ginac_cv_lib_cln_link="-lcln" else @@ -2569,14 +2609,14 @@ rm -f conftest* ;; *) cat > conftest.$ac_ext < int main() { doublefactorial(2); ; return 0; } EOF -if { (eval echo configure:2580: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:2620: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* ginac_cv_lib_cln_link="-lcln" else @@ -2616,7 +2656,7 @@ GINACLIB_LIBS=$LIBS # Extract the first word of "doxygen", so it can be a program name with args. set dummy doxygen; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:2620: checking for $ac_word" >&5 +echo "configure:2660: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_path_DOXYGEN'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -2652,7 +2692,7 @@ fi # Extract the first word of "latex", so it can be a program name with args. set dummy latex; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:2656: checking for $ac_word" >&5 +echo "configure:2696: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_path_LATEX'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -2688,7 +2728,7 @@ fi # Extract the first word of "makeindex", so it can be a program name with args. set dummy makeindex; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:2692: checking for $ac_word" >&5 +echo "configure:2732: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_path_MAKEINDEX'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -2724,7 +2764,7 @@ fi # Extract the first word of "dvips", so it can be a program name with args. set dummy dvips; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:2728: checking for $ac_word" >&5 +echo "configure:2768: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_path_DVIPS'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -2760,7 +2800,7 @@ fi # Extract the first word of "fig2dev", so it can be a program name with args. set dummy fig2dev; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:2764: checking for $ac_word" >&5 +echo "configure:2804: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_path_FIG2DEV'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else diff --git a/configure.in b/configure.in index af2b0a8e..a42eba2c 100644 --- a/configure.in +++ b/configure.in @@ -104,8 +104,9 @@ AC_CHECK_LIB(stdc++, cout) dnl Make sure all the necessary new-style headers are installed on the system. dnl If one of them cannot be found the system is probably not ANSI-conform dnl enough so trying the .h-style headers is a waste of time. -AC_CHECK_HEADERS(iostream vector map string list typeinfo iterator strstream stdexcept algorithm, , +AC_CHECK_HEADERS(iostream vector map string list typeinfo iterator stdexcept algorithm, , AC_MSG_ERROR(need to have ANSI compliant headers)) +AC_CHECK_HEADERS(sstream strstream) dnl We need to have Bruno Haible's CLN installed (macros are in acinclude.m4): GINAC_CHECK_CLN_H diff --git a/doc/Makefile.in b/doc/Makefile.in index 480df48e..b6902514 100644 --- a/doc/Makefile.in +++ b/doc/Makefile.in @@ -269,7 +269,7 @@ distdir: $(DISTFILES) @for file in $(DISTFILES); do \ d=$(srcdir); \ if test -d $$d/$$file; then \ - cp -pr $$d/$$file $(distdir)/$$file; \ + cp -pr $$/$$file $(distdir)/$$file; \ else \ test -f $(distdir)/$$file \ || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ diff --git a/doc/reference/Makefile.in b/doc/reference/Makefile.in index 2edc3256..94f8b732 100644 --- a/doc/reference/Makefile.in +++ b/doc/reference/Makefile.in @@ -165,7 +165,7 @@ distdir: $(DISTFILES) @for file in $(DISTFILES); do \ d=$(srcdir); \ if test -d $$d/$$file; then \ - cp -pr $$d/$$file $(distdir)/$$file; \ + cp -pr $$/$$file $(distdir)/$$file; \ else \ test -f $(distdir)/$$file \ || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ diff --git a/doc/tutorial/Makefile.in b/doc/tutorial/Makefile.in index ca92d6b9..820db8e5 100644 --- a/doc/tutorial/Makefile.in +++ b/doc/tutorial/Makefile.in @@ -317,7 +317,7 @@ distdir: $(DISTFILES) @for file in $(DISTFILES); do \ d=$(srcdir); \ if test -d $$d/$$file; then \ - cp -pr $$d/$$file $(distdir)/$$file; \ + cp -pr $$/$$file $(distdir)/$$file; \ else \ test -f $(distdir)/$$file \ || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ diff --git a/ginac/Makefile.in b/ginac/Makefile.in index 0fbd01be..12b11d08 100644 --- a/ginac/Makefile.in +++ b/ginac/Makefile.in @@ -290,7 +290,7 @@ distdir: $(DISTFILES) @for file in $(DISTFILES); do \ d=$(srcdir); \ if test -d $$d/$$file; then \ - cp -pr $$d/$$file $(distdir)/$$file; \ + cp -pr $$/$$file $(distdir)/$$file; \ else \ test -f $(distdir)/$$file \ || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ diff --git a/ginac/archive.cpp b/ginac/archive.cpp index dfc00cee..0fdb30ad 100644 --- a/ginac/archive.cpp +++ b/ginac/archive.cpp @@ -511,8 +511,8 @@ void archive_node::forget(void) } -/** Dump archive to stream (for debugging). */ -void archive::dump(ostream &os) const +/** Print archive to stream in ugly raw format (for debugging). */ +void archive::printraw(ostream &os) const { // Dump atoms os << "Atoms:\n"; @@ -545,14 +545,14 @@ void archive::dump(ostream &os) const archive_node_id id = 0; while (i != iend) { os << " " << id << " "; - i->dump(os); + i->printraw(os); i++; id++; } } } -/** Dump archive_node to stream (for debugging). */ -void archive_node::dump(ostream &os) const +/** Output archive_node to stream in ugly raw format (for debugging). */ +void archive_node::printraw(ostream &os) const { // Dump cached unarchived expression if (has_expression) diff --git a/ginac/archive.h b/ginac/archive.h index a2db1666..7b464a22 100644 --- a/ginac/archive.h +++ b/ginac/archive.h @@ -77,7 +77,7 @@ public: ex unarchive(const lst &sym_lst) const; void forget(void); - void dump(ostream &os) const; + void printraw(ostream &os) const; private: /** Property data types */ @@ -150,7 +150,7 @@ public: void clear(void); void forget(void); - void dump(ostream &os) const; + void printraw(ostream &os) const; private: /** Vector of archived nodes. */ diff --git a/ginac/color.cpp b/ginac/color.cpp index f9220582..8a793844 100644 --- a/ginac/color.cpp +++ b/ginac/color.cpp @@ -33,6 +33,7 @@ #include "ncmul.h" #include "numeric.h" #include "relational.h" +#include "archive.h" #include "debugmsg.h" #include "utils.h" @@ -40,6 +41,8 @@ namespace GiNaC { #endif // ndef NO_GINAC_NAMESPACE +GINAC_IMPLEMENT_REGISTERED_CLASS(color, indexed) + ////////// // default constructor, destructor, copy constructor assignment operator and helpers ////////// @@ -78,7 +81,7 @@ const color & color::operator=(const color & other) void color::copy(const color & other) { - indexed::copy(other); + inherited::copy(other); type=other.type; representation_label=other.representation_label; } @@ -86,7 +89,7 @@ void color::copy(const color & other) void color::destroy(bool call_parent) { if (call_parent) { - indexed::destroy(call_parent); + inherited::destroy(call_parent); } } @@ -105,7 +108,7 @@ color::color(color_types const t, unsigned rl) : type(t), representation_label(r } color::color(color_types const t, const ex & i1, unsigned rl) - : indexed(i1), type(t), representation_label(rl) + : inherited(i1), type(t), representation_label(rl) { debugmsg("color constructor from color_types,ex,unsigned",LOGLEVEL_CONSTRUCT); GINAC_ASSERT(representation_labelsetflag(status_flags::dynallocated); +} + +/** Archive the object. */ +void color::archive(archive_node &n) const +{ + inherited::archive(n); + n.add_unsigned("type", type); + n.add_unsigned("representation", representation_label); +} + ////////// // functions overriding virtual functions from bases classes ////////// @@ -222,7 +255,7 @@ void color::printcsrc(ostream & os, unsigned type, unsigned upper_precedence) co bool color::info(unsigned inf) const { - return indexed::info(inf); + return inherited::info(inf); } #define CMPINDICES(A,B,C) ((idx1.get_value()==(A))&&(idx2.get_value()==(B))&&(idx3.get_value()==(C))) @@ -354,7 +387,7 @@ int color::compare_same_type(const basic & other) const const color *o = static_cast(&other); if (type==o->type) { if (representation_label==o->representation_label) { - return indexed::compare_same_type(other); + return inherited::compare_same_type(other); } return representation_label < o->representation_label ? -1 : 1; } @@ -367,7 +400,7 @@ bool color::is_equal_same_type(const basic & other) const const color *o = static_cast(&other); if (type!=o->type) return false; if (representation_label!=o->representation_label) return false; - return indexed::is_equal_same_type(other); + return inherited::is_equal_same_type(other); } #include diff --git a/ginac/color.h b/ginac/color.h index 6a464edc..c6c4ca04 100644 --- a/ginac/color.h +++ b/ginac/color.h @@ -41,6 +41,8 @@ typedef vector exvectorvector; /** Base class for color object */ class color : public indexed { + GINAC_DECLARE_REGISTERED_CLASS(color, indexed) + // friends friend color color_ONE(unsigned rl); diff --git a/ginac/coloridx.cpp b/ginac/coloridx.cpp index 60e45968..e7c35c55 100644 --- a/ginac/coloridx.cpp +++ b/ginac/coloridx.cpp @@ -23,6 +23,7 @@ #include #include "coloridx.h" +#include "archive.h" #include "utils.h" #include "debugmsg.h" @@ -30,6 +31,8 @@ namespace GiNaC { #endif // ndef NO_GINAC_NAMESPACE +GINAC_IMPLEMENT_REGISTERED_CLASS(coloridx, idx) + ////////// // default constructor, destructor, copy constructor assignment operator and helpers ////////// @@ -70,12 +73,12 @@ const coloridx & coloridx::operator=(const coloridx & other) void coloridx::copy(const coloridx & other) { - idx::copy(other); + inherited::copy(other); } void coloridx::destroy(bool call_parent) { - if (call_parent) idx::destroy(call_parent); + if (call_parent) inherited::destroy(call_parent); } ////////// @@ -110,6 +113,28 @@ coloridx::coloridx(unsigned v, bool cov) : idx(v,cov) tinfo_key=TINFO_coloridx; } +////////// +// archiving +////////// + +/** Construct object from archive_node. */ +coloridx::coloridx(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst) +{ + debugmsg("coloridx constructor from archive_node", LOGLEVEL_CONSTRUCT); +} + +/** Unarchive the object. */ +ex coloridx::unarchive(const archive_node &n, const lst &sym_lst) +{ + return (new coloridx(n, sym_lst))->setflag(status_flags::dynallocated); +} + +/** Archive the object. */ +void coloridx::archive(archive_node &n) const +{ + inherited::archive(n); +} + ////////// // functions overriding virtual functions from bases classes ////////// diff --git a/ginac/coloridx.h b/ginac/coloridx.h index 52ed82a0..266dcf92 100644 --- a/ginac/coloridx.h +++ b/ginac/coloridx.h @@ -34,6 +34,8 @@ namespace GiNaC { class coloridx : public idx { + GINAC_DECLARE_REGISTERED_CLASS(coloridx, idx) + friend class color; // member functions diff --git a/ginac/idx.cpp b/ginac/idx.cpp index 67d23c5b..5b93905a 100644 --- a/ginac/idx.cpp +++ b/ginac/idx.cpp @@ -26,6 +26,7 @@ #include "ex.h" #include "lst.h" #include "relational.h" +#include "archive.h" #include "utils.h" #include "debugmsg.h" @@ -33,13 +34,15 @@ namespace GiNaC { #endif // ndef NO_GINAC_NAMESPACE +GINAC_IMPLEMENT_REGISTERED_CLASS(idx, basic) + ////////// // default constructor, destructor, copy constructor assignment operator and helpers ////////// // public -idx::idx() : basic(TINFO_idx), symbolic(true), covariant(false) +idx::idx() : inherited(TINFO_idx), symbolic(true), covariant(false) { debugmsg("idx default constructor",LOGLEVEL_CONSTRUCT); serial=next_serial++; @@ -72,7 +75,7 @@ const idx & idx::operator=(const idx & other) void idx::copy(const idx & other) { - basic::copy(other); + inherited::copy(other); serial=other.serial; symbolic=other.symbolic; name=other.name; @@ -82,7 +85,7 @@ void idx::copy(const idx & other) void idx::destroy(bool call_parent) { - if (call_parent) basic::destroy(call_parent); + if (call_parent) inherited::destroy(call_parent); } ////////// @@ -91,34 +94,80 @@ void idx::destroy(bool call_parent) // public -idx::idx(bool cov) : basic(TINFO_idx), symbolic(true), covariant(cov) +idx::idx(bool cov) : inherited(TINFO_idx), symbolic(true), covariant(cov) { debugmsg("idx constructor from bool",LOGLEVEL_CONSTRUCT); serial=next_serial++; name="index"+ToString(serial); } -idx::idx(const string & n, bool cov) : basic(TINFO_idx), +idx::idx(const string & n, bool cov) : inherited(TINFO_idx), symbolic(true), name(n), covariant(cov) { debugmsg("idx constructor from string,bool",LOGLEVEL_CONSTRUCT); serial=next_serial++; } -idx::idx(const char * n, bool cov) : basic(TINFO_idx), +idx::idx(const char * n, bool cov) : inherited(TINFO_idx), symbolic(true), name(n), covariant(cov) { debugmsg("idx constructor from char*,bool",LOGLEVEL_CONSTRUCT); serial=next_serial++; } -idx::idx(unsigned v, bool cov) : basic(TINFO_idx), +idx::idx(unsigned v, bool cov) : inherited(TINFO_idx), symbolic(false), value(v), covariant(cov) { debugmsg("idx constructor from unsigned,bool",LOGLEVEL_CONSTRUCT); serial=0; } +////////// +// archiving +////////// + +/** Construct object from archive_node. */ +idx::idx(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst) +{ + debugmsg("idx constructor from archive_node", LOGLEVEL_CONSTRUCT); + n.find_bool("symbolic", symbolic); + n.find_bool("covariant", covariant); + if (symbolic) { + serial = next_serial++; + if (!(n.find_string("name", name))) + name = "index" + ToString(serial); + } else { + serial = 0; + n.find_unsigned("value", value); + } +} + +/** Unarchive the object. */ +ex idx::unarchive(const archive_node &n, const lst &sym_lst) +{ + ex s = (new idx(n, sym_lst))->setflag(status_flags::dynallocated); + + if (ex_to_idx(s).symbolic) { + // If idx is in sym_lst, return the existing idx + for (int i=0; isetflag(status_flags::dynallocated); + + // If isospin is in sym_lst, return the existing isospin + for (int i=0; i(&other); if (serial==o->serial) { - return indexed::compare_same_type(other); + return inherited::compare_same_type(other); } return serial < o->serial ? -1 : 1; } diff --git a/ginac/isospin.h b/ginac/isospin.h index 0318360f..8988fef1 100644 --- a/ginac/isospin.h +++ b/ginac/isospin.h @@ -33,6 +33,8 @@ namespace GiNaC { /** Base class for isospin object */ class isospin : public indexed { + GINAC_DECLARE_REGISTERED_CLASS(isospin, indexed) + // member functions // default constructor, destructor, copy constructor assignment operator and helpers diff --git a/ginac/numeric.cpp b/ginac/numeric.cpp index 99dcc8e4..77620c32 100644 --- a/ginac/numeric.cpp +++ b/ginac/numeric.cpp @@ -24,14 +24,22 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "config.h" + #include #include #include -#include //!! + +#if defined(HAVE_SSTREAM) +#include +#elif defined(HAVE_STRSTREAM) +#include +#else +#error Need either sstream or strstream +#endif #include "numeric.h" #include "ex.h" -#include "config.h" #include "archive.h" #include "debugmsg.h" #include "utils.h" @@ -236,19 +244,56 @@ numeric::numeric(const archive_node &n, const lst &sym_lst) : inherited(n, sym_l { debugmsg("numeric constructor from archive_node", LOGLEVEL_CONSTRUCT); value = new cl_N; -#if 0 //!! - // This is how it should be implemented but we have no istringstream here... +#ifdef HAVE_SSTREAM + // Read number as string string str; if (n.find_string("number", str)) { istringstream s(str); - s >> *value; + cl_idecoded_float re, im; + char c; + s.get(c); + switch (c) { + case 'N': // Ordinary number + case 'R': // Integer-decoded real number + s >> re.sign >> re.mantissa >> re.exponent; + *value = re.sign * re.mantissa * expt(cl_float(2.0, cl_default_float_format), re.exponent); + break; + case 'C': // Integer-decoded complex number + s >> re.sign >> re.mantissa >> re.exponent; + s >> im.sign >> im.mantissa >> im.exponent; + *value = complex(re.sign * re.mantissa * expt(cl_float(2.0, cl_default_float_format), re.exponent), + im.sign * im.mantissa * expt(cl_float(2.0, cl_default_float_format), im.exponent)); + break; + default: // Ordinary number + s.putback(c); + s >> *value; + break; + } } #else - // Workaround for the above: read from strstream + // Read number as string string str; if (n.find_string("number", str)) { istrstream f(str.c_str(), str.size() + 1); - f >> *value; + cl_idecoded_float re, im; + char c; + f.get(c); + switch (c) { + case 'R': // Integer-decoded real number + f >> re.sign >> re.mantissa >> re.exponent; + *value = re.sign * re.mantissa * expt(cl_float(2.0, cl_default_float_format), re.exponent); + break; + case 'C': // Integer-decoded complex number + f >> re.sign >> re.mantissa >> re.exponent; + f >> im.sign >> im.mantissa >> im.exponent; + *value = complex(re.sign * re.mantissa * expt(cl_float(2.0, cl_default_float_format), re.exponent), + im.sign * im.mantissa * expt(cl_float(2.0, cl_default_float_format), im.exponent)); + break; + default: // Ordinary number + f.putback(c); + f >> *value; + break; + } } #endif calchash(); @@ -266,16 +311,48 @@ ex numeric::unarchive(const archive_node &n, const lst &sym_lst) void numeric::archive(archive_node &n) const { inherited::archive(n); -#if 0 //!! - // This is how it should be implemented but we have no ostringstream here... +#ifdef HAVE_SSTREAM + // Write number as string ostringstream s; - s << *value; + if (is_crational()) + s << *value; + else { + // Non-rational numbers are written in an integer-decoded format + // to preserve the precision + if (is_real()) { + cl_idecoded_float re = integer_decode_float(The(cl_F)(*value)); + s << "R"; + s << re.sign << " " << re.mantissa << " " << re.exponent; + } else { + cl_idecoded_float re = integer_decode_float(The(cl_F)(realpart(*value))); + cl_idecoded_float im = integer_decode_float(The(cl_F)(imagpart(*value))); + s << "C"; + s << re.sign << " " << re.mantissa << " " << re.exponent << " "; + s << im.sign << " " << im.mantissa << " " << im.exponent; + } + } n.add_string("number", s.str()); #else - // Workaround for the above: write to strstream + // Write number as string char buf[1024]; ostrstream f(buf, 1024); - f << *value << ends; + if (is_crational()) + f << *value << ends; + else { + // Non-rational numbers are written in an integer-decoded format + // to preserve the precision + if (is_real()) { + cl_idecoded_float re = integer_decode_float(The(cl_F)(*value)); + f << "R"; + f << re.sign << " " << re.mantissa << " " << re.exponent << ends; + } else { + cl_idecoded_float re = integer_decode_float(The(cl_F)(realpart(*value))); + cl_idecoded_float im = integer_decode_float(The(cl_F)(imagpart(*value))); + f << "C"; + f << re.sign << " " << re.mantissa << " " << re.exponent << " "; + f << im.sign << " " << im.mantissa << " " << im.exponent << ends; + } + } string str(buf); n.add_string("number", str); #endif diff --git a/ginsh/Makefile.in b/ginsh/Makefile.in index 52e10808..977284b4 100644 --- a/ginsh/Makefile.in +++ b/ginsh/Makefile.in @@ -311,7 +311,7 @@ distdir: $(DISTFILES) @for file in $(DISTFILES); do \ d=$(srcdir); \ if test -d $$d/$$file; then \ - cp -pr $$d/$$file $(distdir)/$$file; \ + cp -pr $$/$$file $(distdir)/$$file; \ else \ test -f $(distdir)/$$file \ || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ diff --git a/tools/Makefile.in b/tools/Makefile.in index eb3d1722..901c1860 100644 --- a/tools/Makefile.in +++ b/tools/Makefile.in @@ -293,7 +293,7 @@ distdir: $(DISTFILES) @for file in $(DISTFILES); do \ d=$(srcdir); \ if test -d $$d/$$file; then \ - cp -pr $$d/$$file $(distdir)/$$file; \ + cp -pr $$/$$file $(distdir)/$$file; \ else \ test -f $(distdir)/$$file \ || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ diff --git a/tools/viewgar.cpp b/tools/viewgar.cpp index 1f333f0e..79f99291 100644 --- a/tools/viewgar.cpp +++ b/tools/viewgar.cpp @@ -47,7 +47,7 @@ int main(int argc, char **argv) archive ar; f >> ar; if (dump_mode) { - ar.dump(cout); + ar.printraw(cout); cout << endl; } else { for (unsigned int i=0; i