g4tools
5.4.0
g4tools
tools
sg
bsf
Go to the documentation of this file.
1
// Copyright (C) 2010, Guy Barrand. All rights reserved.
2
// See the file tools.license for terms.
3
4
#ifndef tools_sg_bsf
5
#define tools_sg_bsf
6
7
// sf for simple field.
8
9
// bsf is intended to have no implementation of :
10
// virtual bool write(io::iwbuf&)
11
// virtual bool read(io::irbuf&)
12
13
#include "
field
"
14
15
namespace
tools
{
16
namespace
sg {
17
18
template
<
class
T>
19
class
bsf
:
public
field
{
20
typedef
field
parent
;
21
public
:
22
static
const
std::string&
s_class
() {
23
//we do not use stype(T()).
24
static
const
std::string s_v(
"tools::sg::bsf"
);
25
return
s_v;
26
}
27
virtual
void
*
cast
(
const
std::string& a_class)
const
{
28
if
(
void
* p =
cmp_cast
<
bsf<T>
>(
this
,a_class)) {
return
p;}
29
return
parent::cast
(a_class);
30
}
31
virtual
const
std::string&
s_cls
()
const
{
return
s_class
();}
32
/*
33
virtual bool equal(const field& a_field) const {
34
bsf<T>* fld = safe_cast<field,bsf<T>>(a_field);
35
if(!fld) return false;
36
return operator==(*fld);
37
}
38
*/
39
protected
:
40
bsf
():
m_value
(T()){}
41
public
:
42
bsf
(
const
T& a_value):
m_value
(a_value){}
43
virtual
~bsf
(){}
44
public
:
45
bsf
(
const
bsf
& a_from)
46
:
parent
(a_from)
47
,
m_value
(a_from.
m_value
){}
48
49
bsf
&
operator=
(
const
bsf
& a_from){
50
parent::operator=
(a_from);
51
if
(a_from.
m_value
!=
m_value
)
m_touched
=
true
;
52
m_value
= a_from.
m_value
;
53
return
*
this
;
54
}
55
public
:
56
bsf
&
operator=
(
const
T& a_value){
57
if
(a_value!=
m_value
)
m_touched
=
true
;
58
m_value
= a_value;
59
return
*
this
;
60
}
61
bool
operator==
(
const
bsf
& a_from)
const
{
62
return
m_value
==a_from.
m_value
;
63
}
64
bool
operator!=
(
const
bsf
& a_from)
const
{
65
return
!
operator==
(a_from);
66
}
67
68
bool
operator==
(
const
T& a_value)
const
{
69
return
m_value
==a_value;
70
}
71
bool
operator!=
(
const
T& a_value)
const
{
72
return
!
operator==
(a_value);
73
}
74
75
operator
const
T& ()
const
{
return
m_value
;}
76
operator
T() {
return
m_value
;}
77
78
/* does not work with qrot
79
bsf& operator+=(const T& a_value){
80
m_value += a_value;
81
m_touched = true;
82
return *this;
83
}
84
*/
85
/* does not work with T=std::string
86
bsf& operator-=(const T& a_value){
87
m_value -= a_value;
88
m_touched = true;
89
return *this;
90
}
91
bsf& operator*=(const T& a_value){
92
m_value *= a_value;
93
m_touched = true;
94
return *this;
95
}
96
*/
97
public
:
98
T&
value
() {
return
m_value
;}
99
const
T&
value
()
const
{
return
m_value
;}
100
void
value
(
const
T& a_value) {
101
if
(a_value!=
m_value
)
m_touched
=
true
;
102
m_value
= a_value;
103
}
104
void
value_no_cmp
(
const
T& a_value) {
105
//if(a_value!=m_value) m_touched = true;
106
m_value
= a_value;
107
}
108
//public: //for style.
109
// bool s2v(const std::string& a_s) {
110
// T v;
111
// if(!to<T>(a_s,v)) return false;
112
// if(v!=m_value) m_touched = true;
113
// m_value = v;
114
// return true;
115
// }
116
public
:
//for iv2sg
117
void
setValue
(
const
T& a_value) {
value
(a_value);}
118
const
T&
getValue
()
const
{
return
m_value
;}
119
protected
:
120
T
m_value
;
121
};
122
123
}}
124
125
#endif
tools::sg::bsf::operator=
bsf & operator=(const T &a_value)
Definition:
bsf:56
tools::sg::field::m_touched
bool m_touched
Definition:
field:63
tools::sg::bsf::operator!=
bool operator!=(const T &a_value) const
Definition:
bsf:71
tools::sg::bsf::value
const T & value() const
Definition:
bsf:99
tools::sg::bsf
Definition:
bsf:19
field
tools::sg::bsf::m_value
T m_value
Definition:
bsf:120
tools::sg::bsf::s_cls
virtual const std::string & s_cls() const
Definition:
bsf:31
tools::sg::bsf::bsf
bsf(const bsf &a_from)
Definition:
bsf:45
tools::sg::bsf::~bsf
virtual ~bsf()
Definition:
bsf:43
tools::sg::field
Definition:
field:25
tools::sg::bsf::value
void value(const T &a_value)
Definition:
bsf:100
tools::sg::bsf::bsf
bsf(const T &a_value)
Definition:
bsf:42
tools::sg::bsf::cast
virtual void * cast(const std::string &a_class) const
Definition:
bsf:27
tools::sg::bsf::bsf
bsf()
Definition:
bsf:40
tools::sg::bsf::operator==
bool operator==(const bsf &a_from) const
Definition:
bsf:61
tools::sg::bsf::value_no_cmp
void value_no_cmp(const T &a_value)
Definition:
bsf:104
tools::sg::field::cast
virtual void * cast(const std::string &a_class) const
Definition:
field:28
tools::sg::field::operator=
field & operator=(const field &)
Definition:
field:57
tools::sg::bsf::getValue
const T & getValue() const
Definition:
bsf:118
tools
inlined C code : ///////////////////////////////////
Definition:
aida_ntuple:26
tools::cmp_cast
void * cmp_cast(const TO *a_this, const std::string &a_class)
Definition:
scast:15
tools::sg::bsf::operator!=
bool operator!=(const bsf &a_from) const
Definition:
bsf:64
tools::sg::bsf::operator=
bsf & operator=(const bsf &a_from)
Definition:
bsf:49
tools::sg::bsf::setValue
void setValue(const T &a_value)
Definition:
bsf:117
tools::sg::bsf::value
T & value()
Definition:
bsf:98
tools::sg::bsf::s_class
static const std::string & s_class()
Definition:
bsf:22
tools::sg::bsf::operator==
bool operator==(const T &a_value) const
Definition:
bsf:68
Generated by
1.8.20