]> www.ginac.de Git - ginac.git/commitdiff
Make symbol::name be initialized lazily. ginac_1-5
authorRichard Kreckel <kreckel@ginac.de>
Thu, 9 Dec 2010 08:18:34 +0000 (09:18 +0100)
committerRichard Kreckel <kreckel@ginac.de>
Thu, 9 Dec 2010 08:24:17 +0000 (09:24 +0100)
This fixes symbol::get_name(), which returned an empty string instead of
"symbol" followed by the serial number if the symbol's name wasn't
specified in the constructor.

Thanks to Warren Weckesser for reporting this bug.
(cherry picked from commit f5abf61d2cb1a1d1809d270a24fa098575b172c4)

ginac/symbol.cpp
ginac/symbol.h

index c9db110fdc43a1cfb581128d48f592553644cfae..e7eb9c92317b5d53b55e333b9ec206e4ae4605a3 100644 (file)
@@ -150,12 +150,21 @@ static const std::string& get_default_TeX_name(const std::string& name);
 
 // public
 
+std::string symbol::get_name() const
+{
+       if (name.empty()) {
+               std::ostringstream s;
+               s << "symbol" << serial;
+               name = s.str();
+       }
+       return name;
+}
+
+// protected
+
 void symbol::do_print(const print_context & c, unsigned level) const
 {
-       if (!name.empty())
-               c.s << name;
-       else
-               c.s << "symbol" << serial;
+       c.s << get_name();
 }
 
 void symbol::do_print_latex(const print_latex & c, unsigned level) const
index eefd27c80672583ab37f5ae1be2b544fa0b805c2..ec371f8c3ed8ad40374b8bfc96b845f5d8a66e12 100644 (file)
@@ -69,7 +69,7 @@ protected:
        // non-virtual functions in this class
 public:
        void set_name(const std::string & n) { name = n; }
-       std::string get_name() const { return name; }
+       std::string get_name() const;
        virtual unsigned get_domain() const { return domain::complex; }
 protected:
        void do_print(const print_context & c, unsigned level) const;
@@ -81,7 +81,7 @@ protected:
 
 protected:
        unsigned serial;                 ///< unique serial number for comparison
-       std::string name;                ///< printname of this symbol
+       mutable std::string name;        ///< printname of this symbol
        std::string TeX_name;            ///< LaTeX name of this symbol
 private:
        static unsigned next_serial;
@@ -108,7 +108,7 @@ public:
 GINAC_DECLARE_UNARCHIVER(realsymbol);
 
 
-/** Specialization of symbol to real domain */
+/** Specialization of symbol to real positive domain */
 class possymbol : public realsymbol
 {
 public: