fw4spl
NumericOverflow.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2015.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include <fwAtoms/Numeric.hpp>
8 #include <fwAtoms/Numeric.hxx>
9 
10 #include "fwAtomsPatch/infos/log.hpp"
11 #include "fwAtomsPatch/conditions/NumericOverflow.hpp"
12 
13 
14 namespace fwAtomsPatch
15 {
16 namespace conditions
17 {
18 
19 NumericOverflow::NumericOverflow(::fwAtoms::Base::sptr defaultValue) : Abstract(defaultValue)
20 {
21 }
22 
23 // ----------------------------------------------------------------------------
24 
25 void NumericOverflow::setTreshold(::fwAtoms::Numeric::sptr treshold)
26 {
27  m_treshold = treshold;
28 }
29 
30 // ----------------------------------------------------------------------------
31 
32 bool NumericOverflow::test(::fwAtoms::Base::sptr old,
33  ::fwAtoms::Base::sptr newValue)
34 {
35  return this->test(newValue);
36 }
37 
38 // ----------------------------------------------------------------------------
39 
40 bool NumericOverflow::test(::fwAtoms::Base::sptr value)
41 {
42  if(value->isNumeric())
43  {
44  ::fwAtoms::Numeric::sptr numeric = ::fwAtoms::Numeric::dynamicCast(value);
45  return numeric->getValue<double>() <= m_treshold->getValue<double>();
46  }
47  else
48  {
49  fwAtomsPatchErrorLogMacro("the value is not a numeric");
50  return false;
51  }
52 }
53 
54 // ----------------------------------------------------------------------------
55 
56 
57 NumericOverflow::sptr NumericOverflow::New(::fwAtoms::Base::sptr defaultValue)
58 {
59  NumericOverflow::sptr valueSptr(new NumericOverflow(defaultValue));
60  return valueSptr;
61 }
62 
63 } //conditions
64 } //fwAtomsPatch
Contains functions used to control patching process by defining conditions on objects.
Definition: Abstract.hpp:18
Contains base functionalities used to transform objects from a version to another.
Definition: Abstract.hpp:16
Applies condition on numeric value.