]> www.ginac.de Git - ginac.git/blob - ginac/constant.h
488d8a3edbd515fb54a77f3892ef8619b56ac806
[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 #include <ginac/basic.h>
27
28 /** This class holds constants, symbols with specific numerical value. Each
29  *  object of this class must either provide their own function to evaluate it
30  *  to class numeric or provide the constant as a numeric (if it's an exact
31  *  number). */
32 class constant : public basic
33 {
34
35 // member functions
36
37     // default constructor, destructor, copy constructor assignment operator and helpers
38 public:
39     ~constant();
40     constant(constant const & other);
41     // constant const & operator=(constant const & other); /* it's pervert! */
42 protected:
43     void copy(constant const & other);
44     void destroy(bool call_parent);
45
46     // other constructors
47 public:
48     constant(string const & initname, ex (*efun)()=0);
49     constant(string const & initname, numeric const & initnumber);
50
51     // functions overriding virtual functions from bases classes
52 public:
53     basic * duplicate() const;
54     void printraw(ostream & os) const;
55     void print(ostream & os, unsigned upper_precedence=0) const;
56     void printcsrc(ostream & os, unsigned type, unsigned upper_precedence=0) const;
57     ex evalf(int level=0) const;
58     ex diff(symbol const & s) const;
59 protected:
60     int compare_same_type(basic const & other) const;
61     bool is_equal_same_type(basic const & other) const;
62     
63     // new virtual functions which can be overridden by derived classes
64     // none
65
66     // non-virtual functions in this class
67     // none
68
69 // member variables
70
71 private:
72     string name;
73     ex (*ef)();
74     numeric * number;
75     bool fct_assigned;
76     unsigned serial;  //!< unique serial number for comparision
77     static unsigned next_serial;
78 };
79
80 // global constants
81
82 extern const constant some_constant;
83 extern type_info const & typeid_constant;
84
85 // extern const numeric I;
86 extern const constant Pi;
87 extern const constant Catalan;
88 extern const constant EulerGamma;
89
90 #endif // ndef __GINAC_CONSTANT_H__