]> www.ginac.de Git - ginac.git/blob - ginac/constant.h
e772ada848566a796b9e307f48748a6f2cdd5bb6
[ginac.git] / ginac / constant.h
1 /** @file constant.h
2  *
3  *  Interface to GiNaC's constant types and some special constants.
4  *
5  *  GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2 of the License, or
10  *  (at your option) any later version.
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, write to the Free Software
19  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #ifndef __GINAC_CONSTANT_H__
23 #define __GINAC_CONSTANT_H__
24
25 #include <string>
26
27 /** This class holds constants, symbols with specific numerical value. Each
28  *  object of this class must either provide their own function to evaluate it
29  *  to class numeric or provide the constant as a numeric (if it's an exact
30  *  number). */
31 class constant : public basic
32 {
33
34 // member functions
35
36     // default constructor, destructor, copy constructor assignment operator and helpers
37 public:
38     ~constant();
39     constant(constant const & other);
40     // constant const & operator=(constant const & other); /* it's pervert! */
41 protected:
42     void copy(constant const & other);
43     void destroy(bool call_parent);
44
45     // other constructors
46 public:
47     constant(string const & initname, ex (*efun)()=0);
48     constant(string const & initname, numeric const & initnumber);
49
50     // functions overriding virtual functions from bases classes
51 public:
52     basic * duplicate() const;
53     void printraw(ostream & os) const;
54     void print(ostream & os, unsigned upper_precedence=0) const;
55     void printcsrc(ostream & os, unsigned type, unsigned upper_precedence=0) const;
56     ex evalf(int level=0) const;
57     ex diff(symbol const & s) const;
58 protected:
59     int compare_same_type(basic const & other) const;
60     bool is_equal_same_type(basic const & other) const;
61     
62     // new virtual functions which can be overridden by derived classes
63     // none
64
65     // non-virtual functions in this class
66     // none
67
68 // member variables
69
70 private:
71     string name;
72     ex (*ef)();
73     numeric * number;
74     bool fct_assigned;
75     unsigned serial;  //!< unique serial number for comparision
76     static unsigned next_serial;
77 };
78
79 // global constants
80
81 extern const constant some_constant;
82 extern type_info const & typeid_constant;
83
84 // extern const numeric I;
85 extern const constant Pi;
86 extern const constant Catalan;
87 extern const constant EulerGamma;
88
89 #endif // ndef __GINAC_CONSTANT_H__