xc
function.h
1 // -*-c++-*-
2 //----------------------------------------------------------------------------
3 // xc utils library; general purpose classes and functions.
4 //
5 // Copyright (C) Luis C. PĂ©rez Tato
6 //
7 // XC utils 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 3 of the License, or
10 // (at your option) any later version.
11 //
12 // This software is distributed in the hope that it will be useful, but
13 // 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.
19 // If not, see <http://www.gnu.org/licenses/>.
20 //----------------------------------------------------------------------------
21 //Function.h
22 
23 #ifndef FUNCION_H
24 #define FUNCION_H
25 
26 #include <cassert>
27 #include <algorithm>
28 #include "NmbVars.h"
29 
30 class Function
31  {
32  protected:
34  public:
35  Function(void) {}
36  Function(const NmbVars &vars)
37  { Vars= vars; }
38  Function(const char *vars)
39  { Vars= PutVars(vars); }
40  Function(const char var)
41  { Vars= PutVars(var); }
42  Function(const Function &other)
43  { Vars= other.Vars; }
44  Function &operator=(const Function &other)
45  {
46  Vars= other.Vars;
47  return *this;
48  }
49  short unsigned int GetDim(void) const
50  { return Vars.size(); }
51  inline char GetNmbVar(short unsigned int i) const
52  //Las variables se numeran de 1 a n;
53  { return Vars.at(i-1); }
54  void PutNmbVar(short unsigned int i,char nmb)
55  { Vars[i-1]= nmb; }
56  void PutStr(const char *vars)
57  { Vars= PutVars(vars); }
58  void PutChar(const char var)
59  { Vars= PutVars(var); }
60  void CambioVar(short unsigned int j,const NmbVars &vars)
61  { Vars= Vars.CambioVar(j,vars); }
62  const NmbVars &GetVars(void) const
63  { return Vars; }
64  friend Function operator +(const Function &f1,const Function &f2)
65  {
66  Function f(f1.Vars.Combina(f2.Vars));
67  return f;
68  }
69  friend Function operator -(const Function &f1,const Function &f2)
70  {
71  Function f(f1.Vars.Combina(f2.Vars));
72  return f;
73  }
74  friend Function operator *(const Function &f1,const Function &f2)
75  {
76  Function f(f1.Vars.Combina(f2.Vars));
77  return f;
78  }
79  inline friend bool operator==(const Function &f1,const Function &f2)
80  {
81  if (f1.Vars != f2.Vars) return 0;
82  return 1;
83  }
84  inline friend bool operator!=(const Function &f1,const Function &f2)
85  { return !(f1==f2); }
86  };
87 
88 
89 
90 #endif
91 
Stores the names of the function variables.
Definition: NmbVars.h:36
Definition: function.h:30
NmbVars Vars
Independent variable names.
Definition: function.h:33