DAQ  1.0.0
Data Acquisition System (basic demo)
varvalue.h
Go to the documentation of this file.
1 /*! @brief This file have the interface for VarValue class.
2  @file varvalue.h
3  @author Alvaro Denis <denisacostaq@gmail.com>
4  @date 7/13/2019
5 
6  @copyright
7  @attention <h1><center><strong>COPYRIGHT &copy; 2019 </strong>
8  [<strong>denisacostaq</strong>][denisacostaq-URL].
9  All rights reserved.</center></h1>
10  @attention This file is part of [<strong>DAQs</strong>][DAQs-URL].
11 
12  Redistribution and use in source and binary forms, with or without
13  modification, are permitted provided that the following conditions
14  are met:
15  - 1. Redistributions of source code must retain the above copyright
16  notice, this list of conditions and the following disclaimer.
17  - 2. Redistributions in binary form must reproduce the above copyright
18  notice, this list of conditions and the following disclaimer in the
19  documentation and/or other materials provided with the distribution.
20  - 3. Neither the name of the University nor the names of its contributors
21  may be used to endorse or promote products derived from this software
22  without specific prior written permission.
23 
24  THIS PRODUCT IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
28  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33  THIS PRODUCT, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 
35  [denisacostaq-URL]: https://about.me/denisacostaq "Alvaro Denis Acosta"
36  [DAQs-URL]: https://github.com/denisacostaq/DAQs "DAQs"
37  */
38 #ifndef DATAMODEL_VARVALUE_H
39 #define DATAMODEL_VARVALUE_H
40 
41 #include "src/database-server/data-model/variable.h"
42 
43 /**
44  * @brief The VarValue class define a readed value.
45  * @details A read value is always related to a variable, for a better
46  * understanding check out the following MER diagram.
47  * \dot
48  digraph {
49  graph [layout = dot, rankdir = LR]
50 
51  // Box for entities
52  node [shape=none, margin=0]
53 
54  // One-to-many relation (from one, to many)
55  edge [arrowhead=crow, arrowtail=dot, dir=both]
56 
57  label = "MER variable"
58 
59  // Entities
60  Variable [label=<
61  <table border="0" cellborder="1" cellspacing="0" cellpadding="4">
62  <tr><td bgcolor="darkseagreen">Variable</td></tr>
63  <tr><td port="id" align="left">id: integer</td></tr>
64  <tr><td align="left">name: char(50)</td></tr>
65  <tr><td align="left">color: char(50)</td></tr>
66  </table>
67  >]
68 
69  VariableValue [label=<
70  <table border="0" cellborder="1" cellspacing="0" cellpadding="4">
71  <tr><td bgcolor="darkseagreen">VariableValue</td></tr>
72  <tr><td align="left">id: integer</td></tr>
73  <tr><td align="left">value: double</td></tr>
74  <tr><td align="left">timestamp: integer</td></tr>
75  <tr><td port="fk" align="left">variable_id: integer</td></tr>
76  </table>
77  >]
78 
79  // Relationships
80  Variable:id->VariableValue:fk [label="1:*",len=1.00];
81  }
82  * \enddot
83  */
84 class VarValue {
85  public:
86  VarValue() = default;
87  VarValue(const Variable &variable, double val, std::uint64_t ts);
88  VarValue(Variable &&variable, double &&val, std::uint64_t &&ts);
89  VarValue(VarValue &&var) noexcept;
90  VarValue(const VarValue &var) = default;
91 
92  const Variable &variable() const noexcept;
93  void set_vaiable(const Variable &var) noexcept;
94  double val() const noexcept;
95  void set_val(double val) noexcept;
96  std::uint64_t timestamp() const noexcept;
97  void set_timestamp(std::uint64_t ts) noexcept;
98  const std::string &name() const noexcept;
99 
101  VarValue v{};
102  v.val_ = this->val_;
103  v.variable_ = this->variable_;
104  v.timestamp_ = this->timestamp_;
105  return v;
106  }
107 
108  private:
110  double val_;
112 };
113 
114 #endif // DATAMODEL_VARVALUE_H
double val_
Definition: varvalue.h:110
VarValue(VarValue &&var) noexcept
Definition: varvalue.cc:48
Variable variable_
Definition: varvalue.h:109
VarValue(Variable &&variable, double &&val, std::uint64_t &&ts)
Definition: varvalue.cc:45
Definition: variable.h:44
std::uint64_t timestamp() const noexcept
Definition: varvalue.cc:61
VarValue()=default
std::uint64_t timestamp_
Definition: varvalue.h:111
const Variable & variable() const noexcept
Definition: varvalue.cc:53
double val() const noexcept
Definition: varvalue.cc:57
VarValue DeepCopy()
Definition: varvalue.h:100
void set_val(double val) noexcept
Definition: varvalue.cc:59
const std::string & name() const noexcept
Definition: varvalue.cc:65
VarValue(const VarValue &var)=default
void set_vaiable(const Variable &var) noexcept
Definition: varvalue.cc:55
void set_timestamp(std::uint64_t ts) noexcept
Definition: varvalue.cc:63