xc
NmbVars.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 //NmbVars.h
22 
23 #ifndef NMBVARS_H
24 #define NMBVARS_H
25 
26 #include <assert.h>
27 #include <set>
28 #include <string>
29 #include "utility/matrices/vectorZ.h"
30 
31 typedef vectorZ<char> vZ_char;
33 
36 class NmbVars : public vZ_char
37  {
38  protected:
39  void PutStr(const std::string &str);
40  void PutChar(const char c)
41  { (*this)[0]= c; }
42  public:
43  NmbVars(const size_t &sz=1,const char &c='x') : vZ_char(sz,'x') {}
45  NmbVars(const std::string &vars) : vZ_char(vars.size(),'x')
46  { PutStr(vars); }
47  NmbVars(const char c) : vZ_char(1)
48  //Ojo! este es el que utiliza cuando se da un solo parámetro.
49  { PutChar(c); }
50  NmbVars( const NmbVars &otro) : vZ_char(otro) {}
51  NmbVars( const vZ_char &otro) : vZ_char(otro) {}
52  NmbVars &operator=(const NmbVars &otro)
53  {
54  vZ_char::operator =(otro);
55  return *this;
56  }
57  NmbVars &operator=(const vZ_char &otro)
58  {
59  vZ_char::operator =(otro);
60  return *this;
61  }
63  NmbVars QuitaVar(short unsigned int j) const
64  { return GetMenor(j); }
65  NmbVars Combina(const NmbVars &n2) const;
66  vZ_sui Indices(const NmbVars &n) const;
67  NmbVars CambioVar(short unsigned int j,const NmbVars &v) const
68  {
69  NmbVars c= GetMenor(j);
70  c= v.Combina(c);
71  return c;
72  }
73  friend NmbVars PutVars(const char var);
74  friend NmbVars PutVars(const std::string &var);
75  friend NmbVars operator +(const NmbVars &v1,const NmbVars &v2);
76  friend std::ostream &operator << (std::ostream &stream, const NmbVars &n)
77  { return operator << (stream, (const vZ_char &) n); }
78  };
79 
80 
81 
82 NmbVars PutVars(const char var)
83 //Devuelve el conjunto de variables
84 //correspondiente al caracter
85 //que se le pasa como parámetro.
86  {
87  NmbVars n(size_t(1));
88  n.PutChar(var);
89  return n;
90  }
91 
92 NmbVars PutVars(const std::string &vars)
93 //Devuelve el conjunto de variables
94 //correspondiente a la cadena de caracteres
95 //que se le pasa como parámetro.
96  {
97  NmbVars n(vars.size());
98  n.PutStr(vars);
99  return n;
100  }
101 
102 inline NmbVars operator +(const NmbVars &v1,const NmbVars &v2)
103  { return v1.Combina(v2); }
104 
105 #endif
106 
Stores the names of the function variables.
Definition: NmbVars.h:36
NmbVars QuitaVar(short unsigned int j) const
Return a set of variable names excepth the j-th one.
Definition: NmbVars.h:63
Definition: vectorZ.h:39
NmbVars(const std::string &vars)
Initializes the names of the first n variables from the argument string.
Definition: NmbVars.h:45