-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dato.h
104 lines (81 loc) · 1.82 KB
/
Dato.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#ifndef DATO_H_INCLUDED
#define DATO_H_INCLUDED
#include "Tipos.h"
#include "aed2/Conj.h"
#include "aed2/TiposBasicos.h"
namespace aed2
{
class Dato
{
public:
Dato(const aed2::Nat& x);
Dato(const aed2::String& x);
bool esNat() const;
bool esString() const;
TipoCampo tipo() const;
const aed2::Nat& dameNat() const;
const aed2::String& dameString() const;
bool operator == (const Dato& otro) const;
bool operator != (const Dato& otro) const;
bool operator < (const Dato& otro) const;
bool operator > (const Dato& otro) const;
private:
TipoCampo tipo_;
aed2::Nat nat_;
aed2::String str_;
};
Dato::Dato(const aed2::Nat& x)
: tipo_( NAT ), nat_( x )
{}
Dato::Dato(const aed2::String& x)
: tipo_( STR ), str_( x )
{}
bool Dato::esNat() const
{
return tipo_ == NAT;
}
bool Dato::esString() const
{
return tipo_ == STR;
}
TipoCampo Dato::tipo() const
{
return tipo_;
}
const aed2::Nat& Dato::dameNat() const
{
assert( esNat() );
return nat_;
}
const aed2::String& Dato::dameString() const
{
assert( esString() );
return str_;
}
bool Dato::operator == (const Dato& otro) const
{
return tipo_ == otro.tipo_ and (
( tipo_ == NAT and nat_ == otro.nat_ ) or
( tipo_ == STR and str_ == otro.str_ )
);
}
bool Dato::operator < (const Dato& otro) const
{
return tipo_ == otro.tipo_ and (
( tipo_ == NAT and nat_ < otro.nat_ ) or
( tipo_ == STR and str_ < otro.str_ )
);
}
bool Dato::operator > (const Dato& otro) const
{
return tipo_ == otro.tipo_ and (
( tipo_ == NAT and nat_ > otro.nat_ ) or
( tipo_ == STR and str_ > otro.str_ )
);
}
bool Dato::operator != (const Dato& otro) const
{
return not (*this == otro);
}
}
#endif // DATO_H_INCLUDED