GCC Code Coverage Report


Directory: ./
File: pdserv/src/msrproto/Variable.cpp
Date: 2024-11-17 04:08:36
Exec Total Coverage
Lines: 49 66 74.2%
Branches: 45 102 44.1%

Line Branch Exec Source
1 /*****************************************************************************
2 *
3 * $Id$
4 *
5 * Copyright 2010 Richard Hacker (lerichi at gmx dot net)
6 *
7 * This file is part of the pdserv library.
8 *
9 * The pdserv library is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as published
11 * by the Free Software Foundation, either version 3 of the License, or (at
12 * your option) any later version.
13 *
14 * The pdserv library is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17 * License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with the pdserv library. If not, see <http://www.gnu.org/licenses/>.
21 *
22 *****************************************************************************/
23
24 #include "Variable.h"
25 #include "XmlElement.h"
26
27 using namespace MsrProto;
28
29 /////////////////////////////////////////////////////////////////////////////
30 5236 Variable::Variable (const PdServ::Variable* v, size_t index,
31 const PdServ::DataType& dtype, const PdServ::DataType::DimType& dim,
32 5236 size_t offset):
33 variable(v), index(index),
34 dtype(dtype), dim(dim), offset(offset),
35 10472 memSize(dtype.size * dim.nelem),
36
2/4
✓ Branch 5 taken 5236 times.
✗ Branch 6 not taken.
✓ Branch 21 taken 5236 times.
✗ Branch 22 not taken.
15708 hidden(false)
37 {
38 5236 }
39
40 /////////////////////////////////////////////////////////////////////////////
41 270 void Variable::setDataType(XmlElement &element, const PdServ::DataType& dtype,
42 const PdServ::DataType::DimType& dim) const
43 {
44 // datasize=
45
1/2
✓ Branch 5 taken 270 times.
✗ Branch 6 not taken.
270 XmlElement::Attribute(element, "datasize") << dtype.size;
46
47 // typ=
48 const char *dtstr;
49
4/12
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✓ Branch 10 taken 33 times.
✓ Branch 11 taken 22 times.
✓ Branch 12 taken 113 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 102 times.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
270 switch (dtype.primary()) {
50 case PdServ::DataType::boolean_T : dtstr = "TCHAR"; break;
51 case PdServ::DataType:: uint8_T : dtstr = "TUCHAR"; break;
52 case PdServ::DataType:: int8_T : dtstr = "TCHAR"; break;
53 case PdServ::DataType:: uint16_T : dtstr = "TUSHORT"; break;
54 33 case PdServ::DataType:: int16_T : dtstr = "TSHORT"; break;
55 22 case PdServ::DataType:: uint32_T : dtstr = "TUINT"; break;
56 113 case PdServ::DataType:: int32_T : dtstr = "TINT"; break;
57 case PdServ::DataType:: uint64_T : dtstr = "TULINT"; break;
58 case PdServ::DataType:: int64_T : dtstr = "TLINT"; break;
59 102 case PdServ::DataType:: double_T : dtstr = "TDBL"; break;
60 case PdServ::DataType:: single_T : dtstr = "TFLT"; break;
61 default : dtstr = "COMPOUND"; break;
62 }
63
2/2
✓ Branch 2 taken 33 times.
✓ Branch 3 taken 237 times.
270 if (!dim.isScalar())
64 66 XmlElement::Attribute(element, "typ")
65
1/2
✓ Branch 3 taken 33 times.
✗ Branch 4 not taken.
66 << dtstr
66
3/4
✓ Branch 3 taken 19 times.
✓ Branch 4 taken 14 times.
✓ Branch 6 taken 33 times.
✗ Branch 7 not taken.
33 << (dim.isVector() ? "_LIST" : "_MATRIX");
67 else
68
1/2
✓ Branch 4 taken 237 times.
✗ Branch 5 not taken.
237 XmlElement::Attribute(element, "typ") << dtstr;
69
70 // For vectors:
71 // anz=
72 // cnum=
73 // rnum=
74 // orientation=
75
2/2
✓ Branch 2 taken 33 times.
✓ Branch 3 taken 237 times.
270 if (!dim.isScalar()) {
76
2/4
✓ Branch 2 taken 33 times.
✗ Branch 3 not taken.
✓ Branch 7 taken 33 times.
✗ Branch 8 not taken.
33 XmlElement::Attribute(element, "anz") << dim.nelem;
77 const char *orientation;
78 33 size_t cnum, rnum;
79
80 // Transmit either a vector or a matrix
81
2/2
✓ Branch 2 taken 19 times.
✓ Branch 3 taken 14 times.
33 if (dim.isVector()) {
82 19 cnum = dim.nelem;
83 19 rnum = 1;
84 19 orientation = "VECTOR";
85 }
86 else {
87 14 cnum = dim.back();
88
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 rnum = dim.nelem / cnum;
89 14 orientation = "MATRIX_ROW_MAJOR";
90 }
91
92
2/4
✓ Branch 2 taken 33 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 33 times.
✗ Branch 7 not taken.
33 XmlElement::Attribute(element, "cnum") << cnum;
93
2/4
✓ Branch 2 taken 33 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 33 times.
✗ Branch 7 not taken.
33 XmlElement::Attribute(element, "rnum") << rnum;
94
2/4
✓ Branch 2 taken 33 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 33 times.
✗ Branch 7 not taken.
33 XmlElement::Attribute(element, "orientation") << orientation;
95 }
96 270 }
97
98 /////////////////////////////////////////////////////////////////////////////
99 270 void Variable::addCompoundFields(XmlElement &element,
100 const PdServ::DataType& dtype) const
101 {
102 270 const PdServ::DataType::FieldList& fieldList = dtype.getFieldList();
103
104 270 for (PdServ::DataType::FieldList::const_iterator it = fieldList.begin();
105
1/2
✗ Branch 6 not taken.
✓ Branch 7 taken 270 times.
270 it != fieldList.end(); ++it) {
106 XmlElement field(element.createChild("field"));
107 XmlElement::Attribute(field, "name").setEscaped((*it)->name);
108 XmlElement::Attribute(field, "offset") << (*it)->offset;
109
110 setDataType(element, (*it)->type, (*it)->dim);
111
112 addCompoundFields(field, (*it)->type);
113 }
114 270 }
115
116 /////////////////////////////////////////////////////////////////////////////
117 198 bool Variable::hasChildren(const Variable* v) const
118 {
119
1/2
✓ Branch 6 taken 193 times.
✗ Branch 7 not taken.
193 return (!v or v->variable != variable)
120
3/4
✓ Branch 0 taken 193 times.
✓ Branch 1 taken 5 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 193 times.
391 or DirectoryNode::hasChildren(v);
121 }
122
123 /////////////////////////////////////////////////////////////////////////////
124 311 void Variable::setAttributes(
125 XmlElement &element, bool shortReply, bool derived) const
126 {
127 // index=
128
1/2
✓ Branch 5 taken 311 times.
✗ Branch 6 not taken.
311 XmlElement::Attribute(element, "index") << index;
129
130 // name=
131 // DO NOT REMOVE: Testmanager requires name even with short reply!
132
2/4
✓ Branch 5 taken 311 times.
✗ Branch 6 not taken.
✓ Branch 9 taken 311 times.
✗ Branch 10 not taken.
311 XmlElement::Attribute(element, "name").setEscaped(path());
133
134
2/2
✓ Branch 0 taken 41 times.
✓ Branch 1 taken 270 times.
311 if (shortReply)
135 41 return;
136
137 // alias=
138 // comment=
139
1/2
✗ Branch 8 not taken.
✓ Branch 9 taken 270 times.
270 if (!variable->alias.empty())
140 XmlElement::Attribute(element, "alias") << variable->alias;
141
1/2
✗ Branch 8 not taken.
✓ Branch 9 taken 270 times.
270 if (!variable->comment.empty())
142 XmlElement::Attribute(element, "comment") << variable->comment;
143
144 270 setDataType(element, dtype, dim);
145
146 // text=
147 // FIXME: variable->comment is used twice! 2012-12-14 fp
148
1/2
✗ Branch 8 not taken.
✓ Branch 9 taken 270 times.
270 if (!variable->comment.empty())
149 XmlElement::Attribute(element, "text") << variable->comment;
150
151
5/8
✓ Branch 4 taken 33 times.
✓ Branch 5 taken 237 times.
✓ Branch 6 taken 33 times.
✗ Branch 7 not taken.
✗ Branch 14 not taken.
✓ Branch 15 taken 33 times.
✗ Branch 16 not taken.
✓ Branch 17 taken 270 times.
270 if (childCount() and (derived or hasChildren(this)))
152 XmlElement::Attribute(element, "dir") << 1;
153
154 // hide=
155 // unhide=
156 }
157