]> www.ginac.de Git - ginac.git/blob - ginac/constant.h
ef7e8c8d197a807c5f61928fa8a1c0d737831545
[ginac.git] / ginac / constant.h
1 /** @file constant.h
2  *
3  *  Interface to GiNaC's constant types and some special constants. */
4
5 #ifndef _CONSTANT_H_
6 #define _CONSTANT_H_
7
8 #include <string>
9
10 class constant;
11
12 #include "ex.h"
13 #include "numeric.h"
14
15 /** This class holds constants, symbols with specific numerical value. Each
16  *  object of this class must either provide their own function to evaluate it
17  *  to class numeric or provide the constant as a numeric (if it's an exact
18  *  number). */
19 class constant : public basic
20 {
21
22 // member functions
23
24     // default constructor, destructor, copy constructor assignment operator and helpers
25 public:
26     ~constant();
27     constant(constant const & other);
28     // constant const & operator=(constant const & other); /* it's pervert! */
29 protected:
30     void copy(constant const & other);
31     void destroy(bool call_parent);
32
33     // other constructors
34 public:
35     constant(string const & initname, ex (*efun)()=0);
36     constant(string const & initname, numeric const & initnumber);
37
38     // functions overriding virtual functions from bases classes
39 public:
40     basic * duplicate() const;
41     void printraw(ostream & os) const;
42     void print(ostream & os, unsigned upper_precedence=0) const;
43     void printcsrc(ostream & os, unsigned type, unsigned upper_precedence=0) const;
44     ex evalf(int level=0) const;
45     ex diff(symbol const & s) const;
46 protected:
47     int compare_same_type(basic const & other) const;
48     bool is_equal_same_type(basic const & other) const;
49     
50     // new virtual functions which can be overridden by derived classes
51     // none
52
53     // non-virtual functions in this class
54     // none
55
56 // member variables
57
58 private:
59     string name;
60     ex (*ef)();
61     numeric * number;
62     bool fct_assigned;
63     unsigned serial;  //!< unique serial number for comparision
64     static unsigned next_serial;
65 };
66
67 // global constants
68
69 extern const constant some_constant;
70 extern type_info const & typeid_constant;
71
72 // extern const numeric I;
73 extern const constant Pi;
74 extern const constant Catalan;
75 extern const constant EulerGamma;
76
77 #endif // ndef _CONSTANT_H_