MSpin-JCoupling  2.1
energy.h
1 /***************************************************************************
2  energy.h - description
3  -------------------
4  author : Armando Navarro-Vazquez
5  email : armando.deus@gmail.com
6  ***************************************************************************/
7 
8 /***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 
17 #ifndef MAGNES_ENERGY_H
18 #define MAGNES_ENERGY_H
19 
20 #include "coreexport.h"
21 
23 namespace magnes
24 {
25 
30  class MAGNES_CORE_API Energy
31  {
32  public:
34  enum unity { KCAL, KJ, HARTREES };
36  Energy() : m_value(0) {};
38  ~Energy() { delete m_value; }
39  double Value() const { return *m_value; }
41 // operator double () const { return *m_value; }
42 
44  explicit Energy(double v)
45  {
46  m_value =new double(v);
47  }
49  Energy(const Energy& e)
50  {
51 
52  if ( e )
53  {
54  m_value = new double(e.Value());
55 
56  }
57  else m_value=0;
58  // if (!m_value && !e) //Do nothing
59 
60 
61  }
63  Energy& operator = (const Energy& e)
64  {
65  if ( &e != this)
66  {
67  if ( m_value && e )
68  {
69  *m_value=e.Value();
70 
71  }
72  if ( m_value && !e)
73  {
74  delete m_value;
75  m_value=0;
76  }
77  if ( !m_value && e)
78  {
79  m_value = new double(e.Value());
80 
81  }
82  // if (!m_value && !e) //Do nothing
83 
84  }
85  return *this;
86  }
87 
88 
90  Energy& operator = (double v)
91  {
92  {
93  if ( m_value ) *m_value=v;
94  else
95  m_value = new double(v);
96  }
97  return *this;
98  }
100  static unity Unity();
102  static void SetUnity(unity u);
103  private:
104  typedef void (Energy::*bool_type) () const;
105  void helperfunction() const {};
106  private:
107  //static unity m_unity;
108  double* m_value;
109  static unity m_unity;
110 public:
112  operator bool_type () const
113  {
114  if ( m_value != 0 ) return &Energy::helperfunction;
115  else return 0;
116  }
117 
118 public:
120  friend Energy operator + (const Energy& a, const Energy& b)
121  {
122  if ( !a || !b )
123  {
124  return Energy();
125  }
126  else
127  {
128  return Energy(*a.m_value + *b.m_value );
129  }
130  }
131 
132  };
133 
134 
135 
136 }
137 
138 
139 #endif
unity
Definition: energy.h:34
Energy()
Definition: energy.h:36
Energy(double v)
Definition: energy.h:44
the global magnes namespace
Definition: ccchequation.h:38
A class for storing energy values.
Definition: energy.h:30
Energy(const Energy &e)
Definition: energy.h:49