- debugmsg("ex makewriteable",LOGLEVEL_MEMBER_FUNCTION);
- GINAC_ASSERT(bp!=0);
- GINAC_ASSERT(bp->flags & status_flags::dynallocated);
- if (bp->refcount > 1) {
- basic * bp2=bp->duplicate();
- ++bp2->refcount;
- bp2->setflag(status_flags::dynallocated);
- --bp->refcount;
- bp=bp2;
- }
- GINAC_ASSERT(bp->refcount == 1);
-}
-
-void ex::construct_from_basic(basic const & other)
-{
- if ((other.flags & status_flags::evaluated)==0) {
- // cf. copy constructor
- ex const & tmpex = other.eval(1); // evaluate only one (top) level
- bp = tmpex.bp;
- GINAC_ASSERT(bp!=0);
- GINAC_ASSERT(bp->flags & status_flags::dynallocated);
- ++bp->refcount;
- if ((other.flags & status_flags::dynallocated)&&(other.refcount==0)) {
- delete &const_cast<basic &>(other);
- }
- } else {
- if (other.flags & status_flags::dynallocated) {
- bp=&const_cast<basic &>(other);
- } else {
- bp=other.duplicate();
- bp->setflag(status_flags::dynallocated);
- }
- GINAC_ASSERT(bp!=0);
- // bp->clearflag(status_flags::evaluated);
- ++bp->refcount;
- }
- GINAC_ASSERT(bp!=0);
- GINAC_ASSERT(bp->flags & status_flags::dynallocated);
-}
-
+ debugmsg("ex makewriteable",LOGLEVEL_MEMBER_FUNCTION);
+ GINAC_ASSERT(bp!=0);
+ GINAC_ASSERT(bp->flags & status_flags::dynallocated);
+ if (bp->refcount > 1) {
+ basic * bp2 = bp->duplicate();
+ ++bp2->refcount;
+ bp2->setflag(status_flags::dynallocated);
+ --bp->refcount;
+ bp = bp2;
+ }
+ GINAC_ASSERT(bp->refcount==1);
+}
+
+/** Ctor from basic implementation.
+ * @see ex::ex(const basic &) */
+void ex::construct_from_basic(const basic & other)
+{
+ if ((other.flags & status_flags::evaluated)==0) {
+ // cf. copy ctor
+ const ex & tmpex = other.eval(1); // evaluate only one (top) level
+ bp = tmpex.bp;
+ GINAC_ASSERT(bp!=0);
+ GINAC_ASSERT(bp->flags & status_flags::dynallocated);
+ ++bp->refcount;
+ if ((other.flags & status_flags::dynallocated)&&(other.refcount==0))
+ delete &const_cast<basic &>(other);
+ } else {
+ if (other.flags & status_flags::dynallocated) {
+ // ok, it is already on the heap, so just copy bp:
+ bp = &const_cast<basic &>(other);
+ } else {
+ // create a duplicate on the heap:
+ bp = other.duplicate();
+ bp->setflag(status_flags::dynallocated);
+ }
+ GINAC_ASSERT(bp!=0);
+ // bp->clearflag(status_flags::evaluated);
+ ++bp->refcount;
+ }
+ GINAC_ASSERT(bp!=0);
+ GINAC_ASSERT(bp->flags & status_flags::dynallocated);
+}
+
+void ex::construct_from_int(int i)
+{
+ switch (i) { // some tiny efficiency-hack
+ case -2:
+ bp = _ex_2().bp;
+ ++bp->refcount;
+ break;
+ case -1:
+ bp = _ex_1().bp;
+ ++bp->refcount;
+ break;
+ case 0:
+ bp = _ex0().bp;
+ ++bp->refcount;
+ break;
+ case 1:
+ bp = _ex1().bp;
+ ++bp->refcount;
+ break;
+ case 2:
+ bp = _ex2().bp;
+ ++bp->refcount;
+ break;
+ default:
+ bp = new numeric(i);
+ bp->setflag(status_flags::dynallocated);
+ ++bp->refcount;
+ GINAC_ASSERT((bp->flags) & status_flags::dynallocated);
+ GINAC_ASSERT(bp->refcount==1);
+ }
+}
+
+void ex::construct_from_uint(unsigned int i)
+{
+ switch (i) { // some tiny efficiency-hack
+ case 0:
+ bp = _ex0().bp;
+ ++bp->refcount;
+ break;
+ case 1:
+ bp = _ex1().bp;
+ ++bp->refcount;
+ break;
+ case 2:
+ bp = _ex2().bp;
+ ++bp->refcount;
+ break;
+ default:
+ bp = new numeric(i);
+ bp->setflag(status_flags::dynallocated);
+ ++bp->refcount;
+ GINAC_ASSERT((bp->flags) & status_flags::dynallocated);
+ GINAC_ASSERT(bp->refcount==1);
+ }
+}
+
+void ex::construct_from_long(long i)
+{
+ switch (i) { // some tiny efficiency-hack
+ case -2:
+ bp = _ex_2().bp;
+ ++bp->refcount;
+ break;
+ case -1:
+ bp = _ex_1().bp;
+ ++bp->refcount;
+ break;
+ case 0:
+ bp = _ex0().bp;
+ ++bp->refcount;
+ break;
+ case 1:
+ bp = _ex1().bp;
+ ++bp->refcount;
+ break;
+ case 2:
+ bp = _ex2().bp;
+ ++bp->refcount;
+ break;
+ default:
+ bp = new numeric(i);
+ bp->setflag(status_flags::dynallocated);
+ ++bp->refcount;
+ GINAC_ASSERT((bp->flags) & status_flags::dynallocated);
+ GINAC_ASSERT(bp->refcount==1);
+ }
+}
+
+void ex::construct_from_ulong(unsigned long i)
+{
+ switch (i) { // some tiny efficiency-hack
+ case 0:
+ bp = _ex0().bp;
+ ++bp->refcount;
+ break;
+ case 1:
+ bp = _ex1().bp;
+ ++bp->refcount;
+ break;
+ case 2:
+ bp = _ex2().bp;
+ ++bp->refcount;
+ break;
+ default:
+ bp = new numeric(i);
+ bp->setflag(status_flags::dynallocated);
+ ++bp->refcount;
+ GINAC_ASSERT((bp->flags) & status_flags::dynallocated);
+ GINAC_ASSERT(bp->refcount==1);
+ }
+}
+
+void ex::construct_from_double(double d)
+{
+ bp = new numeric(d);
+ bp->setflag(status_flags::dynallocated);
+ ++bp->refcount;
+ GINAC_ASSERT((bp->flags) & status_flags::dynallocated);
+ GINAC_ASSERT(bp->refcount==1);
+}
+
+void ex::construct_from_string_and_lst(const std::string &s, const ex &l)
+{
+ set_lexer_string(s);
+ set_lexer_symbols(l);
+ ginac_yyrestart(NULL);
+ if (ginac_yyparse())
+ throw (std::runtime_error(get_parser_error()));
+ else {
+ bp = parsed_ex.bp;
+ GINAC_ASSERT(bp!=0);
+ GINAC_ASSERT((bp->flags) & status_flags::dynallocated);
+ ++bp->refcount;
+ }
+}
+