141 Commits
4.0.1 ... 5.2.2

Author SHA1 Message Date
Andrew Johnson
e803240fbf Update SHRLIB_VERSION 2019-03-20 13:57:00 -05:00
Michael Davidsaver
54c07f705f update docs 2019-03-12 19:45:30 -07:00
Michael Davidsaver
fa23ddd370 NTTable::getColumnNames() wrong field 2019-03-12 17:42:36 -07:00
Andrew Johnson
41d56fdf89 Update version numbers and formatting in documentation 2018-12-17 16:05:45 -06:00
Andrew Johnson
a65fc3ef30 Update and unify README.md 2018-12-17 16:04:09 -06:00
Michael Davidsaver
b69bc44974 5.2.1 2018-11-26 11:52:01 -08:00
Michael Davidsaver
a90f0173a7 drop redundant generated html 2018-11-26 11:50:39 -08:00
Michael Davidsaver
83342beb7e travis-ci dropped 3.14 2018-10-29 19:42:12 -07:00
Michael Davidsaver
f6e6cf037f update travis-ci 2018-10-29 17:57:18 -07:00
Andrew Johnson
80920ae0b0 Clean up warnings
Removed unused member variables 'bool dim'.
2018-01-04 17:16:34 -06:00
Michael Davidsaver
1f7667b22d drop prototype PVNTField::createAlarmLimit
not implemented.
2017-12-19 17:15:37 -06:00
Ralph Lange
e15e84fb14 jenkins-ci: fix/update CloudBees jobs 2017-12-19 09:58:49 +01:00
Andrew Johnson
ba2e1c8a1d Update documentation for 5.2.0 release 2017-12-14 17:30:55 -06:00
Andrew Johnson
fb6873e9a3 Applied documentation changes since 5.0.0 to the master branch 2017-12-14 17:21:40 -06:00
Michael Davidsaver
2f4c0eea9d missing include 2017-12-12 09:43:25 -06:00
Andrew Johnson
a2b635c2fe Include <top>/../RELEASE.<host>.local 2017-12-06 20:35:26 -06:00
Andrew Johnson
abd029aa71 Use 'make test-results' in travis-build script 2017-11-30 12:00:28 -06:00
Andrew Johnson
57c6d07a93 Unify .gitignore file 2017-11-30 11:59:45 -06:00
Michael Davidsaver
91c5136883 Test for missing "attribute" array in NTNDArray 2017-11-21 10:59:23 -06:00
Ralph Lange
5e151c3b7a jenkins: remove microbench option and pvCommon dependency from CB build 2017-11-15 17:25:51 +01:00
Ralph Lange
fc4b51cb49 travis-ci: consolidate travis configuration 2017-09-28 15:10:04 +02:00
Ralph Lange
fc703958b3 travis-ci: minor configuration fix 2017-09-27 15:34:02 +02:00
Ralph Lange
1b156c92cd travis-ci: update/streamline configuration for EPICS 7 2017-09-27 12:00:06 +02:00
Marty Kraimer
2c75f1d1e9 Merge pull request #13 from mrkraimer/master
create travis files
2017-09-13 05:31:22 -04:00
mrkraimer
e03096c35e create travis files 2017-09-13 05:14:10 -04:00
Bruno Martins
4b0970ffcb Set tags to false inside reset. Fixes #11 2017-07-26 17:19:45 +02:00
Dave Hickin
048d6ef737 NTUnionBuilder: Add missing value() function
Add missing function NTUnionBuilder::value() to allow the union type of
the NTUnion's value field to be specified.
2016-09-09 18:07:59 +01:00
Ralph Lange
4768444b8a Add QtCreator wildcard to .gitignore 2016-07-28 11:56:26 +02:00
Dave Hickin
0ce3613acc SHRLIB: Set version to 5.2 2016-07-22 17:06:37 +01:00
Dave Hickin
d13696f943 SHRLIB: Add ABI version (5.1) 2016-07-22 17:01:38 +01:00
Dave Hickin
e6597bc2f0 Update source boilerplate for new LICENSE file 2016-07-22 16:56:01 +01:00
Dave Hickin
3d4083221d Remove COPYRIGHT file
Copyright is now in LICENSE file
2016-07-22 16:43:57 +01:00
Dave Hickin
6b64adc150 Update LICENSE to new version 2016-07-22 16:43:24 +01:00
Ralph Lange
c35e78b797 jenkins: update CloudBees jobs to new standard 2016-07-22 14:56:24 +02:00
Dave Hickin
08234150dc Add tests for is_a and isCompatible for PVStructures 2016-04-12 03:24:47 +01:00
Dave Hickin
5dfc4ffd16 Rename ntScalarArray ntMatrix in NTMatrix tests 2016-04-12 03:23:03 +01:00
Dave Hickin
ff4b88754f Add missing is_a(PVStructurePtr) implementations 2016-04-12 03:19:42 +01:00
Dave Hickin
8794d5b6c0 Run NTAttribute and NTContinuum unit tests 2016-04-12 03:16:48 +01:00
Dave Hickin
00aab51203 Documentation: Remove old versions 2016-03-18 22:00:29 +00:00
Dave Hickin
df023e6103 Documentation: Change to release-based versioning
Replace dated documentation scheme by one using release version.
2016-03-18 21:56:15 +00:00
Ralph Lange
e07a42fb48 jenkins: switch to Base 3.15.3 2016-02-16 10:17:24 +01:00
Dave Hickin
6dd63a74a6 Make addTags() non-virtual 2016-02-16 08:32:27 +00:00
dhickin
f90549aba8 Merge pull request #7 from mdavidsaver/master
Move headers to pv/
2016-02-10 20:45:01 +00:00
Michael Davidsaver
4f3f6784d4 adjust Makefiles 2016-02-09 19:25:37 -05:00
Michael Davidsaver
cfe939ca7a Moves source and headers
src/nt/*.h   => src/pv/*.h
src/nt/*.cpp => src/*.cpp
test/nt/*.*  => test/*.*
2016-02-09 19:25:37 -05:00
Dave Hickin
eb440e4662 Corrections to ntCPP.html 2015-10-17 10:29:39 +01:00
Dave Hickin
bd5d0dee12 Add new (markdown) README 2015-10-17 00:33:02 +01:00
Dave Hickin
3b645933f5 Javadoc corrections 2015-10-16 19:19:58 +01:00
Dave Hickin
5cca3a10ac Rename variable to match header. 2015-10-16 15:47:38 +01:00
Dave Hickin
bab0d964ab Add missing implementation of NTScalarArray::value
Use value in unit tests instead of deprecated arrayValue.
2015-10-16 15:46:56 +01:00
Dave Hickin
51d4d270cd Multiple Doxygen improvements 2015-10-16 15:42:56 +01:00
Dave Hickin
3aa1f533bf Add new version of ntCPP.html
Only state that the new types have been added.
Document these in next version.
2015-10-16 15:38:55 +01:00
Dave Hickin
cebc68474d Update TODO 2015-10-16 15:37:03 +01:00
Dave Hickin
a1ac2f41b4 Doxygen fix 2015-10-09 11:44:36 +01:00
Dave Hickin
d8eb50bff8 Release notes: add for 5.0 and improve for 4.0
Add list of new supported types and summary of API changes.
2015-10-08 10:05:42 +01:00
Ralph Lange
e93d1c5c42 jenkins: fix CloudBees doc job 2015-09-28 15:00:47 +02:00
Ralph Lange
8e97c2e8bd jenkins: adapt doc script to new CloudBees jenkins job 2015-09-14 15:13:51 +02:00
Dave Hickin
2bc01a482e Doxygen fixes 2015-09-05 07:34:18 +01:00
Dave Hickin
dd955ea81e Ammend license notice in unit tests
Replaced references to "EPICS pvData" with "this software" in per-file
copyright notice - consistent with other files.
2015-09-04 09:41:08 +01:00
Dave Hickin
a0a19bcfd9 Fix bug in NTUtils::is_a
Previous implementation matches <type-name>:1x.0 and <type-name>:1.0,
depending on the order of the arguments, e.g.
NTUtils::is_a("epics:nt/NTTable:11.0", "epics:nt/NTTable:1.0") returned
true. Fix this and add unit tests to cover this.
2015-09-04 09:39:27 +01:00
Dave Hickin
16b46448c0 License and copyright
Replaced references to "EPICS pvData" and "EPICS JavaIOC" with "this
software" in per-file copyright notice - consistent with other files.
Add BNL and DLS to copyright and legal disclaimers.
2015-09-04 09:24:54 +01:00
Dave Hickin
e5947aa0a2 Add unit tests for NTNDArrayAttribute 2015-09-04 08:37:09 +01:00
Dave Hickin
3c30598a56 Add unit test for NTHistogram 2015-09-04 00:34:41 +01:00
Dave Hickin
85673cadad Add unit test for NTContinuum 2015-09-04 00:33:57 +01:00
Dave Hickin
db0d1e8f9e Fix for NTHistogram::isCompatible()
Correct null pointer check - logic was inverted
2015-09-04 00:33:06 +01:00
Dave Hickin
99f9e0429f Remove duplicate NTField 2015-09-03 14:10:08 +01:00
Dave Hickin
3dc852e2b7 Delete commented out code 2015-09-03 14:09:36 +01:00
Dave Hickin
d9c3dfcf26 Use NTNDArrayAttribute in constructing NTNDArray
Use NTNDArrayAttribute wrapper to construct NTAttributes in NTNDArray.
Delete unused attribute string.
2015-09-03 14:08:56 +01:00
Ralph Lange
38f7d6bea1 jenkins: add configurable dependent branch versions 2015-09-03 13:44:17 +02:00
Matej Sekoranja
4f38e7904d fixed rtems/vxworks compilation 2015-09-01 21:12:47 +02:00
Matej Sekoranja
ad03935c5b Merge pull request #4 from anjohnson/add-license-file
Add license and copyright files
2015-09-01 20:06:49 +02:00
Dave Hickin
5574452b08 Call addIsConnected() in unit tests
for multi-channel types
2015-09-01 16:50:46 +01:00
Dave Hickin
649cd6800d Make isConnected optional in multi channel types 2015-09-01 15:55:21 +01:00
Dave Hickin
05a7a6923f Implement NTNDArray::isValid() 2015-09-01 15:53:52 +01:00
Dave Hickin
f5226f23dc Implement NTNDArray::isCompatible(Structure)
Add implementation of NTNDArray::isCompatible(Structure). Implement
NTNDArray::isCompatible(PVStructure) in terms of this.
2015-09-01 15:53:09 +01:00
Dave Hickin
e1fdcfcab0 Add implementation of NTID 2015-09-01 15:50:18 +01:00
Dave Hickin
5ec16a1772 Fix build error
boolean replaced by bool
2015-09-01 02:40:14 +01:00
Dave Hickin
ba64c6a6a5 Add isValid() implementations
for NTMultiChannel, NTScalarMultiChannel, NTTable and NTURI.
2015-08-31 23:53:10 +01:00
Dave Hickin
ed9a707f14 More efficient implementation of NTTable
Cache the value field. Allows simpler implementation of getColumn().
2015-08-31 23:50:51 +01:00
Dave Hickin
6ec5fb6ef9 Add implentations of isValid()
for NTAggregate, NTAttibute, NTContinuum, NTEnum, NTHistogram, NTMatrix,
NTNameValue, NTNDArrayAttribute, NTScalar, NTScalarArray and NTUnion.
2015-08-30 23:46:02 +01:00
Dave Hickin
ddab44823f Use NTAttribute wrapper in NTNDArray
Use the wrapper NTAttribute wrapper NTNDArrayAttribute to test the
attribute field in implementation of NTNDArray::isCompatible(Structure).
2015-08-29 11:09:32 +01:00
Dave Hickin
d54060576a Add implementation of isCompatible(Structure)
for all types except NTNDArray and implement isCompatible(PVStructure)
in terms of it.
2015-08-29 11:06:37 +01:00
Dave Hickin
e8a9beec07 Remove excess blank lines 2015-08-29 11:00:40 +01:00
Dave Hickin
84304d9b4e Add utility class for parsing NT IDs 2015-08-21 14:46:26 +01:00
Dave Hickin
b62cb22818 Added NTNDArrayAttribute
Added wrapper for NTAttributes extended as required by NTNDArray.
2015-08-21 07:45:16 +01:00
Dave Hickin
1e6fb17e92 Add NTURI 2015-08-21 06:47:52 +01:00
Dave Hickin
bc2622f70a Add getColumnNames() to NTTable 2015-08-21 06:46:17 +01:00
Dave Hickin
da81f8db83 Add NTHistogram 2015-08-21 03:55:35 +01:00
Dave Hickin
7c58eae97e Add NTContinuum 2015-08-21 03:55:04 +01:00
Dave Hickin
0b3e1c9fd1 Add isValid() and overloads of is_a() and isCompatible()
Add convenience methods is_a(PVStructure). Add overloads of isCompatible
taking a Structure since implementation of isCompatible(PVStructure)
only uses introspection interface. Implement for NTScalar and
NTScalarArray. Add isValid() function that checks NT is valid through data
interface.
2015-08-21 01:15:40 +01:00
Dave Hickin
59afc5335a Fixed unit NTTable test failure 2015-08-20 18:32:18 +01:00
Dave Hickin
399a39a20a Tell git to ignore build output of unit tests 2015-08-20 17:26:03 +01:00
Dave Hickin
000dde0454 Make attach* functions return bool in multi-channel types
The attachAlarm and attachTimeStamps() return true if successful, false
otherwise in other classes. In NTMultiChannel and NTScalarMultiChannel
they returned void. Bring multi-channel behaviour in line.
2015-08-20 17:23:59 +01:00
Dave Hickin
5076057d8d Make isConnected optional field of multi-channel types
A boolean[] isConnected field was included in all constructed
NTMultiChannels and NTScalarMultiChannels. However this is neither a
required nor optional field of these types. Applications use this
though, (specifically pvaClient) so treat as if optional field. Add
addIsConnected() function to builders and retain isConnected() in
wrapper classes. Leave isConnected field in structures until clients
updated.
2015-08-20 17:19:18 +01:00
Dave Hickin
fd60732a8c Rename add() addColumn() in NTTable
Function for adding columns to table (i.e. to value subfield) was
add(ScalarType). However add(Field) adds extra field to top-level
structure. Rename former to avoid confusion and as more meaningful
name. Update unit tests.
2015-08-20 17:07:27 +01:00
Dave Hickin
002a465705 Clear up confusion between labels and column names
The labels are strings used in the displaying of the columns of a table
e.g. column titles or headers. The column names of an NTTable are the
names of the fields containing the column data. There was some confusion
in the implementation between these. Rename the labels variable
columnNames and correct the comments. Tables were created with labels
equal to the column names. Retain this behaviour for backwards
compatibility, as a sensible default and to always create a valid table,
but document this.
2015-08-20 17:03:27 +01:00
dhickin
28186f0e3d Merge pull request #6 from dhickin/add_missing_types
Add normative types
2015-08-20 16:35:53 +01:00
Dave Hickin
fc037cf6dc Add unit tests for NTAttribute 2015-08-20 16:16:58 +01:00
Dave Hickin
5ddcc70993 Add getName() and getTags() functions to NTAttribute 2015-08-20 16:16:34 +01:00
Dave Hickin
dc93316856 Merge branch 'add_missing_types' of github.com:dhickin/normativeTypesCPP into add_missing_types 2015-08-20 09:44:27 +01:00
Dave Hickin
b40eca79cf Add NTAttribute including builder 2015-08-20 08:43:27 +01:00
Dave Hickin
f6f5539f7b Add NTAggregate including builder and unit tests 2015-08-20 08:41:45 +01:00
Dave Hickin
0d66034092 Add NTUnion including builder and unit tests 2015-08-20 08:01:29 +01:00
Dave Hickin
1de2666993 Add NTEnum including builder and unit tests 2015-08-20 07:59:29 +01:00
Dave Hickin
7d0b6d86ea Add NTMatrix including builder and unit tests 2015-08-20 07:56:20 +01:00
Ralph Lange
bef1a86b8b jenkins: fix cut-n-paste issue in doc job 2015-08-18 16:54:42 +02:00
Ralph Lange
8f66d21cca Remove mercurial debris (.hg*) 2015-08-18 16:10:42 +02:00
Ralph Lange
f4b7bdbdf0 jenkins: remove hgweb job; split build and doc jobs; update EPICS Base version 2015-08-18 16:10:11 +02:00
Dave Hickin
5f8922e349 Incremented number of tests in NTTable test plan 2015-08-13 12:46:27 +01:00
Dave Hickin
5b7c6ea4d8 Fixed NTTable units tests for extra fields
After fix for NTTable extra fields not being created was merged, unit
tests failed. Tests were wrong. Test was checking number of fields of
constructed structure against number expected without the extra fields.
Corrected check and added checks for extra fields.
2015-08-13 10:59:15 +01:00
dhickin
08f8b56740 Merge pull request #5 from brunoseivam/patch-1
Fix extra fields not being created
2015-08-13 09:51:02 +01:00
Bruno Martins
b52fc4fce8 Fix extra fields not being created
FieldBuilder::createStructure() was being called too early inside NTTableBuilder::createStructure(), preventing extra fields from being properly created.
2015-08-12 22:46:46 -04:00
Andrew Johnson
b976d918d5 Resolves epics-base/normativeTypesCPP #1 2015-08-11 17:43:31 -05:00
Andrew Johnson
c7a58af787 Add COPYRIGHT file 2015-08-11 16:53:36 -05:00
Dave Hickin
b1143fea9e Make #endif comments match #ifdef in inclusion guards 2015-08-06 14:06:14 +01:00
Dave Hickin
efa9dff1d4 Change references to NTTableBuilder to NTScalarBuilder in NTScalar 2015-08-06 14:04:47 +01:00
Dave Hickin
3b9f8a26c0 Include ntscalarMultiChannel.h in nt.h 2015-08-06 13:57:11 +01:00
dhickin
f64329e661 Merge pull request #3 from dhickin/NTScalarMultiChannel
Add NTScalarMultiChannel
2015-08-05 22:13:19 +01:00
Dave Hickin
8b9a8e7050 Add tests for NTScalarMultiChannel 2015-08-04 21:32:34 +01:00
Dave Hickin
5381a0c294 Add NTScalarMultiChannel 2015-08-04 21:30:13 +01:00
Andrew Johnson
36b8e60152 Fix module name in sources LICENSE reference 2015-08-03 16:47:28 -05:00
Andrew Johnson
f226c7ac96 Add LICENSE file copied from pvDataCPP 2015-08-03 16:23:21 -05:00
Andrew Johnson
2f54b89227 Added .gitignore file 2015-06-16 18:06:08 -05:00
Andrew Johnson
ec02b9f7ee Cleanup: Remove extraneous / from SRC 2015-06-08 17:47:14 -05:00
dhickin
efff7f5041 Improve thread-safety of NTNDArray. 2015-06-08 10:34:10 +01:00
dhickin
8c292eeebc Reorder optional fields to consistent order to match new NT spec. 2015-05-11 14:02:18 +01:00
dhickin
25e8c65bb0 Reorder declarations/definitions. 2015-04-22 14:55:40 +01:00
dhickin
f47b059a5b Add definition of missing uniqueId() function. 2015-04-22 14:47:34 +01:00
dhickin
16d8284131 merge branch release/4.0 to default. 2015-04-22 14:42:00 +01:00
Ralph Lange
ef4a9d6b4b jenkins: fix cloudbees script (commands must return 0) 2014-12-19 14:16:57 +01:00
Ralph Lange
8ec19d25f1 jenkins: create and update documentation in only one build configuration 2014-12-19 13:18:23 +01:00
Matej Sekoranja
2d3b415c00 removed bin dbd from upload TAR 2014-12-16 10:43:47 +01:00
Matej Sekoranja
177a048220 added jenkins support 2014-12-15 23:26:01 +01:00
Marty Kraimer
acd986c19d work on doxygen 2014-12-15 08:31:41 -05:00
dhickin
3cb954aefa make local RELEASE.local files take precedence over those in TOP/.. 2014-12-09 13:48:15 +00:00
dhickin
bffeca57a8 Added tag 4.0.2 for changeset e4b8d66cee36 2014-12-05 12:07:35 +00:00
dhickin
e8a04138b0 Added dated version (20141009) for latest html documentation. 2014-12-04 16:05:51 +00:00
dhickin
9f5aec1609 Corrected some spelling and some minor formatting issues. 2014-12-04 15:49:43 +00:00
dhickin
8dadad8101 make "local" *.local files take precedence over those in TOP/.. 2014-12-03 16:55:25 +00:00
dhickin
9cc7c65df6 include CONFIG_SITE.local instead of CONFIG.local at top-level. 2014-12-03 16:10:23 +00:00
Matej Sekoranja
518718357c Added tag 4.0.1 for changeset 1c140dd0e199 2014-11-11 17:03:05 +01:00
90 changed files with 15887 additions and 6037 deletions

10
.ci/travis-build.sh Executable file
View File

@@ -0,0 +1,10 @@
#!/bin/sh
set -e -x
make -j2 $EXTRA
if [ "$TEST" != "NO" ]
then
make -j2 tapfiles
make -j2 -s test-results
fi

107
.ci/travis-prepare.sh Executable file
View File

@@ -0,0 +1,107 @@
#!/bin/sh
set -e -x
CURDIR="$PWD"
cat << EOF > $CURDIR/configure/RELEASE.local
EPICS_BASE=$HOME/.source/epics-base
EOF
install -d "$HOME/.source"
cd "$HOME/.source"
add_gh_flat() {
MODULE=$1
REPOOWNER=$2
REPONAME=$3
BRANCH=$4
MODULE_UC=$(echo $MODULE | tr 'a-z' 'A-Z')
( git clone --quiet --depth 5 --branch $BRANCH https://github.com/$REPOOWNER/$REPONAME.git $MODULE && \
cd $MODULE && git log -n1 )
cat < $CURDIR/configure/RELEASE.local > $MODULE/configure/RELEASE.local
cat << EOF >> $CURDIR/configure/RELEASE.local
${MODULE_UC}=$HOME/.source/$MODULE
EOF
}
# not recursive
git clone --quiet --depth 5 --branch "$BRBASE" https://github.com/${REPOBASE:-epics-base}/epics-base.git epics-base
(cd epics-base && git log -n1 )
add_gh_flat pvData ${REPOPVD:-epics-base} pvDataCPP ${BRPVD:-master}
if [ -e $CURDIR/configure/RELEASE.local ]
then
cat $CURDIR/configure/RELEASE.local
fi
EPICS_HOST_ARCH=`sh epics-base/startup/EpicsHostArch`
# requires wine and g++-mingw-w64-i686
if [ "$WINE" = "32" ]
then
echo "Cross mingw32"
sed -i -e '/CMPLR_PREFIX/d' epics-base/configure/os/CONFIG_SITE.linux-x86.win32-x86-mingw
cat << EOF >> epics-base/configure/os/CONFIG_SITE.linux-x86.win32-x86-mingw
CMPLR_PREFIX=i686-w64-mingw32-
EOF
cat << EOF >> epics-base/configure/CONFIG_SITE
CROSS_COMPILER_TARGET_ARCHS+=win32-x86-mingw
EOF
fi
if [ "$STATIC" = "YES" ]
then
echo "Build static libraries/executables"
cat << EOF >> epics-base/configure/CONFIG_SITE
SHARED_LIBRARIES=NO
STATIC_BUILD=YES
EOF
fi
case "$CMPLR" in
clang)
echo "Host compiler is clang"
cat << EOF >> epics-base/configure/os/CONFIG_SITE.Common.$EPICS_HOST_ARCH
GNU = NO
CMPLR_CLASS = clang
CC = clang
CCC = clang++
EOF
# hack
sed -i -e 's/CMPLR_CLASS = gcc/CMPLR_CLASS = clang/' epics-base/configure/CONFIG.gnuCommon
clang --version
;;
*)
echo "Host compiler is default"
gcc --version
;;
esac
cat <<EOF >> epics-base/configure/CONFIG_SITE
USR_CPPFLAGS += $USR_CPPFLAGS
USR_CFLAGS += $USR_CFLAGS
USR_CXXFLAGS += $USR_CXXFLAGS
EOF
# set RTEMS to eg. "4.9" or "4.10"
# requires qemu, bison, flex, texinfo, install-info
if [ -n "$RTEMS" ]
then
echo "Cross RTEMS${RTEMS} for pc386"
curl -L "https://github.com/mdavidsaver/rsb/releases/download/20171203-${RTEMS}/i386-rtems${RTEMS}-trusty-20171203-${RTEMS}.tar.bz2" \
| tar -C / -xmj
sed -i -e '/^RTEMS_VERSION/d' -e '/^RTEMS_BASE/d' epics-base/configure/os/CONFIG_SITE.Common.RTEMS
cat << EOF >> epics-base/configure/os/CONFIG_SITE.Common.RTEMS
RTEMS_VERSION=$RTEMS
RTEMS_BASE=$HOME/.rtems
EOF
cat << EOF >> epics-base/configure/CONFIG_SITE
CROSS_COMPILER_TARGET_ARCHS += RTEMS-pc386-qemu
EOF
fi
make -j2 -C epics-base $EXTRA
make -j2 -C pvData $EXTRA

14
.gitignore vendored Normal file
View File

@@ -0,0 +1,14 @@
/cfg/
/bin/
/lib/
/db/
/dbd/
/html/
/include/
/templates/
/configure/*.local
O.*/
/QtC-*
*.orig
*.log
.*.swp

View File

@@ -1,8 +0,0 @@
[branchname]
master = master
develop = default
feature = feature/
release = release/
hotfix = hotfix/
support = support/

View File

@@ -1,20 +0,0 @@
QtC*
syntax: glob
.DS_Store
./bin
./include
./lib
./doc
./db
./dbd
./envPaths
./documentation/html
./O.*
./*.pyc
./*.so
./documentation/html
./RELEASE.local
./CONFIG_SITE.local
syntax: regexp

View File

@@ -1,7 +0,0 @@
b9a943e6828731a8a89e811818b2d91faff69d86 1.0-BETA
aaa5f5840b7eea8afaafb4d13a49bf78975aac0f 4.0.0
aaa5f5840b7eea8afaafb4d13a49bf78975aac0f 4.0.0
df4c65e13c2cfaa92e42f84a7afc97c81b5f3888 4.0.0
df4c65e13c2cfaa92e42f84a7afc97c81b5f3888 4.0.0
ec29bda853f50fa501cbcf3ffd836a1ef2adcdd4 4.0.0
0daade17a7440f970750db4a8388e0cee2d04f17 4.0.1

31
.travis.yml Normal file
View File

@@ -0,0 +1,31 @@
sudo: false
dist: trusty
language: c++
compiler:
- gcc
addons:
apt:
packages:
- libreadline6-dev
- libncurses5-dev
- perl
- clang
- g++-mingw-w64-i686
- qemu-system-x86
install:
- ./.ci/travis-prepare.sh
script:
- ./.ci/travis-build.sh
env:
- BRBASE=7.0
- BRBASE=7.0 CMPLR=clang
- BRBASE=7.0 EXTRA="CMD_CXXFLAGS=-std=c++98"
- BRBASE=7.0 EXTRA="CMD_CXXFLAGS=-std=c++11"
- BRBASE=7.0 CMPLR=clang EXTRA="CMD_CXXFLAGS=-std=c++11"
- BRBASE=7.0 WINE=32 TEST=NO STATIC=YES
- BRBASE=7.0 WINE=32 TEST=NO STATIC=NO
- BRBASE=7.0 RTEMS=4.10 TEST=NO
- BRBASE=7.0 RTEMS=4.9 TEST=NO
- BRBASE=3.16
- BRBASE=3.15
- BRBASE=3.14

2366
Doxyfile

File diff suppressed because it is too large Load Diff

65
LICENSE Normal file
View File

@@ -0,0 +1,65 @@
Copyright and License Terms
---------------------------
Copyright (c) 2006-2016 Martin R. Kraimer
Copyright (c) 2006-2016 UChicago Argonne LLC, as Operator of Argonne
National Laboratory.
Copyright (c) 2006 Deutsches Elektronen-Synchrotron,
Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY.
Copyright (c) 2007-2016 Control System Laboratory,
(COSYLAB) Ljubljana Slovenia
Copyright (c) 2010-2016 Brookhaven Science Associates, as Operator
of Brookhaven National Laboratory
Copyright (c) 2011-2016 Diamond Light Source Limited,
(DLS) Didcot, United Kingdom
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
________________________________________________________________________
Additional Disclaimers
----------------------
This software is copyright in part by these institutions:
* Brookhaven Science Associates, as Operator of Brookhaven
National Laboratory, New York, USA
* Control System Laboratory, Ljubljana, Slovenia
* Deutsches Elektronen-Synchroton, Member of the Helmholtz
Association, Hamburg, Germany
* Diamond Light Source Limited, Didcot, United Kingdom
* Helmholtz-Zentrum Berlin fuer Materialien und Energie m.b.H.,
Berlin, Germany.
* UChicage Argonne LLC, as Operator of Argonne National Laboratory,
Illinois, USA
In no event shall these institutions be liable to any party for direct,
indirect, special, incidental, or consequential damages arising out of
the use of this software, its documentation, or any derivatives thereof,
even if advised of the possibility of such damage.
These institutions specifically disclaim any warranties, including, but
not limited to, the implied warranties of merchantability, fitness for a
particular purpose, and non-infringement. This software is provided on
an "as is" basis, and these institutions have no obligation to provide
maintenance, support, updates, enhancements, or modifications.

4
README
View File

@@ -1,4 +0,0 @@
Since the Normative Types specification is not yet at Public Working Draft level,
any implementation must be considered alpha. The implementations of helpers under
this repo must be considered alpha level.

17
README.md Normal file
View File

@@ -0,0 +1,17 @@
# normativeTypesCPP
The EPICS **Normative Types** are a set of standard high-level data types, designed to aid interoperability between EPICS PVA applications.
This normativeTypesCPP module is a part of the EPICS software toolkit that provides C++ helper classes which implement the EPICS Normative Types.
## Links
- General information about EPICS can be found at the
[EPICS Controls website](https://epics-controls.org).
- API documentation for this module can be found in its
documentation directory, in particular the file
normativeTypesCPP.html
## Building
This module is included as a submodule of a full EPICS 7 release and will be compiled during builds of that software.

View File

@@ -29,9 +29,6 @@ USR_CPPFLAGS += --coverage
USR_LDFLAGS += --coverage
endif
INSTALL_INCLUDE = $(INSTALL_LOCATION)/include/pv
USR_INCLUDES += -I $(INSTALL_LOCATION)/include
-include $(TOP)/../CONFIG_SITE.local
-include $(TOP)/configure/CONFIG_SITE.local
-include $(TOP)/../CONFIG.local

View File

@@ -1,32 +1,40 @@
#RELEASE Location of external products
# RELEASE - Location of external support modules
#
# IF YOU MAKE ANY CHANGES to this file you MUST at least run
# "gnumake" in this directory afterwards; you usually need
# to run "gnumake rebuild" in the application's top level
# directory each time this file is changed.
# IF YOU CHANGE ANY PATHS in this file or make API changes to
# any modules it refers to, you should do a "make rebuild" in
# this application's top level directory.
#
# NOTE: The build does not check dependencies against files
# that are outside this application, thus you should run
# "gnumake distclean install" in the top directory each time
# EPICS_BASE, SNCSEQ, or any other external module defined
# in the RELEASE file is rebuilt.
# The EPICS build process does not check dependencies against
# any files from outside the application, so it is safest to
# rebuild it completely if any modules it depends on change.
#
# Host/target specific settings can be specified in files named
# Host- or target-specific settings can be given in files named
# RELEASE.$(EPICS_HOST_ARCH).Common
# RELEASE.Common.$(T_A)
# RELEASE.$(EPICS_HOST_ARCH).$(T_A)
#
# This file is parsed by both GNUmake and an EPICS Perl script,
# so it may ONLY contain definititions of paths to other support
# modules, variable definitions that are used in module paths,
# and include statements that pull in other RELEASE files.
# Variables may be used before their values have been set.
# Build variables that are NOT used in paths should be set in
# the CONFIG_SITE file.
TEMPLATE_TOP=$(EPICS_BASE)/templates/makeBaseApp/top
# Variables and paths to dependent modules:
#MODULES = /path/to/modules
#MYMODULE = $(MODULES)/my-module
#If using the sequencer, point SNCSEQ at its top directory:
#SNCSEQ=$(EPICS_BASE)/../modules/soft/seq
# If building the EPICS modules individually, set these:
#EPICS_PVDATA = $(MODULES)/pvData-7.0.0
#EPICS_LIBCOM = $(MODULES)/libcom-3.17.0
#EPICS_BASE = $(MODULES)/core-7.0.1
# EPICS_BASE usually appears last so other apps can override stuff:
#EPICS_BASE=/opt/epics/base
# Set RULES here if you want to use build rules from elsewhere:
#RULES = $(MODULES)/build-rules
#Capfast users may need the following definitions
#CAPFAST_TEMPLATES=
#SCH2EDIF_PATH=
-include $(TOP)/configure/RELEASE.local
# These allow developers to override the RELEASE variable settings
# without having to modify the configure/RELEASE file itself.
-include $(TOP)/../RELEASE.local
-include $(TOP)/../RELEASE.$(EPICS_HOST_ARCH).local
-include $(TOP)/configure/RELEASE.local

View File

@@ -1,4 +0,0 @@
<h1>Release 4.0 IN DEVELOPMENT</h1>
<p>This is the first release of normativeTypesCPP that is part of an official
EPICS V4 release.
It is a major rewrite of the previous versions of normativeTypesCPP.</p>

View File

@@ -1,7 +1,132 @@
Release 4.0 IN DEVELOPMENT
===========
# normativeTypes Module
This document summarizes the changes to the module between releases.
## Release 5.2.2
- Fix NTTable::getColumnNames().
## Release 5.2.1 (EPICS 7.0.2, Dec 2018)
* No functional changes.
* Removal of declaration for unimplemented PVNTField::createAlarmLimit() and elimination of unused variables.
## Release 5.2.0 (EPICS 7.0.1, Dec 2017)
This release contains bug fixes and minor source updates needed to
build against the latest version of pvData.
## Release 5.1.2 (EPICS V4.6, Aug 2016)
The main changes since release 5.1.1 are:
* NTUnionBuilder: Add missing value() function
* Updated document: Now document all Normative Types
## Release 5.1.1
The main changes since release 5.0 are:
* Linux shared library version added
* Headers and source locations have changed
* Missing is_a implementations added
* NTAttribute::addTags() is now non-virtual
* New license file replaces LICENSE and COPYRIGHT
### Shared library version added
Linux shared library version numbers have been added by setting SHRLIB_VERSION
(to 5.1 in this case). So shared object will be libnt.so.5.1 instead of
libpvData.so.
### Headers and source locations have changed
Source has moved out of nt directory directly into src.
Headers have been moved into a pv directory. This facilitates using some IDEs
such as Qt Creator.
src/nt/ntscalar.cpp -> src/ntscalar.cpp
src/nt/ntscalar.h -> src/pv/ntscalar.h
### Missing is_a implementations added
is_a(PVStructurePtr const &) implementation has been added for each type.
## Release 5.0 (EPICS V4.5, Oct 2015)
This release adds support through wrapper classes and builders for the
remaining Normative Types:
* NTEnum
* NTMatrix
* NTURI
* NTAttribute
* NTContinuum
* NTHistogram
* NTAggregate
* NTUnion
* NTScalarMultiChannel
Release 5.0 therefore implements fully the
[16 Mar 2015 version](http://epics-pvdata.sourceforge.net/alpha/normativeTypes/normativeTypes_20150316.html)
of the normativeTypes specification.
Each wrapper class has an extended API:
* is_a now has a convenience overload taking a PVStructure.
* isCompatible, reporting introspection type compatibility, now has an overload
taking a Structure. The PVStructure version is retained as a convenience
method and for backwards compatibility.
* An isValid function now reports validity of a compatible PVStructure's data
with respect to the specification.
Other changes are:
* Support for NTAttributes extended as required by NTNDArray
(NTNDArrayAttributes).
* A new class for parsing NT IDs (NTID).
* Resolution of the confusion between column names and labels in NTTable and
improved API. Function for adding columns is now addColumn rather than add.
New getColumnNames function provided.
* isConnected is treated as an optional rather than a required field in
NTMultiChannelArray. isConnected() and addIsConnected() functions added to
wrapper and builder respectively.
* Unit tests for all new classes.
## Release 4.0 (EPICS V4.4, Dec 2014)
This is the first release of normativeTypesCPP that is part of an official
EPICS V4 release.
It is a major rewrite of the previous versions of normativeTypesCPP.
This release provides support through wrapper classes and builders for the
following Normative Types:
* NTScalar
* NTScalarArray
* NTNameValue
* NTTable
* NTMultiChannel
* NTNDArray
Each type has a wrapper class of the same name which has functions for checking
compatibility of existing PVStructures (isCompatible) and the reported types of
Structures (is_a), wraps existing PVStructures (wrap, wrapUnsafe) and provides
a convenient interface to all required and optional fields.
Each type has a builder which can create a Structure, a PVStructure or a
wrapper around a new PVStructure. In each case optional or extra fields can be
added and options such as choice of scalar type can be made.
Additional features are:
* Utility classes NTField and NTPVField for standard structure fields and
NTUtils for type IDs.
* Unit tests for the implemented classes.

View File

@@ -1,22 +0,0 @@
<h1>TODO</h1>
<h2>NTScalarArray</h2>
<p>NTScalarArrayBuilder::arrayValue</p>
<p>Should this be:</p>
<p>NTScalarArrayBuilder::value</p>
<p>This makes NTScalarArray consistent with other NTTypes.</p>
<h2>NTNameValue</h2>
<p>This does not have a value field like all the other NTTypes.
Perhaps instead of</p>
<pre><code>NTNameValue
string[] name
string[] value
</code></pre>
<p>It should be</p>
<pre><code>NTNameValue
value
string[] name
string[] value
</code></pre>
<h2>NTTable</h2>
<p>Should lables be label?
Compare with name,value from NTNameValue.</p>

View File

@@ -1,37 +1,5 @@
TODO
===========
====
NTScalarArray
------------
Documentation for recently added types.
NTScalarArrayBuilder::arrayValue
Should this be:
NTScalarArrayBuilder::value
This makes NTScalarArray consistent with other NTTypes.
NTNameValue
------------
This does not have a value field like all the other NTTypes.
Perhaps instead of
NTNameValue
string[] name
string[] value
It should be
NTNameValue
value
string[] name
string[] value
NTTable
----------
Should lables be label?
Compare with name,value from NTNameValue.

File diff suppressed because it is too large Load Diff

View File

@@ -1,289 +0,0 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>EPICS pvDataCPP</title>
<link rel="stylesheet" type="text/css"
href="http://epics-pvdata.sourceforge.net/base.css" />
<link rel="stylesheet" type="text/css"
href="http://epics-pvdata.sourceforge.net/epicsv4.css" />
<style type="text/css">
/*<![CDATA[*/
.about { margin-left: 3em; margin-right: 3em; font-size: .83em}
table { margin-left: auto; margin-right: auto }
.diagram { text-align: center; margin: 2.5em 0 }
span.opt { color: grey }
span.nterm { font-style:italic }
span.term { font-family:courier }
span.user { font-family:courier }
span.user:before { content:"<" }
span.user:after { content:">" }
.nonnorm { font-style:italic }
p.ed { color: #AA0000 }
span.ed { color: #AA0000 }
p.ed.priv { display: inline; }
span.ed.priv { display: inline; }
/*]]>*/</style>
<!-- Script that generates the Table of Contents -->
<script type="text/javascript"
src="http://epics-pvdata.sourceforge.net/script/tocgen.js">
</script>
</head>
<body>
<div class="head">
<h1>EPICS pvDataCPP</h1>
<!-- Maturity: Working Draft or Request for Comments, or Recommendation, and date. -->
<h2 class="nocount">EPICS v4 Working Group, Working Draft, 23-July-2014</h2>
<dl>
<dt>Latest version:</dt>
<dd><a
href="ntCPP.html">ntCPP.html</a>
</dd>
<dt>This version:</dt>
<dd><a
href="ntCPP_20140723.html">ntCPP_20140723.html</a>
</dd>
<dt>Previous version:</dt>
<dd>None</dd>
<dt>Editors:</dt>
<dd>Marty Kraimer, BNL</dd>
<dd>Michael Davidsaver, BNL</dd>
<dd>Matej Sekoranja, CosyLab</dd>
</dl>
<p class="copyright">This product is made available subject to acceptance of the <a
href="http://epics-pvdata.sourceforge.net/LICENSE.html">EPICS open source
license.</a></p>
<hr />
</div>
<h2 class="nocount">Abstract</h2>
<p>EPICS Version 4 provides efficient
storage, access, and communication, of memory resident structured data.
pvData is the storage compoment.
pvDataCPP is the C++ implementation of pvData.
It is one part of the set of related products in the EPICS
V4 control system programming environment:<br />
<a href="http://epics-pvdata.sourceforge.net/relatedDocumentsV4.html">relatedDocumentsV4.html</a>
</p>
<h2 class="nocount">Status of this Document</h2>
<p>For now this is a working copy so it is not the same as "This version" shown above.</p>
<p>This is the 23-July-2014 version of the C++ implementation of pvData.
</p>
<p>RELEASE_NOTES.md provides changes since the last release.
TODO.md describes things to do before the next release.
</p>
<div id="toc">
<h2 class="nocount" style="page-break-before: always">Table of Contents</h2>
</div>
<div id="contents" class="contents">
<body>
<h1 style="text-align: center">EPICS normative type C++ implementation
</h1>
<h2 class="nocount" id="L50">Draft, 4-Nov-2012</h2>
<dl>
<dt>This version:</dt>
<dd><a href="http://epics-pvdata.hg.sourceforge.net/hgweb/epics-pvdata/normativeTypesCPP/raw-file/tip/documentation/ntCPP.html">ntCPP.html</a></dd>
<dt>Editors:</dt>
<dd>Matej Sekoranja, CosyLab<br>
Marty Kraimer, BNL
</dd>
</dl>
<hr />
</div>
<h2>Introduction</h2>
<p>This section describes the C++ implemmentation of normative types. Two (2) helper classes are implemented,
ntNameValue and NTTable respectively. </p>
<h3>Normative Type Fields.</h3>
<p>These are helper classes for creating standard fields for normative types.
There is a single instance of this class, which is obtained via NTField::get().
</p>
<pre>class NTField: NoDefaultMethods {
public:
static NTFieldPtr get();
~NTField() {}
PVStructurePtr createEnumerated(StringArray const &amp; choices);
PVStructurePtr createTimeStamp();
PVStructurePtr createAlarm();
PVStructurePtr createDisplay();
PVStructurePtr createAlarmLimit();
PVStructurePtr createControl();
PVStructureArrayPtr createEnumeratedArray();
PVStructureArrayPtr createTimeStampArray();
PVStructureArrayPtr createAlarmArray();
};</pre>
<p>where</p>
<dl>
<dt>createEnumerated</dt>
<dd>Create an introspection interface for an enumerated structure.</dd>
<dt>createTimeStamp</dt>
<dd>Create an interspection interface for a timeStamp structure.</dd>
<dt>createAlarm</dt>
<dd>Create an interspection interface for an alarm structure.</dd>
<dt>createDisplay</dt>
<dd>Create an introsepecion interface for a display structure.</dd>
<dt>createAlarmLimit</dt>
<dd>Create an introspection interface for an alarm limit structure.</dd>
<dt>createControl</dt>
<dd>Create an introspection interface for a control structure.</dd>
<dt>createEnumeratedArray</dt>
<dd>Create an introspection interface for an structureArray of enumerated
structures.</dd>
<dt>createTimeStampArray</dt>
<dd>Create an introspection interface for an structureArray of timeStamp
structures.</dd>
<dt>createAlarmArray</dt>
<dd>Create an introspection interface for an structureArray of alarm
structures.</dd>
</dl>
<h3>NTNameValue</h3>
<p>These are helper classes for NTNameValue</p>
<pre>class NTNameValue : private NoDefaultMethods
{
public:
static bool isNTNameValue(PVStructurePtr const & pvStructure);
static NTNameValuePtr create(
bool hasFunction,bool hasTimeStamp, bool hasAlarm);
static NTNameValuePtr create(
PVStructurePtr const & pvStructure);
~NTNameValue();
PVStringPtr getFunction();
void attachTimeStamp(PVTimeStamp &amp;pvTimeStamp);
void attachAlarm(PVAlarm &amp;pvAlarm);
PVStructurePtr getPVStructure();
PVStructurePtr getTimeStamp();
PVStructurePtr getAlarm();
PVStringArrayPtr getNames();
PVStringArrayPtr getValues();
};</pre>
<p>where</p>
<dl>
<dt>isNTNameValue</dt>
<dd>Is the structure a NTNameValue structure?</dd>
<dt>create</dt>
<dd>Create an NTNameValue that has the associated fields.</dd>
<dt>~NTNameValue</dt>
<dd>The destructor.</dd>
<dt>getFunction</dt>
<dd>Get the function field. This can be null.</dd>
<dt>attachTimeStamp</dt>
<dd>The timeStamp field of the NTNameValue is atttached to the
pvTimeStamp.</dd>
<dt>attachAlarm</dt>
<dd>The alarm field of the NTNameValue is atttached to the alarm.</dd>
<dt>getPVStructure</dt>
<dd>Get the pvStructure that this NTNameValue contains.</dd>
<dt>getTimeStamp</dt>
<dd>Get the timeStamp field.</dd>
<dt>getAlarm</dt>
<dd>Get the alarm field.</dd>
<dt>getNames</dt>
<dd>Get the names field.</dd>
<dt>getValues</dt>
<dd>Get the values field.</dd>
</dl>
<h3>NTTable</h3>
<p>These are helper classes for NTTable</p>
<pre>class NTTable: private NoDefaultMethods
{
public:
static bool isNTTable(PVStructurePtr const & pvStructure);
static PVStructure::shared_pointer create(
bool hasFunction,bool hasTimeStamp, bool hasAlarm,
int numberValues,
FieldConstPtrArray valueFields);
static NTTablePtr create(
bool hasFunction,bool hasTimeStamp, bool hasAlarm,
StringArray const & valueNames,
FieldConstPtrArray const &valueFields);
static NTTablePtr clone(PVStructurePtr const &);
~NTTable();
PVStringPtr getFunction();
void attachTimeStamp(PVTimeStamp &amp;pvTimeStamp);
void attachAlarm(PVAlarm &amp;pvAlarm);
PVStructurePtr getPVStructure();
PVStructurePtr getTimeStamp();
PVStructurePtr getAlarm();
PVStringArrayPtr getLabel();
size_t getNumberValues();
FieldConstPtr getField(int index);
PVFieldPtr getPVField(int index);
};</pre>
<p>where</p>
<dl>
<dt>isNTTable</dt>
<dd>y</dd>
<dt>create</dt>
<dd>Create an NTTable that has the associated fields.</dd>
<dt>~NTTable</dt>
<dd>The destructor.</dd>
<dt>getFunction</dt>
<dd>Get the function field. This can be null.</dd>
<dt>attachTimeStamp</dt>
<dd>The timeStamp field of the NTTable is atttached to the pvTimeStamp.</dd>
<dt>attachAlarm</dt>
<dd>The alarm field of the NTTable is atttached to the alarm.</dd>
<dt>getPVStructure</dt>
<dd>Get the pvStructure that this NTTable contains.</dd>
<dt>getTimeStamp</dt>
<dd>Get the timeStamp field.</dd>
<dt>getAlarm</dt>
<dd>Get the alarm field.</dd>
<dt>getLabel</dt>
<dd>Get the label field.</dd>
<dt>getNumberValues</dt>
<dd>Get the number of value fields.</dd>
<dt>getField</dt>
<dd>Get the introspection interface for the specified field.</dd>
<dt>getPVField</dt>
<dd>Get the data field for the specified field.</dd>
</dl>
<h2>MTMultiChannel</h2>
<pre>
structure NTMultiChannel
union_t[] value
string[] channelName
time_t timeStamp :opt // time when data collected
alarm_t alarm :opt // alarm associated with data collection
int[] severity :opt // alarm severity for each value
int[] status :opt // alarm status for each value
string[] message :opt // alarm message for each value
long[] secondsPastEpoch :opt // seconds for each value.
int[] nanoseconds :opt // nanoseconds for each value
string descriptor :opt // descriptor data
</pre>
</div>
</body>
</html>

File diff suppressed because it is too large Load Diff

77
jenkins/cloudbees_build Normal file
View File

@@ -0,0 +1,77 @@
# normativeTypes C++ implementation
# Jenkins @ Cloudbees build script
#
# Jenkins invokes scripts with the "-ex" option. So the build is considered a failure
# if any of the commands exits with a non-zero exit code.
#
# Author: Ralph Lange <ralph.lange@gmx.de>
# Copyright (C) 2013 Helmholtz-Zentrum Berlin für Materialien und Energie GmbH
# Copyright (C) 2014-2016 ITER Organization.
# All rights reserved. Use is subject to license terms.
installTool () {
local module=$1
local version=$2
wget -nv https://openepics.ci.cloudbees.com/job/${module}-${version}_Build/lastSuccessfulBuild/artifact/${module,,}-${version}.CB-dist.tar.gz
tar -xzf ${module,,}-${version}.CB-dist.tar.gz
}
installE4 () {
local module=$1
local branch=$2
wget -nv https://openepics.ci.cloudbees.com/job/e4-cpp-${module}-${branch}-build/BASE=${BASE}/lastSuccessfulBuild/artifact/${module}.CB-dist.tar.gz
tar -xzf ${module}.CB-dist.tar.gz
}
###########################################
# Defaults for EPICS Base
DEFAULT_BASE=3.15.4
BASE=${BASE:-${DEFAULT_BASE}}
###########################################
# Dependent module branches
PVDATA_BRANCH="master"
###########################################
# Fetch and unpack dependencies
export STUFF=/tmp/stuff
rm -fr ${STUFF}
mkdir -p ${STUFF}
cd ${STUFF}
installTool Boost 1.61.0
installTool Base ${BASE}
installE4 pvData ${PVDATA_BRANCH}
###########################################
# Build
cd ${WORKSPACE}
export EPICS_BASE=${STUFF}
export EPICS_HOST_ARCH=$(${EPICS_BASE}/startup/EpicsHostArch)
export LD_LIBRARY_PATH=${EPICS_BASE}/lib/${EPICS_HOST_ARCH}
export PATH=${STUFF}/bin:${PATH}
cat > configure/RELEASE.local << EOF
EPICS_BASE=${EPICS_BASE}
EOF
make distclean all
###########################################
# Test
make runtests
###########################################
# Create cache
tar --exclude=test* -czf normativeTypes.CB-dist.tar.gz lib include

66
jenkins/cloudbees_doc Normal file
View File

@@ -0,0 +1,66 @@
# normativeTypes C++ implementation
# Jenkins @ Cloudbees documentation generation and deployment
#
# Jenkins invokes scripts with the "-ex" option. So the build is considered a failure
# if any of the commands exits with a non-zero exit code.
#
# Author: Ralph Lange <ralph.lange@gmx.de>
# Copyright (C) 2013 Helmholtz-Zentrum Berlin für Materialien und Energie GmbH
# Copyright (C) 2014-2016 ITER Organization.
# All rights reserved. Use is subject to license terms.
installTool () {
local module=$1
local version=$2
wget -nv https://openepics.ci.cloudbees.com/job/${module}-${version}_Build/lastSuccessfulBuild/artifact/${module,,}-${version}.CB-dist.tar.gz
tar -xzf ${module,,}-${version}.CB-dist.tar.gz
}
installE4 () {
local module=$1
local branch=$2
wget -nv https://openepics.ci.cloudbees.com/job/e4-cpp-${module}-${branch}-build/BASE=${BASE}/lastSuccessfulBuild/artifact/${module}.CB-dist.tar.gz
tar -xzf ${module}.CB-dist.tar.gz
}
###########################################
# Defaults for EPICS Base and parameters
BASE=3.15.4
PUBLISH=${PUBLISH:-NO}
BRANCH=${BRANCH:-master}
###########################################
# Fetch and unpack dependencies
export STUFF=/tmp/stuff
rm -fr ${STUFF}
mkdir -p ${STUFF}
cd ${STUFF}
installTool Doxygen 1.8.11
###########################################
# Generate
cd ${WORKSPACE}
installE4 normativeTypes ${BRANCH}
export PATH=${STUFF}/bin:${PATH}
doxygen
###########################################
# Publish
if [ "${PUBLISH}" != "DONT" ]; then
# Upload explicit dummy to ensure target directory exists
echo "Created by CloudBees Jenkins upload job. Should be deleted as part of the job." > DUMMY
rsync -q -e ssh DUMMY epics-jenkins@web.sourceforge.net:/home/project-web/epics-pvdata/htdocs/docbuild/normativeTypesCPP/${PUBLISH}/
rsync -aqP --delete -e ssh documentation epics-jenkins@web.sourceforge.net:/home/project-web/epics-pvdata/htdocs/docbuild/normativeTypesCPP/${PUBLISH}/
fi

View File

@@ -1,32 +1,53 @@
TOP = ..
include $(TOP)/configure/CONFIG
SRC = $(TOP)/src/
SRC_DIRS += $(SRC)/nt
INC += nt.h
INC += ntutils.h
INC += ntfield.h
INC += ntscalar.h
INC += ntscalarArray.h
INC += ntnameValue.h
INC += nttable.h
INC += ntmultiChannel.h
INC += ntndarray.h
INC += pv/nt.h
INC += pv/ntutils.h
INC += pv/ntid.h
INC += pv/ntfield.h
INC += pv/ntscalar.h
INC += pv/ntscalarArray.h
INC += pv/ntnameValue.h
INC += pv/nttable.h
INC += pv/ntmultiChannel.h
INC += pv/ntscalarMultiChannel.h
INC += pv/ntndarray.h
INC += pv/ntmatrix.h
INC += pv/ntenum.h
INC += pv/ntunion.h
INC += pv/ntaggregate.h
INC += pv/ntattribute.h
INC += pv/ntcontinuum.h
INC += pv/nthistogram.h
INC += pv/nturi.h
INC += pv/ntndarrayAttribute.h
LIBSRCS += ntutils.cpp
LIBSRCS += ntid.cpp
LIBSRCS += ntfield.cpp
LIBSRCS += ntscalar.cpp
LIBSRCS += ntscalarArray.cpp
LIBSRCS += ntnameValue.cpp
LIBSRCS += nttable.cpp
LIBSRCS += ntmultiChannel.cpp
LIBSRCS += ntscalarMultiChannel.cpp
LIBSRCS += ntndarray.cpp
LIBSRCS += ntmatrix.cpp
LIBSRCS += ntenum.cpp
LIBSRCS += ntunion.cpp
LIBSRCS += ntaggregate.cpp
LIBSRCS += ntattribute.cpp
LIBSRCS += ntcontinuum.cpp
LIBSRCS += nthistogram.cpp
LIBSRCS += nturi.cpp
LIBSRCS += ntndarrayAttribute.cpp
LIBRARY=nt
LIBRARY = nt
nt_LIBS += pvData Com
# shared library ABI version.
SHRLIB_VERSION ?= 5.2.2
include $(TOP)/configure/RULES

View File

@@ -1,22 +0,0 @@
/* nt.h */
/**
* Copyright - See the COPYRIGHT that is included with this distribution.
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
*/
#ifndef NT_H
#define NT_H
/*
* Include all the normative types here.
*/
#include <pv/ntfield.h>
#include <pv/ntscalar.h>
#include <pv/ntscalarArray.h>
#include <pv/ntnameValue.h>
#include <pv/nttable.h>
#include <pv/ntndarray.h>
#include <pv/ntmultiChannel.h>
#endif /* NT_H */

View File

@@ -1,316 +0,0 @@
/* ntmultiChannel.h */
/**
* Copyright - See the COPYRIGHT that is included with this distribution.
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
*/
#ifndef NTMULTICHANNEL_H
#define NTMULTICHANNEL_H
#include <vector>
#include <string>
#ifdef epicsExportSharedSymbols
# define ntmultiChannelEpicsExportSharedSymbols
# undef epicsExportSharedSymbols
#endif
#include <pv/pvDisplay.h>
#include <pv/pvControl.h>
#ifdef ntmultiChannelEpicsExportSharedSymbols
# define epicsExportSharedSymbols
# undef ntmultiChannelEpicsExportSharedSymbols
#endif
#include <pv/ntfield.h>
#include <shareLib.h>
namespace epics { namespace nt {
/**
* Convenience Class for NTMultiChannel
* @author mrk
*
*/
class NTMultiChannel;
typedef std::tr1::shared_ptr<NTMultiChannel> NTMultiChannelPtr;
namespace detail {
/**
* Interface for in-line creating of NTMultiChannel.
* One instance can be used to create multiple instances.
* An instance of this object must not be used concurrently (an object has a state).
* @author mse
*/
class epicsShareClass NTMultiChannelBuilder :
public std::tr1::enable_shared_from_this<NTMultiChannelBuilder>
{
public:
POINTER_DEFINITIONS(NTMultiChannelBuilder);
/**
* specify the union for the value field.
* If this is not called then a variantUnion is the default.
* @return this instance of a {@code NTMultiChannelBuilder}.
*/
shared_pointer value(epics::pvData::UnionConstPtr valuePtr);
/**
* Add descriptor field to the NTMultiChannel.
* @return this instance of a {@code NTMultiChannelBuilder}.
*/
shared_pointer addDescriptor();
/**
* Add alarm structure to the NTMultiChannel.
* @return this instance of a {@code NTMultiChannelBuilder}.
*/
shared_pointer addAlarm();
/**
* Add timeStamp structure to the NTMultiChannel.
* @return this instance of a {@code NTMultiChannelBuilder}.
*/
shared_pointer addTimeStamp();
/**
* Add severity array to the NTMultiChannel.
* @return this instance of a {@code NTMultiChannelBuilder}.
*/
shared_pointer addSeverity();
/**
* Add status array to the NTMultiChannel.
* @return this instance of a {@code NTMultiChannelBuilder}.
*/
shared_pointer addStatus();
/**
* Add message array to the NTMultiChannel.
* @return this instance of a {@code NTMultiChannelBuilder}.
*/
shared_pointer addMessage();
/**
* Add secondsPastEpoch array to the NTMultiChannel.
* @return this instance of a {@code NTMultiChannelBuilder}.
*/
shared_pointer addSecondsPastEpoch();
/**
* Add nanoseconds array to the NTMultiChannel.
* @return this instance of a {@code NTMultiChannelBuilder}.
*/
shared_pointer addNanoseconds();
/**
* Add userTag array to the NTMultiChannel.
* @return this instance of a {@code NTMultiChannelBuilder}.
*/
shared_pointer addUserTag();
/**
* Create a {@code Structure} that represents NTMultiChannel.
* This resets this instance state and allows new instance to be created.
* @return a new instance of a {@code Structure}.
*/
epics::pvData::StructureConstPtr createStructure();
/**
* Create a {@code PVStructure} that represents NTMultiChannel.
* This resets this instance state and allows new {@code instance to be created.}
* @return a new instance of a {@code PVStructure}
*/
epics::pvData::PVStructurePtr createPVStructure();
/**
* Create a {@code NTMultiChannel} instance.
* This resets this instance state and allows new {@code instance to be created.}
* @return a new instance of a {@code NTMultiChannel}
*/
NTMultiChannelPtr create();
/**
* Add extra {@code Field} to the type.
* @param name name of the field.
* @param field a field to add.
* @return this instance of a {@code NTMultiChannelBuilder}.
*/
shared_pointer add(std::string const & name, epics::pvData::FieldConstPtr const & field);
private:
NTMultiChannelBuilder();
void reset();
epics::pvData::UnionConstPtr valueType;
bool descriptor;
bool alarm;
bool timeStamp;
bool severity;
bool status;
bool message;
bool secondsPastEpoch;
bool nanoseconds;
bool userTag;
// NOTE: this preserves order, however it does not handle duplicates
epics::pvData::StringArray extraFieldNames;
epics::pvData::FieldConstPtrArray extraFields;
friend class ::epics::nt::NTMultiChannel;
};
}
typedef std::tr1::shared_ptr<detail::NTMultiChannelBuilder> NTMultiChannelBuilderPtr;
class epicsShareClass NTMultiChannel
{
public:
POINTER_DEFINITIONS(NTMultiChannel);
static const std::string URI;
/**
* Wrap (aka dynamic cast, or wrap) the structure to NTMultiChannel.
* First isCompatible is called.
* This method will nullptr if the structure is is not compatible.
* @param structure The structure to wrap-ed (dynamic cast, wrapped) to NTMultiChannel.
* @return NTMultiChannel instance on success, nullptr otherwise.
*/
static shared_pointer wrap(epics::pvData::PVStructurePtr const & structure);
/**
* Wrap (aka dynamic cast, or wrap) the structure to NTMultiChannel without checking for isCompatible
* @param structure The structure to wrap-ed (dynamic cast, wrapped) to NTMultiChannel.
* @return NTMultiChannel instance.
*/
static shared_pointer wrapUnsafe(epics::pvData::PVStructurePtr const & structure);
/**
* Is the Structure an NTMultiChannel.
* This method structure->getID() and checks if it is the same as the URI.
* @param structure The structure to test.
* @return (false,true) if (is not, is) an NTMultiChannel.
*/
static bool is_a(
epics::pvData::StructureConstPtr const &structure);
/**
* Is the pvStructure compatible with NTMultiChannel.
* This method introspects the fields to see if they are compatible.
* @param pvStructure The pvStructure to test.
* @return (false,true) if (is not, is) an NTMultiChannel.
*/
static bool isCompatible(
epics::pvData::PVStructurePtr const &pvStructure);
/**
* Create a NTMultiChannelBuilder instance
* @return builder instance.
*/
static NTMultiChannelBuilderPtr createBuilder();
/**
* Destructor
*/
~NTMultiChannel() {}
/**
* Attach a pvTimeStamp.
* @param pvTimeStamp The pvTimeStamp that will be attached.
* Does nothing if no timeStamp
*/
void attachTimeStamp(epics::pvData::PVTimeStamp &pvTimeStamp) const;
/**
* Attach a pvAlarm.
* @param pvAlarm The pvAlarm that will be attached.
* Does nothing if no alarm
*/
void attachAlarm(epics::pvData::PVAlarm &pvAlarm) const;
/**
* Get the pvStructure.
* @return PVStructurePtr.
*/
epics::pvData::PVStructurePtr getPVStructure() const
{return pvNTMultiChannel;}
/**
* Get the timeStamp.
* @return PVStructurePtr which may be null.
*/
epics::pvData::PVStructurePtr getTimeStamp() const
{return pvTimeStamp;}
/**
* Get the alarm.
* @return PVStructurePtr which may be null.
*/
epics::pvData::PVStructurePtr getAlarm() const
{return pvAlarm;}
/**
* Get the value of each channel.
* @return PVUnionArrayPtr
*/
epics::pvData::PVUnionArrayPtr getValue() const
{return pvValue;}
/**
* Get the channelName of each channel.
* @return PVStringArrayPtr
*/
epics::pvData::PVStringArrayPtr getChannelName() const
{ return pvChannelName;};
/**
* Get the connection state of each channel.
* @return PVBooleanArrayPtr
*/
epics::pvData::PVBooleanArrayPtr getIsConnected() const
{ return pvIsConnected;};
/**
* Get the severity of each channel.
* @return PVIntArrayPtr which may be null.
*/
epics::pvData::PVIntArrayPtr getSeverity() const
{return pvSeverity;}
/**
* Get the status of each channel.
* @return PVIntArrayPtr which may be null.
*/
epics::pvData::PVIntArrayPtr getStatus() const
{return pvStatus;}
/**
* Get the message of each chnnel.
* @return PVStringArrayPtr which may be null.
*/
epics::pvData::PVStringArrayPtr getMessage() const
{return pvMessage;}
/**
* Get the secondsPastEpoch of each channel.
* @return PVLongArrayPtr which may be null.
*/
epics::pvData::PVLongArrayPtr getSecondsPastEpoch() const
{return pvSecondsPastEpoch;}
/**
* Get the nanoseconds of each channel.
* @return PVIntArrayPtr which may be null.
*/
epics::pvData::PVIntArrayPtr getNanoseconds() const
{return pvNanoseconds;}
/**
* Get the userTag of each channel.
* @return PVIntArrayPtr which may be null.
*/
epics::pvData::PVIntArrayPtr getUserTag() const
{return pvUserTag;}
/**
* Get the descriptor.
* @return PVStringPtr which may be null.
*/
epics::pvData::PVStringPtr getDescriptor() const
{return pvDescriptor;}
private:
NTMultiChannel(epics::pvData::PVStructurePtr const & pvStructure);
epics::pvData::PVStructurePtr pvNTMultiChannel;
epics::pvData::PVStructurePtr pvTimeStamp;
epics::pvData::PVStructurePtr pvAlarm;
epics::pvData::PVUnionArrayPtr pvValue;
epics::pvData::PVStringArrayPtr pvChannelName;
epics::pvData::PVBooleanArrayPtr pvIsConnected;
epics::pvData::PVIntArrayPtr pvSeverity;
epics::pvData::PVIntArrayPtr pvStatus;
epics::pvData::PVStringArrayPtr pvMessage;
epics::pvData::PVLongArrayPtr pvSecondsPastEpoch;
epics::pvData::PVIntArrayPtr pvNanoseconds;
epics::pvData::PVIntArrayPtr pvUserTag;
epics::pvData::PVStringPtr pvDescriptor;
friend class detail::NTMultiChannelBuilder;
};
}}
#endif /* NTMULTICHANNEL_H */

View File

@@ -1,251 +0,0 @@
/* ntnameValue.h */
/**
* Copyright - See the COPYRIGHT that is included with this distribution.
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
*/
#ifndef NTNAMEVALUE_H
#define NTNAMEVALUE_H
#ifdef epicsExportSharedSymbols
# define ntnameValueEpicsExportSharedSymbols
# undef epicsExportSharedSymbols
#endif
#include <pv/pvDisplay.h>
#include <pv/pvControl.h>
#ifdef ntnameValueEpicsExportSharedSymbols
# define epicsExportSharedSymbols
# undef ntnameValueEpicsExportSharedSymbols
#endif
#include <pv/ntfield.h>
#include <shareLib.h>
namespace epics { namespace nt {
class NTNameValue;
typedef std::tr1::shared_ptr<NTNameValue> NTNameValuePtr;
namespace detail {
/**
* Interface for in-line creating of NTNameValue.
* One instance can be used to create multiple instances.
* An instance of this object must not be used concurrently (an object has a state).
* @author mse
*/
class epicsShareClass NTNameValueBuilder :
public std::tr1::enable_shared_from_this<NTNameValueBuilder>
{
public:
POINTER_DEFINITIONS(NTNameValueBuilder);
/**
* Set a value array {@code Scalar} type.
* @param scalarType value array scalar array.
* @return this instance of a {@code NTTableBuilder}.
*/
shared_pointer value(epics::pvData::ScalarType scalarType);
/**
* Add descriptor field to the NTNameValue.
* @return this instance of a {@code NTNameValueBuilder}.
*/
shared_pointer addDescriptor();
/**
* Add alarm structure to the NTNameValue.
* @return this instance of a {@code NTNameValueBuilder}.
*/
shared_pointer addAlarm();
/**
* Add timeStamp structure to the NTNameValue.
* @return this instance of a {@code NTNameValueBuilder}.
*/
shared_pointer addTimeStamp();
/**
* Create a {@code Structure} that represents NTNameValue.
* This resets this instance state and allows new instance to be created.
* @return a new instance of a {@code Structure}.
*/
epics::pvData::StructureConstPtr createStructure();
/**
* Create a {@code PVStructure} that represents NTNameValue.
* This resets this instance state and allows new {@code instance to be created.
* @return a new instance of a {@code PVStructure}
*/
epics::pvData::PVStructurePtr createPVStructure();
/**
* Create a {@code NTNameValue} instance.
* This resets this instance state and allows new {@code instance to be created.
* @return a new instance of a {@code NTNameValue}
*/
NTNameValuePtr create();
/**
* Add extra {@code Field} to the type.
* @param name name of the field.
* @param field a field to add.
* @return this instance of a {@code NTNameValueBuilder}.
*/
shared_pointer add(std::string const & name, epics::pvData::FieldConstPtr const & field);
private:
NTNameValueBuilder();
void reset();
bool valueTypeSet;
epics::pvData::ScalarType valueType;
bool descriptor;
bool alarm;
bool timeStamp;
// NOTE: this preserves order, however it does not handle duplicates
epics::pvData::StringArray extraFieldNames;
epics::pvData::FieldConstPtrArray extraFields;
friend class ::epics::nt::NTNameValue;
};
}
typedef std::tr1::shared_ptr<detail::NTNameValueBuilder> NTNameValueBuilderPtr;
/**
* Convenience Class for NTNameValue
* @author mrk
*/
class epicsShareClass NTNameValue
{
public:
POINTER_DEFINITIONS(NTNameValue);
static const std::string URI;
/**
* Wrap (aka dynamic cast, or wrap) the structure to NTNameValue.
* First isCompatible is called.
* This method will nullptr if the structure is is not compatible.
* This method will nullptr if the structure is nullptr.
* @param structure The structure to wrap-ed (dynamic cast, wrapped) to NTNameValue.
* @return NTNameValue instance on success, nullptr otherwise.
*/
static shared_pointer wrap(epics::pvData::PVStructurePtr const & structure);
/**
* Wrap (aka dynamic cast, or wrap) the structure to NTMultiChannel without checking for isCompatible
* @param structure The structure to wrap-ed (dynamic cast, wrapped) to NTNameValue.
* @return NTNameValue instance.
*/
static shared_pointer wrapUnsafe(epics::pvData::PVStructurePtr const & structure);
/**
* Is the structure an NTNameValue.
* @param structure The structure to test.
* @return (false,true) if (is not, is) an NTNameValue.
*/
static bool is_a(epics::pvData::StructureConstPtr const & structure);
/**
* Is the pvStructure compatible with NTNameValue..
* This method introspects the fields to see if they are compatible.
* @param pvStructure The pvStructure to test.
* @return (false,true) if (is not, is) an NTMultiChannel.
*/
static bool isCompatible(
epics::pvData::PVStructurePtr const &pvStructure);
/**
* Create a NTNameValue builder instance.
* @return builder instance.
*/
static NTNameValueBuilderPtr createBuilder();
/**
* Destructor.
*/
~NTNameValue() {}
/**
* Attach a pvTimeStamp.
* @param pvTimeStamp The pvTimeStamp that will be attached.
* Does nothing if no timeStamp.
* @return true if the operation was successfull (i.e. this instance has a timeStamp field), otherwise false.
*/
bool attachTimeStamp(epics::pvData::PVTimeStamp &pvTimeStamp) const;
/**
* Attach an pvAlarm.
* @param pvAlarm The pvAlarm that will be attached.
* Does nothing if no alarm.
* @return true if the operation was successfull (i.e. this instance has a timeStamp field), otherwise false.
*/
bool attachAlarm(epics::pvData::PVAlarm &pvAlarm) const;
/**
* Get the pvStructure.
* @return PVStructurePtr.
*/
epics::pvData::PVStructurePtr getPVStructure() const;
/**
* Get the descriptor field.
* @return The pvString or null if no function field.
*/
epics::pvData::PVStringPtr getDescriptor() const;
/**
* Get the timeStamp.
* @return PVStructurePtr which may be null.
*/
epics::pvData::PVStructurePtr getTimeStamp() const;
/**
* Get the alarm.
* @return PVStructurePtr which may be null.
*/
epics::pvData::PVStructurePtr getAlarm() const;
/**
* Get the name array field.
* @return The PVStringArray for the name.
*/
epics::pvData::PVStringArrayPtr getName() const;
/**
* Get the value array field.
* @return The PVField for the value.
*/
epics::pvData::PVFieldPtr getValue() const;
/**
* Get the value array field of a specified type (e.g. PVDoubleArray).
* @return The <PVT> array for the value.
*/
template<typename PVT>
std::tr1::shared_ptr<PVT> getValue() const
{
epics::pvData::PVFieldPtr pvField = getValue();
if (pvField.get())
return std::tr1::dynamic_pointer_cast<PVT>(pvField);
else
return std::tr1::shared_ptr<PVT>();
}
private:
NTNameValue(epics::pvData::PVStructurePtr const & pvStructure);
epics::pvData::PVStructurePtr pvNTNameValue;
friend class detail::NTNameValueBuilder;
};
}}
#endif /* NTNAMEVALUE_H */

View File

@@ -1,354 +0,0 @@
/* ntndarray.cpp */
/**
* Copyright - See the COPYRIGHT that is included with this distribution.
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
*/
#include <algorithm>
#define epicsExportSharedSymbols
#include <pv/ntndarray.h>
#include <pv/ntutils.h>
using namespace std;
using namespace epics::pvData;
namespace epics { namespace nt {
static NTFieldPtr ntField = NTField::get();
namespace detail {
const std::string ntAttrStr("epics:nt/NTAttribute:1.0");
static FieldCreatePtr fieldCreate = getFieldCreate();
static PVDataCreatePtr pvDataCreate = getPVDataCreate();
StructureConstPtr NTNDArrayBuilder::createStructure()
{
enum
{
DISCRIPTOR_INDEX,
TIMESTAMP_INDEX,
ALARM_INDEX,
DISPLAY_INDEX
};
const size_t NUMBER_OF_INDICES = DISPLAY_INDEX+1;
const size_t NUMBER_OF_STRUCTURES = 1 << NUMBER_OF_INDICES;
static StructureConstPtr ntndarrayStruc[NUMBER_OF_STRUCTURES];
static UnionConstPtr valueType;
static StructureConstPtr codecStruc;
static StructureConstPtr dimensionStruc;
static StructureConstPtr attributeStruc;
static Mutex mutex;
Lock xx(mutex);
StructureConstPtr returnedStruc;
size_t index = 0;
if (descriptor) index |= 1 << DISCRIPTOR_INDEX;
if (timeStamp) index |= 1 << TIMESTAMP_INDEX;
if (alarm) index |= 1 << ALARM_INDEX;
if (display) index |= 1 << DISPLAY_INDEX;
bool isExtended = !extraFieldNames.empty();
if (isExtended || !ntndarrayStruc[index])
{
StandardFieldPtr standardField = getStandardField();
FieldBuilderPtr fb = fieldCreate->createFieldBuilder();
if (!valueType)
{
for (int i = pvBoolean; i < pvString; ++i)
{
ScalarType st = static_cast<ScalarType>(i);
fb->addArray(std::string(ScalarTypeFunc::name(st)) + "Value", st);
}
valueType = fb->createUnion();
}
if (!codecStruc)
{
codecStruc = fb->setId("codec_t")->
add("name", pvString)->
add("parameters", fieldCreate->createVariantUnion())->
createStructure();
}
if (!dimensionStruc)
{
dimensionStruc = fb->setId("dimension_t")->
add("size", pvInt)->
add("offset", pvInt)->
add("fullSize", pvInt)->
add("binning", pvInt)->
add("reverse", pvBoolean)->
createStructure();
}
if (!attributeStruc)
{
attributeStruc = fb->setId(ntAttrStr)->
add("name", pvString)->
add("value", fieldCreate->createVariantUnion())->
add("descriptor", pvString)->
add("sourceType", pvInt)->
add("source", pvString)->
createStructure();
}
fb->setId(NTNDArray::URI)->
add("value", valueType)->
add("codec", codecStruc)->
add("compressedSize", pvLong)->
add("uncompressedSize", pvLong)->
addArray("dimension", dimensionStruc)->
add("uniqueId", pvInt)->
add("dataTimeStamp", standardField->timeStamp())->
addArray("attribute", attributeStruc);
if (descriptor)
fb->add("descriptor", pvString);
if (timeStamp)
fb->add("timeStamp", standardField->timeStamp());
if (alarm)
fb->add("alarm", standardField->alarm());
if (display)
fb->add("display", standardField->display());
size_t extraCount = extraFieldNames.size();
for (size_t i = 0; i< extraCount; i++)
fb->add(extraFieldNames[i], extraFields[i]);
returnedStruc = fb->createStructure();
if (!isExtended)
ntndarrayStruc[index] = returnedStruc;
}
else
{
return ntndarrayStruc[index];
}
return returnedStruc;
}
NTNDArrayBuilder::shared_pointer NTNDArrayBuilder::addDescriptor()
{
descriptor = true;
return shared_from_this();
}
NTNDArrayBuilder::shared_pointer NTNDArrayBuilder::addAlarm()
{
alarm = true;
return shared_from_this();
}
NTNDArrayBuilder::shared_pointer NTNDArrayBuilder::addTimeStamp()
{
timeStamp = true;
return shared_from_this();
}
NTNDArrayBuilder::shared_pointer NTNDArrayBuilder::addDisplay()
{
display = true;
return shared_from_this();
}
PVStructurePtr NTNDArrayBuilder::createPVStructure()
{
return getPVDataCreate()->createPVStructure(createStructure());
}
NTNDArrayPtr NTNDArrayBuilder::create()
{
return NTNDArrayPtr(new NTNDArray(createPVStructure()));
}
NTNDArrayBuilder::NTNDArrayBuilder()
{
reset();
}
void NTNDArrayBuilder::reset()
{
descriptor = false;
timeStamp = false;
alarm = false;
display = false;
extraFieldNames.clear();
extraFields.clear();
}
NTNDArrayBuilder::shared_pointer NTNDArrayBuilder::add(string const & name, FieldConstPtr const & field)
{
extraFields.push_back(field); extraFieldNames.push_back(name);
return shared_from_this();
}
}
const std::string NTNDArray::URI("epics:nt/NTNDArray:1.0");
const std::string ntAttrStr("epics:nt/NTAttribute:1.0");
static FieldCreatePtr fieldCreate = getFieldCreate();
static PVDataCreatePtr pvDataCreate = getPVDataCreate();
NTNDArray::shared_pointer NTNDArray::wrap(PVStructurePtr const & structure)
{
if(!isCompatible(structure)) return shared_pointer();
return wrapUnsafe(structure);
}
NTNDArray::shared_pointer NTNDArray::wrapUnsafe(PVStructurePtr const & structure)
{
return shared_pointer(new NTNDArray(structure));
}
bool NTNDArray::is_a(StructureConstPtr const & structure)
{
return NTUtils::is_a(structure->getID(), URI);
}
bool NTNDArray::isCompatible(PVStructurePtr const & pvStructure)
{
if(!pvStructure) return false;
PVUnionPtr pvValue = pvStructure->getSubField<PVUnion>("value");
if(!pvValue) return false;
PVFieldPtr pvField = pvStructure->getSubField("descriptor");
if(pvField && !pvStructure->getSubField<PVString>("descriptor")) return false;
pvField = pvStructure->getSubField("alarm");
if(pvField && !ntField->isAlarm(pvField->getField())) return false;
pvField = pvStructure->getSubField("timeStamp");
if(pvField && !ntField->isTimeStamp(pvField->getField())) return false;
pvField = pvStructure->getSubField("display");
if(pvField && !ntField->isDisplay(pvField->getField())) return false;
if(!pvStructure->getSubField<PVLong>("compressedSize")) return false;
if(!pvStructure->getSubField<PVLong>("uncompressedSize")) return false;
PVStructurePtr pvCodec = pvStructure->getSubField<PVStructure>("codec");
if(!pvCodec) return false;
if(!pvCodec->getSubField<PVString>("name")) return false;
if(!pvCodec->getSubField<PVUnion>("parameters")) return false;
PVStructureArrayPtr pvDimension = pvStructure->getSubField<PVStructureArray>("dimension");
if(pvDimension->getStructureArray()->getStructure()->getID().compare("dimension_t")!=0) return false;
if(!pvStructure->getSubField<PVInt>("uniqueId")) return false;
pvField = pvStructure->getSubField("dataTimeStamp");
if(pvField && !ntField->isTimeStamp(pvField->getField())) return false;
PVStructureArrayPtr pvAttribute = pvStructure->getSubField<PVStructureArray>("attribute");
if(pvAttribute->getStructureArray()->getStructure()->getID().compare(ntAttrStr)!=0) return false;
return true;
}
NTNDArrayBuilderPtr NTNDArray::createBuilder()
{
return NTNDArrayBuilderPtr(new detail::NTNDArrayBuilder());
}
bool NTNDArray::attachTimeStamp(PVTimeStamp &pvTimeStamp) const
{
PVStructurePtr ts = getTimeStamp();
if (ts)
return pvTimeStamp.attach(ts);
else
return false;
}
bool NTNDArray::attachDataTimeStamp(PVTimeStamp &pvTimeStamp) const
{
PVStructurePtr ts = getDataTimeStamp();
if (ts)
return pvTimeStamp.attach(ts);
else
return false;
}
bool NTNDArray::attachAlarm(PVAlarm &pvAlarm) const
{
PVStructurePtr al = getAlarm();
if (al)
return pvAlarm.attach(al);
else
return false;
}
PVStructurePtr NTNDArray::getPVStructure() const
{
return pvNTNDArray;
}
PVUnionPtr NTNDArray::getValue() const
{
return pvNTNDArray->getSubField<PVUnion>("value");
}
PVStructurePtr NTNDArray::getCodec() const
{
return pvNTNDArray->getSubField<PVStructure>("codec");
}
PVLongPtr NTNDArray::getCompressedDataSize() const
{
return pvNTNDArray->getSubField<PVLong>("compressedSize");
}
PVLongPtr NTNDArray::getUncompressedDataSize() const
{
return pvNTNDArray->getSubField<PVLong>("uncompressedSize");
}
PVStructureArrayPtr NTNDArray::getAttribute() const
{
return pvNTNDArray->getSubField<PVStructureArray>("attribute");
}
PVStructureArrayPtr NTNDArray::getDimension() const
{
return pvNTNDArray->getSubField<PVStructureArray>("dimension");
}
PVStructurePtr NTNDArray::getDataTimeStamp() const
{
return pvNTNDArray->getSubField<PVStructure>("dataTimeStamp");
}
PVStringPtr NTNDArray::getDescriptor() const
{
return pvNTNDArray->getSubField<PVString>("descriptor");
}
PVStructurePtr NTNDArray::getTimeStamp() const
{
return pvNTNDArray->getSubField<PVStructure>("timeStamp");
}
PVStructurePtr NTNDArray::getAlarm() const
{
return pvNTNDArray->getSubField<PVStructure>("alarm");
}
PVStructurePtr NTNDArray::getDisplay() const
{
return pvNTNDArray->getSubField<PVStructure>("display");
}
NTNDArray::NTNDArray(PVStructurePtr const & pvStructure) :
pvNTNDArray(pvStructure)
{}
}}

View File

@@ -1,286 +0,0 @@
/* ntndarray.h */
/**
* Copyright - See the COPYRIGHT that is included with this distribution.
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
*/
#ifndef NTNDARRAY_H
#define NTNDARRAY_H
#include <vector>
#include <string>
#ifdef epicsExportSharedSymbols
# define ntscalarArrayEpicsExportSharedSymbols
# undef epicsExportSharedSymbols
#endif
#include <pv/pvDisplay.h>
#include <pv/pvControl.h>
#ifdef ntscalarArrayEpicsExportSharedSymbols
# define epicsExportSharedSymbols
# undef ntscalarArrayEpicsExportSharedSymbols
#endif
#include <pv/ntfield.h>
#include <shareLib.h>
namespace epics { namespace nt {
class NTNDArray;
typedef std::tr1::shared_ptr<NTNDArray> NTNDArrayPtr;
namespace detail {
/**
* Interface for in-line creating of NTNDArray.
* One instance can be used to create multiple instances.
* An instance of this object must not be used concurrently (an object has a state).
* @author mse
*/
class epicsShareClass NTNDArrayBuilder :
public std::tr1::enable_shared_from_this<NTNDArrayBuilder>
{
public:
POINTER_DEFINITIONS(NTNDArrayBuilder);
/**
* Add descriptor field to the NTNDArray.
* @return this instance of a {@code NTNDArrayBuilder}.
*/
shared_pointer addDescriptor();
/**
* Add alarm structure to the NTNDArray.
* @return this instance of a {@code NTNDArrayBuilder}.
*/
shared_pointer addAlarm();
/**
* Add timeStamp structure to the NTNDArray.
* @return this instance of a {@code NTNDArrayBuilder}.
*/
shared_pointer addTimeStamp();
/**
* Add display structure to the NTNDArray.
* @return this instance of a {@code NTNDArrayBuilder}.
*/
shared_pointer addDisplay();
/**
* Create a {@code Structure} that represents NTNDArray.
* This resets this instance state and allows new instance to be created.
* @return a new instance of a {@code Structure}.
*/
epics::pvData::StructureConstPtr createStructure();
/**
* Create a {@code PVStructure} that represents NTNDArray.
* This resets this instance state and allows new {@code instance to be created.
* @return a new instance of a {@code PVStructure}
*/
epics::pvData::PVStructurePtr createPVStructure();
/**
* Create a {@code NTNDArray} instance.
* This resets this instance state and allows new {@code instance to be created.
* @return a new instance of a {@code NTNDArray}
*/
NTNDArrayPtr create();
/**
* Add extra {@code Field} to the type.
* @param name name of the field.
* @param field a field to add.
* @return this instance of a {@code NTArrayBuilder}.
*/
shared_pointer add(std::string const & name, epics::pvData::FieldConstPtr const & field);
private:
NTNDArrayBuilder();
void reset();
bool descriptor;
bool timeStamp;
bool alarm;
bool display;
// NOTE: this preserves order, however it does not handle duplicates
epics::pvData::StringArray extraFieldNames;
epics::pvData::FieldConstPtrArray extraFields;
friend class ::epics::nt::NTNDArray;
};
}
typedef std::tr1::shared_ptr<detail::NTNDArrayBuilder> NTNDArrayBuilderPtr;
/**
* Convenience Class for NTNDArray
* @author dgh
*/
class epicsShareClass NTNDArray
{
public:
POINTER_DEFINITIONS(NTNDArray);
static const std::string URI;
/**
* Wrap (aka dynamic cast, or wrap) the structure to NTNDArray.
* First isCompatible is called.
* This method will nullptr if the structure is is not compatible.
* This method will nullptr if the structure is nullptr.
* @param structure The structure to wrap-ed (dynamic cast, wrapped) to NTNDArray.
* @return NTNDArray instance on success, nullptr otherwise.
*/
static shared_pointer wrap(epics::pvData::PVStructurePtr const & structure);
/**
* Wrap (aka dynamic cast, or wrap) the structure to NTMultiChannel without checking for isCompatible
* @param structure The structure to wrap-ed (dynamic cast, wrapped) to NTNDArray.
* @return NTNDArray instance.
*/
static shared_pointer wrapUnsafe(epics::pvData::PVStructurePtr const & structure);
/**
* Is the structure an NTNDArray.
* @param structure The structure to test.
* @return (false,true) if (is not, is) an NTNDArray.
*/
static bool is_a(epics::pvData::StructureConstPtr const & structure);
/**
* Is the pvStructure compatible with NTNDArray..
* This method introspects the fields to see if they are compatible.
* @param pvStructure The pvStructure to test.
* @return (false,true) if (is not, is) an NTMultiChannel.
*/
static bool isCompatible(
epics::pvData::PVStructurePtr const &pvStructure);
/**
* Create a NTNDArrayBuilder instance
* @return builder instance.
*/
static NTNDArrayBuilderPtr createBuilder();
/**
* Destructor.
*/
~NTNDArray() {}
/**
* Attach a pvTimeStamp to timeStamp field.
* @param pvTimeStamp The pvTimeStamp that will be attached.
* Does nothing if no timeStamp.
* @return true if the operation was successfull (i.e. this instance has a timeStamp field), otherwise false.
*/
bool attachTimeStamp(epics::pvData::PVTimeStamp &pvTimeStamp) const;
/**
* Attach a pvTimeStamp to dataTimeStamp field.
* @param pvTimeStamp The pvTimeStamp that will be attached.
* Does nothing if no timeStamp.
* @return true if the operation was successfull (i.e. this instance has a timeStamp field), otherwise false.
*/
bool attachDataTimeStamp(epics::pvData::PVTimeStamp &pvTimeStamp) const;
/**
* Attach an pvAlarm.
* @param pvAlarm The pvAlarm that will be attached.
* Does nothing if no alarm.
* @return true if the operation was successfull (i.e. this instance has a timeStamp field), otherwise false.
*/
bool attachAlarm(epics::pvData::PVAlarm &pvAlarm) const;
/**
* Get the pvStructure.
* @return PVStructurePtr.
*/
epics::pvData::PVStructurePtr getPVStructure() const;
/**
* Get the value field.
* @return The PVField for the values.
*/
epics::pvData::PVUnionPtr getValue() const;
/**
* Get the codec field.
* @return the PVStructurePtr.
*/
epics::pvData::PVStructurePtr getCodec() const;
/**
* Get the compressedDataSize field.
* @return PVStructurePtr.
*/
epics::pvData::PVLongPtr getCompressedDataSize() const;
/**
* Get the uncompressedDataSize field.
* @return PVStructurePtr.
*/
epics::pvData::PVLongPtr getUncompressedDataSize() const;
/**
* Get the attribute field.
* @return the PVStructurePtr.
*/
epics::pvData::PVStructureArrayPtr getAttribute() const;
/**
* Get the dimension field.
* @return the PVStructurePtr.
*/
epics::pvData::PVStructureArrayPtr getDimension() const;
/**
* Get the uniqueId field.
* @return PVStructurePtr.
*/
epics::pvData::PVIntPtr getUniqueId() const;
/**
* Get the data timeStamp field.
* @return PVStructurePtr.
*/
epics::pvData::PVStructurePtr getDataTimeStamp() const;
/**
* Get the descriptor field.
* @return The pvString or null if no function field.
*/
epics::pvData::PVStringPtr getDescriptor() const;
/**
* Get the timeStamp field.
* @return PVStructurePtr which may be null.
*/
epics::pvData::PVStructurePtr getTimeStamp() const;
/**
* Get the alarm field.
* @return PVStructurePtr which may be null.
*/
epics::pvData::PVStructurePtr getAlarm() const;
/**
* Get the display field.
* @return PVStructurePtr which may be null.
*/
epics::pvData::PVStructurePtr getDisplay() const;
private:
NTNDArray(epics::pvData::PVStructurePtr const & pvStructure);
epics::pvData::PVStructurePtr pvNTNDArray;
friend class detail::NTNDArrayBuilder;
};
}}
#endif /* NTNDARRAY_H */

View File

@@ -1,284 +0,0 @@
/* ntscalar.h */
/**
* Copyright - See the COPYRIGHT that is included with this distribution.
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
*/
#ifndef NTSCALAR_H
#define NTSCALAR_H
#ifdef epicsExportSharedSymbols
# define ntscalarEpicsExportSharedSymbols
# undef epicsExportSharedSymbols
#endif
#include <pv/pvDisplay.h>
#include <pv/pvControl.h>
#ifdef ntscalarEpicsExportSharedSymbols
# define epicsExportSharedSymbols
# undef ntscalarEpicsExportSharedSymbols
#endif
#include <pv/ntfield.h>
#include <shareLib.h>
namespace epics { namespace nt {
class NTScalar;
typedef std::tr1::shared_ptr<NTScalar> NTScalarPtr;
namespace detail {
/**
* Interface for in-line creating of NTScalar.
* One instance can be used to create multiple instances.
* An instance of this object must not be used concurrently (an object has a state).
* @author mse
*/
class epicsShareClass NTScalarBuilder :
public std::tr1::enable_shared_from_this<NTScalarBuilder>
{
public:
POINTER_DEFINITIONS(NTScalarBuilder);
/**
* Set a value type of a NTScalar.
* @param scalarType the value type.
* @return this instance of a {@code NTTableBuilder}.
*/
shared_pointer value(epics::pvData::ScalarType scalarType);
/**
* Add descriptor field to the NTScalar.
* @return this instance of a {@code NTScalarBuilder}.
*/
shared_pointer addDescriptor();
/**
* Add alarm structure to the NTScalar.
* @return this instance of a {@code NTScalarBuilder}.
*/
shared_pointer addAlarm();
/**
* Add timeStamp structure to the NTScalar.
* @return this instance of a {@code NTScalarBuilder}.
*/
shared_pointer addTimeStamp();
/**
* Add display structure to the NTScalar.
* @return this instance of a {@code NTScalarBuilder}.
*/
shared_pointer addDisplay();
/**
* Add control structure to the NTScalar.
* @return this instance of a {@code NTScalarBuilder}.
*/
shared_pointer addControl();
/**
* Create a {@code Structure} that represents NTScalar.
* This resets this instance state and allows new instance to be created.
* @return a new instance of a {@code Structure}.
*/
epics::pvData::StructureConstPtr createStructure();
/**
* Create a {@code PVStructure} that represents NTScalar.
* This resets this instance state and allows new {@code instance to be created.
* @return a new instance of a {@code PVStructure}
*/
epics::pvData::PVStructurePtr createPVStructure();
/**
* Create a {@code NTScalar} instance.
* This resets this instance state and allows new {@code instance to be created.
* @return a new instance of a {@code NTScalar}
*/
NTScalarPtr create();
/**
* Add extra {@code Field} to the type.
* @param name name of the field.
* @param field a field to add.
* @return this instance of a {@code NTScalarBuilder}.
*/
shared_pointer add(std::string const & name, epics::pvData::FieldConstPtr const & field);
private:
NTScalarBuilder();
void reset();
bool valueTypeSet;
epics::pvData::ScalarType valueType;
bool descriptor;
bool alarm;
bool timeStamp;
bool display;
bool control;
// NOTE: this preserves order, however it does not handle duplicates
epics::pvData::StringArray extraFieldNames;
epics::pvData::FieldConstPtrArray extraFields;
friend class ::epics::nt::NTScalar;
};
}
typedef std::tr1::shared_ptr<detail::NTScalarBuilder> NTScalarBuilderPtr;
/**
* Convenience Class for NTScalar
* @author mrk
*/
class epicsShareClass NTScalar
{
public:
POINTER_DEFINITIONS(NTScalar);
static const std::string URI;
/**
* Wrap (aka dynamic cast, or wrap) the structure to NTScalar.
* First isCompatible is called.
* This method will nullptr if the structure is is not compatible.
* This method will nullptr if the structure is nullptr.
* @param structure The structure to wrap-ed (dynamic cast, wrapped) to NTScalar.
* @return NTScalar instance on success, nullptr otherwise.
*/
static shared_pointer wrap(epics::pvData::PVStructurePtr const & structure);
/**
* Wrap (aka dynamic cast, or wrap) the structure to NTMultiChannel without checking for isCompatible
* @param structure The structure to wrap-ed (dynamic cast, wrapped) to NTScalar.
* @return NTScalar instance.
*/
static shared_pointer wrapUnsafe(epics::pvData::PVStructurePtr const & structure);
/**
* Is the structure an NTScalar.
* @param structure The structure to test.
* @return (false,true) if (is not, is) an NTScalar.
*/
static bool is_a(epics::pvData::StructureConstPtr const & structure);
/**
* Is the pvStructure compatible with NTScalar.
* This method introspects the fields to see if they are compatible.
* @param pvStructure The pvStructure to test.
* @return (false,true) if (is not, is) an NTMultiChannel.
*/
static bool isCompatible(
epics::pvData::PVStructurePtr const &pvStructure);
/**
* Create a NTScalar builder instance.
* @return builder instance.
*/
static NTScalarBuilderPtr createBuilder();
/**
* Destructor.
*/
~NTScalar() {}
/**
* Attach a pvTimeStamp.
* @param pvTimeStamp The pvTimeStamp that will be attached.
* Does nothing if no timeStamp.
* @return true if the operation was successfull (i.e. this instance has a timeStamp field), otherwise false.
*/
bool attachTimeStamp(epics::pvData::PVTimeStamp &pvTimeStamp) const;
/**
* Attach an pvAlarm.
* @param pvAlarm The pvAlarm that will be attached.
* Does nothing if no alarm.
* @return true if the operation was successfull (i.e. this instance has a timeStamp field), otherwise false.
*/
bool attachAlarm(epics::pvData::PVAlarm &pvAlarm) const;
/**
* Attach an pvDisplay.
* @param pvDisplay The pvDisplay that will be attached.
* Does nothing if no display.
* @return true if the operation was successfull (i.e. this instance has a display field), otherwise false.
*/
bool attachDisplay(epics::pvData::PVDisplay &pvDisplay) const;
/**
* Attach an pvControl.
* @param pvControl The pvControl that will be attached.
* Does nothing if no control.
* @return true if the operation was successfull (i.e. this instance has a control field), otherwise false.
*/
bool attachControl(epics::pvData::PVControl &pvControl) const;
/**
* Get the pvStructure.
* @return PVStructurePtr.
*/
epics::pvData::PVStructurePtr getPVStructure() const;
/**
* Get the descriptor field.
* @return The pvString or null if no function field.
*/
epics::pvData::PVStringPtr getDescriptor() const;
/**
* Get the timeStamp.
* @return PVStructurePtr which may be null.
*/
epics::pvData::PVStructurePtr getTimeStamp() const;
/**
* Get the alarm.
* @return PVStructurePtr which may be null.
*/
epics::pvData::PVStructurePtr getAlarm() const;
/**
* Get the display.
* @return PVStructurePtr which may be null.
*/
epics::pvData::PVStructurePtr getDisplay() const;
/**
* Get the control.
* @return PVStructurePtr which may be null.
*/
epics::pvData::PVStructurePtr getControl() const;
/**
* Get the value field.
* @return The PVField for the values.
*/
epics::pvData::PVFieldPtr getValue() const;
/**
* Get the value field of a specified type (e.g. PVDouble).
* @return The <PVT> field for the values.
*/
template<typename PVT>
std::tr1::shared_ptr<PVT> getValue() const
{
return std::tr1::dynamic_pointer_cast<PVT>(pvValue);
}
private:
NTScalar(epics::pvData::PVStructurePtr const & pvStructure);
epics::pvData::PVStructurePtr pvNTScalar;
epics::pvData::PVFieldPtr pvValue;
friend class detail::NTScalarBuilder;
};
}}
#endif /* NTScalar_H */

View File

@@ -1,287 +0,0 @@
/* ntscalarArray.h */
/**
* Copyright - See the COPYRIGHT that is included with this distribution.
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
*/
#ifndef NTSCALARARRAY_H
#define NTSCALARARRAY_H
#ifdef epicsExportSharedSymbols
# define ntscalarArrayEpicsExportSharedSymbols
# undef epicsExportSharedSymbols
#endif
#include <pv/pvDisplay.h>
#include <pv/pvControl.h>
#ifdef ntscalarArrayEpicsExportSharedSymbols
# define epicsExportSharedSymbols
# undef ntscalarArrayEpicsExportSharedSymbols
#endif
#include <pv/ntfield.h>
#include <shareLib.h>
namespace epics { namespace nt {
class NTScalarArray;
typedef std::tr1::shared_ptr<NTScalarArray> NTScalarArrayPtr;
namespace detail {
/**
* Interface for in-line creating of NTScalarArray.
* One instance can be used to create multiple instances.
* An instance of this object must not be used concurrently (an object has a state).
* @author mse
*/
class epicsShareClass NTScalarArrayBuilder :
public std::tr1::enable_shared_from_this<NTScalarArrayBuilder>
{
public:
POINTER_DEFINITIONS(NTScalarArrayBuilder);
/**
* Set a value type of a NTScalarArray.
* @param elementType the value array element type.
* @return this instance of a {@code NTTableBuilder}.
*/
shared_pointer arrayValue(epics::pvData::ScalarType elementType);
/**
* Add descriptor field to the NTScalarArray.
* @return this instance of a {@code NTScalarArrayBuilder}.
*/
shared_pointer addDescriptor();
/**
* Add alarm structure to the NTScalarArray.
* @return this instance of a {@code NTScalarArrayBuilder}.
*/
shared_pointer addAlarm();
/**
* Add timeStamp structure to the NTScalarArray.
* @return this instance of a {@code NTScalarArrayBuilder}.
*/
shared_pointer addTimeStamp();
/**
* Add display structure to the NTScalarArray.
* @return this instance of a {@code NTScalarArrayBuilder}.
*/
shared_pointer addDisplay();
/**
* Add control structure to the NTScalarArray.
* @return this instance of a {@code NTScalarArrayBuilder}.
*/
shared_pointer addControl();
/**
* Create a {@code Structure} that represents NTScalarArray.
* This resets this instance state and allows new instance to be created.
* @return a new instance of a {@code Structure}.
*/
epics::pvData::StructureConstPtr createStructure();
/**
* Create a {@code PVStructure} that represents NTScalarArray.
* This resets this instance state and allows new {@code instance to be created.
* @return a new instance of a {@code PVStructure}
*/
epics::pvData::PVStructurePtr createPVStructure();
/**
* Create a {@code NTScalarArray} instance.
* This resets this instance state and allows new {@code instance to be created.
* @return a new instance of a {@code NTScalarArray}
*/
NTScalarArrayPtr create();
/**
* Add extra {@code Field} to the type.
* @param name name of the field.
* @param field a field to add.
* @return this instance of a {@code NTScalarArrayBuilder}.
*/
shared_pointer add(std::string const & name, epics::pvData::FieldConstPtr const & field);
private:
NTScalarArrayBuilder();
void reset();
bool valueTypeSet;
epics::pvData::ScalarType valueType;
bool descriptor;
bool alarm;
bool timeStamp;
bool display;
bool control;
// NOTE: this preserves order, however it does not handle duplicates
epics::pvData::StringArray extraFieldNames;
epics::pvData::FieldConstPtrArray extraFields;
friend class ::epics::nt::NTScalarArray;
};
}
typedef std::tr1::shared_ptr<detail::NTScalarArrayBuilder> NTScalarArrayBuilderPtr;
/**
* Convenience Class for NTScalarArray
* @author mrk
*/
class epicsShareClass NTScalarArray
{
public:
POINTER_DEFINITIONS(NTScalarArray);
static const std::string URI;
/**
* Wrap (aka dynamic cast, or wrap) the structure to NTScalarArray.
* First isCompatible is called.
* This method will nullptr if the structure is is not compatible.
* This method will nullptr if the structure is nullptr.
* @param structure The structure to wrap-ed (dynamic cast, wrapped) to NTScalarArray.
* @return NTScalarArray instance on success, nullptr otherwise.
*/
static shared_pointer wrap(epics::pvData::PVStructurePtr const & structure);
/**
* Wrap (aka dynamic cast, or wrap) the structure to NTMultiChannel without checking for isCompatible
* @param structure The structure to wrap-ed (dynamic cast, wrapped) to NTScalarArray.
* @return NTScalarArray instance.
*/
static shared_pointer wrapUnsafe(epics::pvData::PVStructurePtr const & structure);
/**
* Is the structure an NTScalarArray.
* @param structure The structure to test.
* @return (false,true) if (is not, is) an NTScalarArray.
*/
static bool is_a(epics::pvData::StructureConstPtr const & structure);
/**
* Is the pvStructure compatible with NTScalarArray..
* This method introspects the fields to see if they are compatible.
* @param pvStructure The pvStructure to test.
* @return (false,true) if (is not, is) an NTMultiChannel.
*/
static bool isCompatible(
epics::pvData::PVStructurePtr const &pvStructure);
/**
* Create a NTScalarArray builder instance.
* @return builder instance.
*/
static NTScalarArrayBuilderPtr createBuilder();
/**
* Destructor.
*/
~NTScalarArray() {}
/**
* Attach a pvTimeStamp.
* @param pvTimeStamp The pvTimeStamp that will be attached.
* Does nothing if no timeStamp.
* @return true if the operation was successfull (i.e. this instance has a timeStamp field), otherwise false.
*/
bool attachTimeStamp(epics::pvData::PVTimeStamp &pvTimeStamp) const;
/**
* Attach an pvAlarm.
* @param pvAlarm The pvAlarm that will be attached.
* Does nothing if no alarm.
* @return true if the operation was successfull (i.e. this instance has a timeStamp field), otherwise false.
*/
bool attachAlarm(epics::pvData::PVAlarm &pvAlarm) const;
/**
* Attach an pvDisplay.
* @param pvDisplay The pvDisplay that will be attached.
* Does nothing if no display.
* @return true if the operation was successfull (i.e. this instance has a display field), otherwise false.
*/
bool attachDisplay(epics::pvData::PVDisplay &pvDisplay) const;
/**
* Attach an pvControl.
* @param pvControl The pvControl that will be attached.
* Does nothing if no control.
* @return true if the operation was successfull (i.e. this instance has a control field), otherwise false.
*/
bool attachControl(epics::pvData::PVControl &pvControl) const;
/**
* Get the pvStructure.
* @return PVStructurePtr.
*/
epics::pvData::PVStructurePtr getPVStructure() const;
/**
* Get the descriptor field.
* @return The pvString or null if no function field.
*/
epics::pvData::PVStringPtr getDescriptor() const;
/**
* Get the timeStamp.
* @return PVStructurePtr which may be null.
*/
epics::pvData::PVStructurePtr getTimeStamp() const;
/**
* Get the alarm.
* @return PVStructurePtr which may be null.
*/
epics::pvData::PVStructurePtr getAlarm() const;
/**
* Get the display.
* @return PVStructurePtr which may be null.
*/
epics::pvData::PVStructurePtr getDisplay() const;
/**
* Get the control.
* @return PVStructurePtr which may be null.
*/
epics::pvData::PVStructurePtr getControl() const;
/**
* Get the value field.
* @return The PVField for the values.
*/
epics::pvData::PVFieldPtr getValue() const;
/**
* Get the value field of a specified type (e.g. PVDoubleArray).
* @return The <PVT> field for the values.
*/
template<typename PVT>
std::tr1::shared_ptr<PVT> getValue() const
{
return std::tr1::dynamic_pointer_cast<PVT>(pvValue);
}
private:
NTScalarArray(epics::pvData::PVStructurePtr const & pvStructure);
epics::pvData::PVStructurePtr pvNTScalarArray;
epics::pvData::PVFieldPtr pvValue;
friend class detail::NTScalarArrayBuilder;
};
}}
#endif /* NTScalarArray_H */

View File

@@ -1,256 +0,0 @@
/* nttable.h */
/**
* Copyright - See the COPYRIGHT that is included with this distribution.
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
*/
#ifndef NTTABLE_H
#define NTTABLE_H
#include <vector>
#include <string>
#ifdef epicsExportSharedSymbols
# define nttableEpicsExportSharedSymbols
# undef epicsExportSharedSymbols
#endif
#include <pv/pvDisplay.h>
#include <pv/pvControl.h>
#ifdef nttableEpicsExportSharedSymbols
# define epicsExportSharedSymbols
# undef nttableEpicsExportSharedSymbols
#endif
#include <pv/ntfield.h>
#include <shareLib.h>
namespace epics { namespace nt {
class NTTable;
typedef std::tr1::shared_ptr<NTTable> NTTablePtr;
namespace detail {
/**
* Interface for in-line creating of NTTable.
* One instance can be used to create multiple instances.
* An instance of this object must not be used concurrently (an object has a state).
* @author mse
*/
class epicsShareClass NTTableBuilder :
public std::tr1::enable_shared_from_this<NTTableBuilder>
{
public:
POINTER_DEFINITIONS(NTTableBuilder);
/**
* Add a column of given {@code Scalar} type.
* @param name name of the column.
* @param elementType column type, a scalar array.
* @return this instance of a {@code NTTableBuilder}.
*/
shared_pointer add(std::string const & name, epics::pvData::ScalarType elememtType);
/**
* Add descriptor field to the NTTable.
* @return this instance of a {@code NTTableBuilder}.
*/
shared_pointer addDescriptor();
/**
* Add alarm structure to the NTTable.
* @return this instance of a {@code NTTableBuilder}.
*/
shared_pointer addAlarm();
/**
* Add timeStamp structure to the NTTable.
* @return this instance of a {@code NTTableBuilder}.
*/
shared_pointer addTimeStamp();
/**
* Create a {@code Structure} that represents NTTable.
* This resets this instance state and allows new instance to be created.
* @return a new instance of a {@code Structure}.
*/
epics::pvData::StructureConstPtr createStructure();
/**
* Create a {@code PVStructure} that represents NTTable.
* This resets this instance state and allows new {@code instance to be created.
* @return a new instance of a {@code PVStructure}
*/
epics::pvData::PVStructurePtr createPVStructure();
/**
* Create a {@code NTTable} instance.
* This resets this instance state and allows new {@code instance to be created.
* @return a new instance of a {@code NTTable}
*/
NTTablePtr create();
/**
* Add extra {@code Field} to the type.
* @param name name of the field.
* @param field a field to add.
* @return this instance of a {@code NTTableBuilder}.
*/
shared_pointer add(std::string const & name, epics::pvData::FieldConstPtr const & field);
private:
NTTableBuilder();
void reset();
std::vector<std::string> labels;
std::vector<epics::pvData::ScalarType> types;
bool descriptor;
bool alarm;
bool timeStamp;
// NOTE: this preserves order, however it does not handle duplicates
epics::pvData::StringArray extraFieldNames;
epics::pvData::FieldConstPtrArray extraFields;
friend class ::epics::nt::NTTable;
};
}
typedef std::tr1::shared_ptr<detail::NTTableBuilder> NTTableBuilderPtr;
/**
* Convenience Class for NTTable
* @author mrk
*/
class epicsShareClass NTTable
{
public:
POINTER_DEFINITIONS(NTTable);
static const std::string URI;
/**
* Wrap (aka dynamic cast, or wrap) the structure to NTTable.
* First isCompatible is called.
* This method will nullptr if the structure is is not compatible.
* This method will nullptr if the structure is nullptr.
* @param structure The structure to wrap-ed (dynamic cast, wrapped) to NTTable.
* @return NTTable instance on success, nullptr otherwise.
*/
static shared_pointer wrap(epics::pvData::PVStructurePtr const & structure);
/**
* Wrap (aka dynamic cast, or wrap) the structure to NTMultiChannel without checking for isCompatible
* @param structure The structure to wrap-ed (dynamic cast, wrapped) to NTTable.
* @return NTTable instance.
*/
static shared_pointer wrapUnsafe(epics::pvData::PVStructurePtr const & structure);
/**
* Is the structure an NTTable.
* @param structure The structure to test.
* @return (false,true) if (is not, is) an NTTable.
*/
static bool is_a(epics::pvData::StructureConstPtr const & structure);
/**
* Is the pvStructure compatible with NTTable.
* This method introspects the fields to see if they are compatible.
* @param pvStructure The pvStructure to test.
* @return (false,true) if (is not, is) an NTMultiChannel.
*/
static bool isCompatible(
epics::pvData::PVStructurePtr const &pvStructure);
/**
* Create a NTTable builder instance.
* @return builder instance.
*/
static NTTableBuilderPtr createBuilder();
/**
* Destructor.
*/
~NTTable() {}
/**
* Attach a pvTimeStamp.
* @param pvTimeStamp The pvTimeStamp that will be attached.
* Does nothing if no timeStamp.
* @return true if the operation was successfull (i.e. this instance has a timeStamp field), otherwise false.
*/
bool attachTimeStamp(epics::pvData::PVTimeStamp &pvTimeStamp) const;
/**
* Attach an pvAlarm.
* @param pvAlarm The pvAlarm that will be attached.
* Does nothing if no alarm.
* @return true if the operation was successfull (i.e. this instance has a timeStamp field), otherwise false.
*/
bool attachAlarm(epics::pvData::PVAlarm &pvAlarm) const;
/**
* Get the pvStructure.
* @return PVStructurePtr.
*/
epics::pvData::PVStructurePtr getPVStructure() const;
/**
* Get the descriptor field.
* @return The pvString or null if no function field.
*/
epics::pvData::PVStringPtr getDescriptor() const;
/**
* Get the timeStamp.
* @return PVStructurePtr which may be null.
*/
epics::pvData::PVStructurePtr getTimeStamp() const;
/**
* Get the alarm.
* @return PVStructurePtr which may be null.
*/
epics::pvData::PVStructurePtr getAlarm() const;
/**
* Get the labels field.
* @return The pvStringArray for the labels.
*/
epics::pvData::PVStringArrayPtr getLabels() const;
/**
* Get the PVField (column) for a field that follows the label field.
* @param columnName The name of the column.
* @return The PVFieldPtr for the field.
*/
epics::pvData::PVFieldPtr getColumn(std::string const & columnName) const;
/**
* Get the PVField (column) for a field that follows the label field of a specified type (e.g. PVDoubleArray).
* @param columnName The name of the column.
* @return The <PVT> field.
*/
template<typename PVT>
std::tr1::shared_ptr<PVT> getColumn(std::string const & columnName) const
{
epics::pvData::PVFieldPtr pvField = getColumn(columnName);
if (pvField.get())
return std::tr1::dynamic_pointer_cast<PVT>(pvField);
else
return std::tr1::shared_ptr<PVT>();
}
private:
NTTable(epics::pvData::PVStructurePtr const & pvStructure);
epics::pvData::PVStructurePtr pvNTTable;
friend class detail::NTTableBuilder;
};
}}
#endif /* NTTABLE_H */

View File

@@ -1,25 +0,0 @@
/* ntutils.cpp */
/**
* Copyright - See the COPYRIGHT that is included with this distribution.
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
*/
#define epicsExportSharedSymbols
#include <pv/ntutils.h>
using namespace std;
namespace epics { namespace nt {
bool NTUtils::is_a(const std::string &u1, const std::string &u2)
{
// remove minor for the u2
size_t pos = u2.find_last_of('.');
std::string su2 = (pos == string::npos) ? u2 : u2.substr(0, pos);
// "starts with comparison"
return su2.size() <= u1.size() && u1.compare(0, su2.size(), su2) == 0;
}
}}

381
src/ntaggregate.cpp Normal file
View File

@@ -0,0 +1,381 @@
/* ntaggregate.cpp */
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#define epicsExportSharedSymbols
#include <pv/ntaggregate.h>
#include <pv/ntutils.h>
using namespace std;
using namespace epics::pvData;
namespace epics { namespace nt {
static NTFieldPtr ntField = NTField::get();
namespace detail {
StructureConstPtr NTAggregateBuilder::createStructure()
{
FieldBuilderPtr builder =
getFieldCreate()->createFieldBuilder()->
setId(NTAggregate::URI)->
add("value", pvDouble)->
add("N", pvLong);
if (dispersion)
builder->add("dispersion", pvDouble);
if (first)
builder->add("first", pvDouble);
if (firstTimeStamp)
builder->add("firstTimeStamp", ntField->createTimeStamp());
if (last)
builder->add("last" , pvDouble);
if (lastTimeStamp)
builder->add("lastTimeStamp", ntField->createTimeStamp());
if (max)
builder->add("max", pvDouble);
if (min)
builder->add("min", pvDouble);
if (descriptor)
builder->add("descriptor", pvString);
if (alarm)
builder->add("alarm", ntField->createAlarm());
if (timeStamp)
builder->add("timeStamp", ntField->createTimeStamp());
size_t extraCount = extraFieldNames.size();
for (size_t i = 0; i< extraCount; i++)
builder->add(extraFieldNames[i], extraFields[i]);
StructureConstPtr s = builder->createStructure();
reset();
return s;
}
NTAggregateBuilder::shared_pointer NTAggregateBuilder::addDispersion()
{
dispersion = true;
return shared_from_this();
}
NTAggregateBuilder::shared_pointer NTAggregateBuilder::addFirst()
{
first = true;
return shared_from_this();
}
NTAggregateBuilder::shared_pointer NTAggregateBuilder::addFirstTimeStamp()
{
firstTimeStamp = true;
return shared_from_this();
}
NTAggregateBuilder::shared_pointer NTAggregateBuilder::addLast()
{
last = true;
return shared_from_this();
}
NTAggregateBuilder::shared_pointer NTAggregateBuilder::addLastTimeStamp()
{
lastTimeStamp = true;
return shared_from_this();
}
NTAggregateBuilder::shared_pointer NTAggregateBuilder::addMax()
{
max = true;
return shared_from_this();
}
NTAggregateBuilder::shared_pointer NTAggregateBuilder::addMin()
{
min = true;
return shared_from_this();
}
NTAggregateBuilder::shared_pointer NTAggregateBuilder::addDescriptor()
{
descriptor = true;
return shared_from_this();
}
NTAggregateBuilder::shared_pointer NTAggregateBuilder::addAlarm()
{
alarm = true;
return shared_from_this();
}
NTAggregateBuilder::shared_pointer NTAggregateBuilder::addTimeStamp()
{
timeStamp = true;
return shared_from_this();
}
PVStructurePtr NTAggregateBuilder::createPVStructure()
{
return getPVDataCreate()->createPVStructure(createStructure());
}
NTAggregatePtr NTAggregateBuilder::create()
{
return NTAggregatePtr(new NTAggregate(createPVStructure()));
}
NTAggregateBuilder::NTAggregateBuilder()
{
reset();
}
void NTAggregateBuilder::reset()
{
dispersion = false;
first = false;
firstTimeStamp = false;
last = false;
lastTimeStamp = false;
max = false;
min = false;
descriptor = false;
alarm = false;
timeStamp = false;
extraFieldNames.clear();
extraFields.clear();
}
NTAggregateBuilder::shared_pointer NTAggregateBuilder::add(string const & name, FieldConstPtr const & field)
{
extraFields.push_back(field); extraFieldNames.push_back(name);
return shared_from_this();
}
}
const std::string NTAggregate::URI("epics:nt/NTAggregate:1.0");
NTAggregate::shared_pointer NTAggregate::wrap(PVStructurePtr const & pvStructure)
{
if(!isCompatible(pvStructure)) return shared_pointer();
return wrapUnsafe(pvStructure);
}
NTAggregate::shared_pointer NTAggregate::wrapUnsafe(PVStructurePtr const & pvStructure)
{
return shared_pointer(new NTAggregate(pvStructure));
}
bool NTAggregate::is_a(StructureConstPtr const & structure)
{
return NTUtils::is_a(structure->getID(), URI);
}
bool NTAggregate::is_a(PVStructurePtr const & pvStructure)
{
return is_a(pvStructure->getStructure());
}
bool NTAggregate::isCompatible(StructureConstPtr const &structure)
{
if (structure.get() == 0) return false;
ScalarConstPtr valueField = structure->getField<Scalar>("value");
if (valueField.get() == 0 || valueField->getScalarType() != pvDouble)
return false;
ScalarConstPtr nField = structure->getField<Scalar>("N");
if (nField.get() == 0 || nField->getScalarType() != pvLong)
return false;
FieldConstPtr field = structure->getField("dispersion");
if (field.get())
{
ScalarConstPtr dispersionField = structure->getField<Scalar>("dispersion");
if (!dispersionField.get() || dispersionField->getScalarType() != pvDouble)
return false;
}
field = structure->getField("first");
if (field.get())
{
ScalarConstPtr firstField = structure->getField<Scalar>("first");
if (!firstField.get() || firstField->getScalarType() != pvDouble)
return false;
}
field = structure->getField("firstTimeStamp");
if (field.get() && !ntField->isTimeStamp(field))
return false;
field = structure->getField("last");
if (field.get())
{
ScalarConstPtr lastField = structure->getField<Scalar>("last");
if (!lastField.get() || lastField->getScalarType() != pvDouble)
return false;
}
field = structure->getField("lastTimeStamp");
if (field.get() && !ntField->isTimeStamp(field))
return false;
field = structure->getField("max");
if (field.get())
{
ScalarConstPtr maxField = structure->getField<Scalar>("max");
if (!maxField.get() || maxField->getScalarType() != pvDouble)
return false;
}
field = structure->getField("min");
if (field.get())
{
ScalarConstPtr minField = structure->getField<Scalar>("min");
if (!minField.get() || minField->getScalarType() != pvDouble)
return false;
}
field = structure->getField("descriptor");
if (field.get())
{
ScalarConstPtr descriptorField = structure->getField<Scalar>("descriptor");
if (!descriptorField.get() || descriptorField->getScalarType() != pvString)
return false;
}
NTFieldPtr ntField = NTField::get();
field = structure->getField("alarm");
if (field.get() && !ntField->isAlarm(field))
return false;
field = structure->getField("timeStamp");
if (field.get() && !ntField->isTimeStamp(field))
return false;
return true;
}
bool NTAggregate::isCompatible(PVStructurePtr const & pvStructure)
{
if(!pvStructure) return false;
return isCompatible(pvStructure->getStructure());
}
bool NTAggregate::isValid()
{
return true;
}
NTAggregateBuilderPtr NTAggregate::createBuilder()
{
return NTAggregateBuilderPtr(new detail::NTAggregateBuilder());
}
bool NTAggregate::attachTimeStamp(PVTimeStamp &pvTimeStamp) const
{
PVStructurePtr ts = getTimeStamp();
if (ts)
return pvTimeStamp.attach(ts);
else
return false;
}
bool NTAggregate::attachAlarm(PVAlarm &pvAlarm) const
{
PVStructurePtr al = getAlarm();
if (al)
return pvAlarm.attach(al);
else
return false;
}
PVStructurePtr NTAggregate::getPVStructure() const
{
return pvNTAggregate;
}
PVStringPtr NTAggregate::getDescriptor() const
{
return pvNTAggregate->getSubField<PVString>("descriptor");
}
PVStructurePtr NTAggregate::getTimeStamp() const
{
return pvNTAggregate->getSubField<PVStructure>("timeStamp");
}
PVStructurePtr NTAggregate::getAlarm() const
{
return pvNTAggregate->getSubField<PVStructure>("alarm");
}
PVDoublePtr NTAggregate::getValue() const
{
return pvValue;
}
PVLongPtr NTAggregate::getN() const
{
return pvNTAggregate->getSubField<PVLong>("N");
}
PVDoublePtr NTAggregate::getDispersion() const
{
return pvNTAggregate->getSubField<PVDouble>("dispersion");
}
PVDoublePtr NTAggregate::getFirst() const
{
return pvNTAggregate->getSubField<PVDouble>("first");
}
PVStructurePtr NTAggregate::getFirstTimeStamp() const
{
return pvNTAggregate->getSubField<PVStructure>("firstTimeStamp");
}
PVDoublePtr NTAggregate::getLast() const
{
return pvNTAggregate->getSubField<PVDouble>("last");
}
PVStructurePtr NTAggregate::getLastTimeStamp() const
{
return pvNTAggregate->getSubField<PVStructure>("lastTimeStamp");
}
PVDoublePtr NTAggregate::getMax() const
{
return pvNTAggregate->getSubField<PVDouble>("max");
}
PVDoublePtr NTAggregate::getMin() const
{
return pvNTAggregate->getSubField<PVDouble>("min");
}
NTAggregate::NTAggregate(PVStructurePtr const & pvStructure) :
pvNTAggregate(pvStructure), pvValue(pvNTAggregate->getSubField<PVDouble>("value"))
{}
}}

250
src/ntattribute.cpp Normal file
View File

@@ -0,0 +1,250 @@
/* ntattribute.cpp */
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#define epicsExportSharedSymbols
#include <pv/ntattribute.h>
#include <pv/ntutils.h>
using namespace std;
using namespace epics::pvData;
namespace epics { namespace nt {
static NTFieldPtr ntField = NTField::get();
namespace detail {
StructureConstPtr NTAttributeBuilder::createStructure()
{
FieldBuilderPtr builder =
getFieldCreate()->createFieldBuilder()->
setId(NTAttribute::URI)->
add("name", pvString)->
add("value", getFieldCreate()->createVariantUnion());
if (tags)
builder->addArray("tags", pvString);
if (descriptor)
builder->add("descriptor", pvString);
if (alarm)
builder->add("alarm", ntField->createAlarm());
if (timeStamp)
builder->add("timeStamp", ntField->createTimeStamp());
size_t extraCount = extraFieldNames.size();
for (size_t i = 0; i< extraCount; i++)
builder->add(extraFieldNames[i], extraFields[i]);
StructureConstPtr s = builder->createStructure();
reset();
return s;
}
NTAttributeBuilder::shared_pointer NTAttributeBuilder::addTags()
{
tags = true;
return shared_from_this();
}
NTAttributeBuilder::shared_pointer NTAttributeBuilder::addDescriptor()
{
descriptor = true;
return shared_from_this();
}
NTAttributeBuilder::shared_pointer NTAttributeBuilder::addAlarm()
{
alarm = true;
return shared_from_this();
}
NTAttributeBuilder::shared_pointer NTAttributeBuilder::addTimeStamp()
{
timeStamp = true;
return shared_from_this();
}
PVStructurePtr NTAttributeBuilder::createPVStructure()
{
return getPVDataCreate()->createPVStructure(createStructure());
}
NTAttributePtr NTAttributeBuilder::create()
{
return NTAttributePtr(new NTAttribute(createPVStructure()));
}
NTAttributeBuilder::NTAttributeBuilder()
{
reset();
}
void NTAttributeBuilder::reset()
{
descriptor = false;
alarm = false;
timeStamp = false;
extraFieldNames.clear();
extraFields.clear();
}
NTAttributeBuilder::shared_pointer NTAttributeBuilder::add(string const & name, FieldConstPtr const & field)
{
extraFields.push_back(field); extraFieldNames.push_back(name);
return shared_from_this();
}
}
const std::string NTAttribute::URI("epics:nt/NTAttribute:1.0");
NTAttribute::shared_pointer NTAttribute::wrap(PVStructurePtr const & pvStructure)
{
if(!isCompatible(pvStructure)) return shared_pointer();
return wrapUnsafe(pvStructure);
}
NTAttribute::shared_pointer NTAttribute::wrapUnsafe(PVStructurePtr const & pvStructure)
{
return shared_pointer(new NTAttribute(pvStructure));
}
bool NTAttribute::is_a(StructureConstPtr const & structure)
{
return NTUtils::is_a(structure->getID(), URI);
}
bool NTAttribute::is_a(PVStructurePtr const & pvStructure)
{
return is_a(pvStructure->getStructure());
}
bool NTAttribute::isCompatible(StructureConstPtr const & structure)
{
if (structure.get() == 0) return false;
ScalarConstPtr nameField = structure->getField<Scalar>("name");
if (nameField.get() == 0 || nameField->getScalarType() != pvString)
return false;
UnionConstPtr valueField = structure->getField<Union>("value");
if (valueField.get() == 0 || !valueField->isVariant())
return false;
FieldConstPtr field = structure->getField("tags");
if (field.get())
{
ScalarArrayConstPtr tagsField = structure->getField<ScalarArray>("tags");
if (tagsField.get() == 0 || tagsField->getElementType() != pvString)
return false;
}
field = structure->getField("descriptor");
if (field.get())
{
ScalarConstPtr descriptorField = structure->getField<Scalar>("descriptor");
if (!descriptorField.get() || descriptorField->getScalarType() != pvString)
return false;
}
NTFieldPtr ntField = NTField::get();
field = structure->getField("alarm");
if (field.get() && !ntField->isAlarm(field))
return false;
field = structure->getField("timeStamp");
if (field.get() && !ntField->isTimeStamp(field))
return false;
return true;
}
bool NTAttribute::isCompatible(PVStructurePtr const & pvStructure)
{
if(!pvStructure) return false;
return isCompatible(pvStructure->getStructure());
}
bool NTAttribute::isValid()
{
return true;
}
NTAttributeBuilderPtr NTAttribute::createBuilder()
{
return NTAttributeBuilderPtr(new detail::NTAttributeBuilder());
}
bool NTAttribute::attachTimeStamp(PVTimeStamp &pvTimeStamp) const
{
PVStructurePtr ts = getTimeStamp();
if (ts)
return pvTimeStamp.attach(ts);
else
return false;
}
bool NTAttribute::attachAlarm(PVAlarm &pvAlarm) const
{
PVStructurePtr al = getAlarm();
if (al)
return pvAlarm.attach(al);
else
return false;
}
PVStructurePtr NTAttribute::getPVStructure() const
{
return pvNTAttribute;
}
PVStringPtr NTAttribute::getDescriptor() const
{
return pvNTAttribute->getSubField<PVString>("descriptor");
}
PVStructurePtr NTAttribute::getTimeStamp() const
{
return pvNTAttribute->getSubField<PVStructure>("timeStamp");
}
PVStructurePtr NTAttribute::getAlarm() const
{
return pvNTAttribute->getSubField<PVStructure>("alarm");
}
PVStringPtr NTAttribute::getName() const
{
return pvNTAttribute->getSubField<PVString>("name");
}
PVUnionPtr NTAttribute::getValue() const
{
return pvValue;
}
PVStringArrayPtr NTAttribute::getTags() const
{
return pvNTAttribute->getSubField<PVStringArray>("tags");
}
NTAttribute::NTAttribute(PVStructurePtr const & pvStructure) :
pvNTAttribute(pvStructure), pvValue(pvNTAttribute->getSubField<PVUnion>("value"))
{
}
}}

238
src/ntcontinuum.cpp Normal file
View File

@@ -0,0 +1,238 @@
/* ntcontinuum.cpp */
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#define epicsExportSharedSymbols
#include <pv/ntcontinuum.h>
#include <pv/ntutils.h>
using namespace std;
using namespace epics::pvData;
namespace epics { namespace nt {
static NTFieldPtr ntField = NTField::get();
namespace detail {
StructureConstPtr NTContinuumBuilder::createStructure()
{
FieldBuilderPtr builder =
getFieldCreate()->createFieldBuilder()->
setId(NTContinuum::URI)->
addArray("base", pvDouble)->
addArray("value", pvDouble)->
addArray("units", pvString);
if (descriptor)
builder->add("descriptor", pvString);
if (alarm)
builder->add("alarm", ntField->createAlarm());
if (timeStamp)
builder->add("timeStamp", ntField->createTimeStamp());
size_t extraCount = extraFieldNames.size();
for (size_t i = 0; i< extraCount; i++)
builder->add(extraFieldNames[i], extraFields[i]);
StructureConstPtr s = builder->createStructure();
reset();
return s;
}
NTContinuumBuilder::shared_pointer NTContinuumBuilder::addDescriptor()
{
descriptor = true;
return shared_from_this();
}
NTContinuumBuilder::shared_pointer NTContinuumBuilder::addAlarm()
{
alarm = true;
return shared_from_this();
}
NTContinuumBuilder::shared_pointer NTContinuumBuilder::addTimeStamp()
{
timeStamp = true;
return shared_from_this();
}
PVStructurePtr NTContinuumBuilder::createPVStructure()
{
return getPVDataCreate()->createPVStructure(createStructure());
}
NTContinuumPtr NTContinuumBuilder::create()
{
return NTContinuumPtr(new NTContinuum(createPVStructure()));
}
NTContinuumBuilder::NTContinuumBuilder()
{
reset();
}
void NTContinuumBuilder::reset()
{
descriptor = false;
alarm = false;
timeStamp = false;
extraFieldNames.clear();
extraFields.clear();
}
NTContinuumBuilder::shared_pointer NTContinuumBuilder::add(string const & name, FieldConstPtr const & field)
{
extraFields.push_back(field); extraFieldNames.push_back(name);
return shared_from_this();
}
}
const std::string NTContinuum::URI("epics:nt/NTContinuum:1.0");
NTContinuum::shared_pointer NTContinuum::wrap(PVStructurePtr const & pvStructure)
{
if(!isCompatible(pvStructure)) return shared_pointer();
return wrapUnsafe(pvStructure);
}
NTContinuum::shared_pointer NTContinuum::wrapUnsafe(PVStructurePtr const & pvStructure)
{
return shared_pointer(new NTContinuum(pvStructure));
}
bool NTContinuum::is_a(StructureConstPtr const & structure)
{
return NTUtils::is_a(structure->getID(), URI);
}
bool NTContinuum::is_a(PVStructurePtr const & pvStructure)
{
return is_a(pvStructure->getStructure());
}
bool NTContinuum::isCompatible(StructureConstPtr const & structure)
{
if (structure.get() == 0) return false;
ScalarArrayConstPtr baseField = structure->getField<ScalarArray>("base");
if (baseField.get() == 0 || baseField->getElementType() != pvDouble)
return false;
ScalarArrayConstPtr valueField = structure->getField<ScalarArray>("value");
if (valueField.get() == 0 || valueField->getElementType() != pvDouble)
return false;
ScalarArrayConstPtr unitsField = structure->getField<ScalarArray>("units");
if (unitsField.get() == 0 || unitsField->getElementType() != pvString)
return false;
FieldConstPtr field = structure->getField("descriptor");
if (field.get())
{
ScalarConstPtr descriptorField = structure->getField<Scalar>("descriptor");
if (!descriptorField.get() || descriptorField->getScalarType() != pvString)
return false;
}
NTFieldPtr ntField = NTField::get();
field = structure->getField("alarm");
if (field.get() && !ntField->isAlarm(field))
return false;
field = structure->getField("timeStamp");
if (field.get() && !ntField->isTimeStamp(field))
return false;
return true;
}
bool NTContinuum::isCompatible(PVStructurePtr const & pvStructure)
{
if(!pvStructure) return false;
return isCompatible(pvStructure->getStructure());
}
bool NTContinuum::isValid()
{
return ((getUnits()->getLength()-1)*getBase()->getLength() ==
getValue()->getLength());
}
NTContinuumBuilderPtr NTContinuum::createBuilder()
{
return NTContinuumBuilderPtr(new detail::NTContinuumBuilder());
}
bool NTContinuum::attachTimeStamp(PVTimeStamp &pvTimeStamp) const
{
PVStructurePtr ts = getTimeStamp();
if (ts)
return pvTimeStamp.attach(ts);
else
return false;
}
bool NTContinuum::attachAlarm(PVAlarm &pvAlarm) const
{
PVStructurePtr al = getAlarm();
if (al)
return pvAlarm.attach(al);
else
return false;
}
PVStructurePtr NTContinuum::getPVStructure() const
{
return pvNTContinuum;
}
PVStringPtr NTContinuum::getDescriptor() const
{
return pvNTContinuum->getSubField<PVString>("descriptor");
}
PVStructurePtr NTContinuum::getTimeStamp() const
{
return pvNTContinuum->getSubField<PVStructure>("timeStamp");
}
PVStructurePtr NTContinuum::getAlarm() const
{
return pvNTContinuum->getSubField<PVStructure>("alarm");
}
PVDoubleArrayPtr NTContinuum::getBase() const
{
return pvNTContinuum->getSubField<PVDoubleArray>("base");
}
PVDoubleArrayPtr NTContinuum::getValue() const
{
return pvValue;
}
PVStringArrayPtr NTContinuum::getUnits() const
{
return pvNTContinuum->getSubField<PVStringArray>("units");
}
NTContinuum::NTContinuum(PVStructurePtr const & pvStructure) :
pvNTContinuum(pvStructure),
pvValue(pvNTContinuum->getSubField<PVDoubleArray>("value"))
{}
}}

217
src/ntenum.cpp Normal file
View File

@@ -0,0 +1,217 @@
/* ntenum.cpp */
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#define epicsExportSharedSymbols
#include <pv/ntenum.h>
#include <pv/ntutils.h>
using namespace std;
using namespace epics::pvData;
namespace epics { namespace nt {
static NTFieldPtr ntField = NTField::get();
namespace detail {
StructureConstPtr NTEnumBuilder::createStructure()
{
FieldBuilderPtr builder =
getFieldCreate()->createFieldBuilder()->
setId(NTEnum::URI)->
add("value", ntField->createEnumerated());
if (descriptor)
builder->add("descriptor", pvString);
if (alarm)
builder->add("alarm", ntField->createAlarm());
if (timeStamp)
builder->add("timeStamp", ntField->createTimeStamp());
size_t extraCount = extraFieldNames.size();
for (size_t i = 0; i< extraCount; i++)
builder->add(extraFieldNames[i], extraFields[i]);
StructureConstPtr s = builder->createStructure();
reset();
return s;
}
NTEnumBuilder::shared_pointer NTEnumBuilder::addDescriptor()
{
descriptor = true;
return shared_from_this();
}
NTEnumBuilder::shared_pointer NTEnumBuilder::addAlarm()
{
alarm = true;
return shared_from_this();
}
NTEnumBuilder::shared_pointer NTEnumBuilder::addTimeStamp()
{
timeStamp = true;
return shared_from_this();
}
PVStructurePtr NTEnumBuilder::createPVStructure()
{
return getPVDataCreate()->createPVStructure(createStructure());
}
NTEnumPtr NTEnumBuilder::create()
{
return NTEnumPtr(new NTEnum(createPVStructure()));
}
NTEnumBuilder::NTEnumBuilder()
{
reset();
}
void NTEnumBuilder::reset()
{
descriptor = false;
alarm = false;
timeStamp = false;
extraFieldNames.clear();
extraFields.clear();
}
NTEnumBuilder::shared_pointer NTEnumBuilder::add(string const & name, FieldConstPtr const & field)
{
extraFields.push_back(field); extraFieldNames.push_back(name);
return shared_from_this();
}
}
const std::string NTEnum::URI("epics:nt/NTEnum:1.0");
NTEnum::shared_pointer NTEnum::wrap(PVStructurePtr const & pvStructure)
{
if(!isCompatible(pvStructure)) return shared_pointer();
return wrapUnsafe(pvStructure);
}
NTEnum::shared_pointer NTEnum::wrapUnsafe(PVStructurePtr const & pvStructure)
{
return shared_pointer(new NTEnum(pvStructure));
}
bool NTEnum::is_a(StructureConstPtr const & structure)
{
return NTUtils::is_a(structure->getID(), URI);
}
bool NTEnum::is_a(PVStructurePtr const & pvStructure)
{
return is_a(pvStructure->getStructure());
}
bool NTEnum::isCompatible(StructureConstPtr const &structure)
{
if (structure.get() == 0) return false;
NTFieldPtr ntField = NTField::get();
FieldConstPtr valueField = structure->getField("value");
if (!valueField.get() || !ntField->isEnumerated(valueField))
return false;
FieldConstPtr field = structure->getField("descriptor");
if (field.get())
{
ScalarConstPtr descriptorField = structure->getField<Scalar>("descriptor");
if (!descriptorField.get() || descriptorField->getScalarType() != pvString)
return false;
}
field = structure->getField("alarm");
if (field.get() && !ntField->isAlarm(field))
return false;
field = structure->getField("timeStamp");
if (field.get() && !ntField->isTimeStamp(field))
return false;
return true;
}
bool NTEnum::isCompatible(PVStructurePtr const & pvStructure)
{
if(!pvStructure) return false;
return isCompatible(pvStructure->getStructure());
}
bool NTEnum::isValid()
{
return true;
}
NTEnumBuilderPtr NTEnum::createBuilder()
{
return NTEnumBuilderPtr(new detail::NTEnumBuilder());
}
bool NTEnum::attachTimeStamp(PVTimeStamp &pvTimeStamp) const
{
PVStructurePtr ts = getTimeStamp();
if (ts)
return pvTimeStamp.attach(ts);
else
return false;
}
bool NTEnum::attachAlarm(PVAlarm &pvAlarm) const
{
PVStructurePtr al = getAlarm();
if (al)
return pvAlarm.attach(al);
else
return false;
}
PVStructurePtr NTEnum::getPVStructure() const
{
return pvNTEnum;
}
PVStringPtr NTEnum::getDescriptor() const
{
return pvNTEnum->getSubField<PVString>("descriptor");
}
PVStructurePtr NTEnum::getTimeStamp() const
{
return pvNTEnum->getSubField<PVStructure>("timeStamp");
}
PVStructurePtr NTEnum::getAlarm() const
{
return pvNTEnum->getSubField<PVStructure>("alarm");
}
PVStructurePtr NTEnum::getValue() const
{
return pvValue;
}
NTEnum::NTEnum(PVStructurePtr const & pvStructure) :
pvNTEnum(pvStructure), pvValue(pvNTEnum->getSubField<PVStructure>("value"))
{}
}}

View File

@@ -1,8 +1,7 @@
/* ntfield.cpp */
/**
* Copyright - See the COPYRIGHT that is included with this distribution.
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#include <pv/lock.h>

242
src/nthistogram.cpp Normal file
View File

@@ -0,0 +1,242 @@
/* ntcontinuum.cpp */
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#define epicsExportSharedSymbols
#include <pv/nthistogram.h>
#include <pv/ntutils.h>
using namespace std;
using namespace epics::pvData;
namespace epics { namespace nt {
static NTFieldPtr ntField = NTField::get();
namespace detail {
NTHistogramBuilder::shared_pointer NTHistogramBuilder::value(
epics::pvData::ScalarType scalarType
)
{
valueType = scalarType;
valueTypeSet = true;
return shared_from_this();
}
StructureConstPtr NTHistogramBuilder::createStructure()
{
if (!valueTypeSet)
throw std::runtime_error("value array element type not set");
FieldBuilderPtr builder =
getFieldCreate()->createFieldBuilder()->
setId(NTHistogram::URI)->
addArray("ranges", pvDouble)->
addArray("value", valueType);
if (descriptor)
builder->add("descriptor", pvString);
if (alarm)
builder->add("alarm", ntField->createAlarm());
if (timeStamp)
builder->add("timeStamp", ntField->createTimeStamp());
size_t extraCount = extraFieldNames.size();
for (size_t i = 0; i< extraCount; i++)
builder->add(extraFieldNames[i], extraFields[i]);
StructureConstPtr s = builder->createStructure();
reset();
return s;
}
NTHistogramBuilder::shared_pointer NTHistogramBuilder::addDescriptor()
{
descriptor = true;
return shared_from_this();
}
NTHistogramBuilder::shared_pointer NTHistogramBuilder::addAlarm()
{
alarm = true;
return shared_from_this();
}
NTHistogramBuilder::shared_pointer NTHistogramBuilder::addTimeStamp()
{
timeStamp = true;
return shared_from_this();
}
PVStructurePtr NTHistogramBuilder::createPVStructure()
{
return getPVDataCreate()->createPVStructure(createStructure());
}
NTHistogramPtr NTHistogramBuilder::create()
{
return NTHistogramPtr(new NTHistogram(createPVStructure()));
}
NTHistogramBuilder::NTHistogramBuilder()
{
reset();
}
void NTHistogramBuilder::reset()
{
valueTypeSet = false;
descriptor = false;
alarm = false;
timeStamp = false;
extraFieldNames.clear();
extraFields.clear();
}
NTHistogramBuilder::shared_pointer NTHistogramBuilder::add(string const & name, FieldConstPtr const & field)
{
extraFields.push_back(field); extraFieldNames.push_back(name);
return shared_from_this();
}
}
const std::string NTHistogram::URI("epics:nt/NTHistogram:1.0");
NTHistogram::shared_pointer NTHistogram::wrap(PVStructurePtr const & pvStructure)
{
if(!isCompatible(pvStructure)) return shared_pointer();
return wrapUnsafe(pvStructure);
}
NTHistogram::shared_pointer NTHistogram::wrapUnsafe(PVStructurePtr const & pvStructure)
{
return shared_pointer(new NTHistogram(pvStructure));
}
bool NTHistogram::is_a(StructureConstPtr const & structure)
{
return NTUtils::is_a(structure->getID(), URI);
}
bool NTHistogram::is_a(PVStructurePtr const & pvStructure)
{
return is_a(pvStructure->getStructure());
}
bool NTHistogram::isCompatible(StructureConstPtr const &structure)
{
if(!structure.get()) return false;
ScalarArrayConstPtr rangesField = structure->getField<ScalarArray>("ranges");
if(!rangesField.get() || rangesField->getElementType() != pvDouble) return false;
ScalarArrayConstPtr valueField = structure->getField<ScalarArray>("value");
if(!valueField.get()) return false;
ScalarType scalarType = valueField->getElementType();
if (scalarType != pvShort &&
scalarType != pvInt &&
scalarType != pvLong)
return false;
FieldConstPtr field = structure->getField("descriptor");
if(field)
{
ScalarConstPtr descriptorField = structure->getField<Scalar>("descriptor");
if (!descriptorField.get() || descriptorField->getScalarType() != pvString)
return false;
}
field = structure->getField("alarm");
if (field.get() && !ntField->isAlarm(field))
return false;
field = structure->getField("timeStamp");
if (field.get() && !ntField->isTimeStamp(field))
return false;
return true;
}
bool NTHistogram::isCompatible(PVStructurePtr const & pvStructure)
{
if(!pvStructure.get()) return false;
return isCompatible(pvStructure->getStructure());
}
bool NTHistogram::isValid()
{
return (getValue()->getLength()+1 == getRanges()->getLength());
}
NTHistogramBuilderPtr NTHistogram::createBuilder()
{
return NTHistogramBuilderPtr(new detail::NTHistogramBuilder());
}
bool NTHistogram::attachTimeStamp(PVTimeStamp &pvTimeStamp) const
{
PVStructurePtr ts = getTimeStamp();
if (ts)
return pvTimeStamp.attach(ts);
else
return false;
}
bool NTHistogram::attachAlarm(PVAlarm &pvAlarm) const
{
PVStructurePtr al = getAlarm();
if (al)
return pvAlarm.attach(al);
else
return false;
}
PVStructurePtr NTHistogram::getPVStructure() const
{
return pvNTHistogram;
}
PVStringPtr NTHistogram::getDescriptor() const
{
return pvNTHistogram->getSubField<PVString>("descriptor");
}
PVStructurePtr NTHistogram::getTimeStamp() const
{
return pvNTHistogram->getSubField<PVStructure>("timeStamp");
}
PVStructurePtr NTHistogram::getAlarm() const
{
return pvNTHistogram->getSubField<PVStructure>("alarm");
}
PVDoubleArrayPtr NTHistogram::getRanges() const
{
return pvNTHistogram->getSubField<PVDoubleArray>("ranges");
}
PVScalarArrayPtr NTHistogram::getValue() const
{
return pvValue;
}
NTHistogram::NTHistogram(PVStructurePtr const & pvStructure) :
pvNTHistogram(pvStructure),
pvValue(pvNTHistogram->getSubField<PVScalarArray>("value"))
{}
}}

190
src/ntid.cpp Normal file
View File

@@ -0,0 +1,190 @@
/* ntid.cpp */
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#include <pv/ntid.h>
#include <pv/typeCast.h>
namespace epics {
namespace nt {
const static std::string BAD_NAME = "?";
NTID::NTID(const std::string & id)
: fullName(id),
qualifiedName(BAD_NAME),
namespaceStr(BAD_NAME),
name(BAD_NAME),
version(BAD_NAME),
nsSepIndex(std::string::npos),
versionSepIndex(std::string::npos),
nsQualified(false),
hasVersion(false),
endMajorIndex(0),
majorVersionStr(BAD_NAME),
majorVersionParsed(false),
hasMajor(false),
majorVersion(0),
endMinorIndex(0),
minorVersionStr(BAD_NAME),
minorVersionParsed(false),
hasMinor(false),
minorVersion(0)
{
nsSepIndex = id.find('/');
nsQualified = nsSepIndex != std::string::npos;
size_t startIndex = nsQualified ? nsSepIndex+1 : 0;
versionSepIndex = id.find(':', startIndex);
hasVersion = versionSepIndex != std::string::npos;
}
std::string NTID::getFullName() { return fullName; }
std::string NTID::getQualifiedName()
{
if (qualifiedName == BAD_NAME)
{
qualifiedName = hasVersion ?
fullName.substr(0, versionSepIndex) : fullName;
}
return qualifiedName;
}
std::string NTID::getNamespace()
{
if (namespaceStr == BAD_NAME)
{
namespaceStr = nsQualified ?
fullName.substr(0, nsSepIndex) : "";
}
return namespaceStr;
}
std::string NTID::getName()
{
if (name == BAD_NAME)
{
if (hasVersion)
{
size_t startIndex = nsQualified ? nsSepIndex+1 : 0;
name = fullName.substr(startIndex, versionSepIndex);
}
else if (nsQualified)
{
name = fullName.substr(nsSepIndex+1);
}
else
{
name = fullName;
}
}
return name;
}
std::string NTID::getVersion()
{
if (version == BAD_NAME)
{
version = (hasVersion) ? fullName.substr(versionSepIndex+1) : "";
}
return version;
}
std::string NTID::getMajorVersionString()
{
if (majorVersionStr == BAD_NAME)
{
if (hasVersion)
{
endMajorIndex = fullName.find('.', versionSepIndex+1);
majorVersionStr = (endMajorIndex != std::string::npos)
? fullName.substr(versionSepIndex+1, endMajorIndex-(versionSepIndex+1)) :
fullName.substr(versionSepIndex+1);
}
else
majorVersionStr = "";
}
return majorVersionStr;
}
bool NTID::hasMajorVersion()
{
if (hasVersion && !majorVersionParsed)
{
try {
using pvData::detail::parseToPOD;
uint32_t mv;
parseToPOD(getMajorVersionString(), &mv);
majorVersion = static_cast<int>(mv);
hasMajor = true;
} catch (...) {}
majorVersionParsed = true;
}
return hasMajor;
}
int NTID::getMajorVersion()
{
// call hasMajorVersion() to calculate values
hasMajorVersion();
return majorVersion;
}
std::string NTID::getMinorVersionString()
{
// call hasMinorVersion() to calculate start of minor
getMajorVersionString();
if (minorVersionStr == BAD_NAME)
{
if (hasVersion && endMajorIndex != std::string::npos)
{
endMinorIndex = fullName.find('.', endMajorIndex+1);
minorVersionStr = (endMinorIndex != std::string::npos)
? fullName.substr(endMajorIndex+1, endMinorIndex-(endMajorIndex+1)) :
fullName.substr(endMajorIndex+1);
}
else
minorVersionStr = "";
}
return minorVersionStr;
}
bool NTID::hasMinorVersion()
{
if (hasVersion && !minorVersionParsed)
{
try {
using pvData::detail::parseToPOD;
uint32_t mv;
parseToPOD(getMinorVersionString(), &mv);
minorVersion = static_cast<int>(mv);
hasMinor = true;
} catch (...) {}
minorVersionParsed = true;
}
return hasMinor;
}
int NTID::getMinorVersion()
{
// call hasMinorVersion() to calculate values
hasMinorVersion();
return minorVersion;
}
}}

287
src/ntmatrix.cpp Normal file
View File

@@ -0,0 +1,287 @@
/* ntmatrix.cpp */
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#define epicsExportSharedSymbols
#include <pv/ntmatrix.h>
#include <pv/ntutils.h>
using namespace std;
using namespace epics::pvData;
namespace epics { namespace nt {
static NTFieldPtr ntField = NTField::get();
namespace detail {
StructureConstPtr NTMatrixBuilder::createStructure()
{
FieldBuilderPtr builder =
getFieldCreate()->createFieldBuilder()->
setId(NTMatrix::URI)->
addArray("value", pvDouble);
if (dim)
builder->addArray("dim", pvInt);
if (descriptor)
builder->add("descriptor", pvString);
if (alarm)
builder->add("alarm", ntField->createAlarm());
if (timeStamp)
builder->add("timeStamp", ntField->createTimeStamp());
if (display)
builder->add("display", ntField->createDisplay());
size_t extraCount = extraFieldNames.size();
for (size_t i = 0; i< extraCount; i++)
builder->add(extraFieldNames[i], extraFields[i]);
StructureConstPtr s = builder->createStructure();
reset();
return s;
}
NTMatrixBuilder::shared_pointer NTMatrixBuilder::addDim()
{
dim = true;
return shared_from_this();
}
NTMatrixBuilder::shared_pointer NTMatrixBuilder::addDescriptor()
{
descriptor = true;
return shared_from_this();
}
NTMatrixBuilder::shared_pointer NTMatrixBuilder::addAlarm()
{
alarm = true;
return shared_from_this();
}
NTMatrixBuilder::shared_pointer NTMatrixBuilder::addTimeStamp()
{
timeStamp = true;
return shared_from_this();
}
NTMatrixBuilder::shared_pointer NTMatrixBuilder::addDisplay()
{
display = true;
return shared_from_this();
}
PVStructurePtr NTMatrixBuilder::createPVStructure()
{
return getPVDataCreate()->createPVStructure(createStructure());
}
NTMatrixPtr NTMatrixBuilder::create()
{
return NTMatrixPtr(new NTMatrix(createPVStructure()));
}
NTMatrixBuilder::NTMatrixBuilder()
{
reset();
}
void NTMatrixBuilder::reset()
{
dim = false;
descriptor = false;
alarm = false;
timeStamp = false;
display = false;
extraFieldNames.clear();
extraFields.clear();
}
NTMatrixBuilder::shared_pointer NTMatrixBuilder::add(string const & name, FieldConstPtr const & field)
{
extraFields.push_back(field); extraFieldNames.push_back(name);
return shared_from_this();
}
}
const std::string NTMatrix::URI("epics:nt/NTMatrix:1.0");
NTMatrix::shared_pointer NTMatrix::wrap(PVStructurePtr const & pvStructure)
{
if(!isCompatible(pvStructure)) return shared_pointer();
return wrapUnsafe(pvStructure);
}
NTMatrix::shared_pointer NTMatrix::wrapUnsafe(PVStructurePtr const & pvStructure)
{
return shared_pointer(new NTMatrix(pvStructure));
}
bool NTMatrix::is_a(StructureConstPtr const & structure)
{
return NTUtils::is_a(structure->getID(), URI);
}
bool NTMatrix::is_a(PVStructurePtr const & pvStructure)
{
return is_a(pvStructure->getStructure());
}
bool NTMatrix::isCompatible(StructureConstPtr const & structure)
{
if (structure.get() == 0) return false;
ScalarArrayConstPtr valueField = structure->getField<ScalarArray>("value");
if (valueField.get() == 0 || valueField->getElementType() != pvDouble)
return false;
FieldConstPtr field = structure->getField("dim");
if (field.get())
{
ScalarArrayConstPtr dimField = structure->getField<ScalarArray>("dim");
if (dimField.get() == 0 || dimField->getElementType() != pvInt)
return false;
}
field = structure->getField("descriptor");
if (field.get())
{
ScalarConstPtr descriptorField = structure->getField<Scalar>("descriptor");
if (!descriptorField.get() || descriptorField->getScalarType() != pvString)
return false;
}
NTFieldPtr ntField = NTField::get();
field = structure->getField("alarm");
if (field.get() && !ntField->isAlarm(field))
return false;
field = structure->getField("timeStamp");
if (field.get() && !ntField->isTimeStamp(field))
return false;
field = structure->getField("display");
if (field.get() && !ntField->isDisplay(field))
return false;
return true;
}
bool NTMatrix::isCompatible(PVStructurePtr const & pvStructure)
{
if(!pvStructure) return false;
return isCompatible(pvStructure->getStructure());
}
bool NTMatrix::isValid()
{
int valueLength = getValue()->getLength();
if (valueLength == 0)
return false;
PVIntArrayPtr pvDim = getDim();
if (pvDim.get())
{
int length = pvDim->getLength();
if (length != 1 && length !=2)
return false;
PVIntArray::const_svector data = pvDim->view();
int expectedLength = 1;
for (PVIntArray::const_svector::const_iterator it = data.begin();
it != data.end(); ++it)
{
expectedLength *= *it;
}
if (expectedLength != valueLength)
return false;
}
return true;
}
NTMatrixBuilderPtr NTMatrix::createBuilder()
{
return NTMatrixBuilderPtr(new detail::NTMatrixBuilder());
}
bool NTMatrix::attachTimeStamp(PVTimeStamp &pvTimeStamp) const
{
PVStructurePtr ts = getTimeStamp();
if (ts)
return pvTimeStamp.attach(ts);
else
return false;
}
bool NTMatrix::attachAlarm(PVAlarm &pvAlarm) const
{
PVStructurePtr al = getAlarm();
if (al)
return pvAlarm.attach(al);
else
return false;
}
bool NTMatrix::attachDisplay(PVDisplay &pvDisplay) const
{
PVStructurePtr dp = getDisplay();
if (dp)
return pvDisplay.attach(dp);
else
return false;
}
PVStructurePtr NTMatrix::getPVStructure() const
{
return pvNTMatrix;
}
PVStringPtr NTMatrix::getDescriptor() const
{
return pvNTMatrix->getSubField<PVString>("descriptor");
}
PVStructurePtr NTMatrix::getTimeStamp() const
{
return pvNTMatrix->getSubField<PVStructure>("timeStamp");
}
PVStructurePtr NTMatrix::getAlarm() const
{
return pvNTMatrix->getSubField<PVStructure>("alarm");
}
PVStructurePtr NTMatrix::getDisplay() const
{
return pvNTMatrix->getSubField<PVStructure>("display");
}
PVDoubleArrayPtr NTMatrix::getValue() const
{
return pvValue;
}
PVIntArrayPtr NTMatrix::getDim() const
{
return pvNTMatrix->getSubField<PVIntArray>("dim");
}
NTMatrix::NTMatrix(PVStructurePtr const & pvStructure) :
pvNTMatrix(pvStructure),
pvValue(pvNTMatrix->getSubField<PVDoubleArray>("value"))
{}
}}

View File

@@ -1,8 +1,7 @@
/* ntmultiChannel.cpp */
/**
* Copyright - See the COPYRIGHT that is included with this distribution.
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#include <algorithm>
@@ -84,10 +83,16 @@ NTMultiChannelBuilder::shared_pointer NTMultiChannelBuilder::addUserTag()
return shared_from_this();
}
NTMultiChannelBuilder::shared_pointer NTMultiChannelBuilder::addIsConnected()
{
isConnected = true;
return shared_from_this();
}
StructureConstPtr NTMultiChannelBuilder::createStructure()
{
StandardFieldPtr standardField = getStandardField();
size_t nfields = 3;
size_t nfields = 2;
size_t extraCount = extraFieldNames.size();
nfields += extraCount;
if(descriptor) ++nfields;
@@ -99,6 +104,7 @@ StructureConstPtr NTMultiChannelBuilder::createStructure()
if(secondsPastEpoch) ++nfields;
if(nanoseconds) ++nfields;
if(userTag) ++nfields;
if(isConnected) ++nfields;
FieldConstPtrArray fields(nfields);
StringArray names(nfields);
size_t ind = 0;
@@ -110,19 +116,17 @@ StructureConstPtr NTMultiChannelBuilder::createStructure()
}
names[ind] = "channelName";
fields[ind++] = fieldCreate->createScalarArray(pvString);
names[ind] = "isConnected";
fields[ind++] = fieldCreate->createScalarArray(pvBoolean);
if(timeStamp) {
names[ind] = "timeStamp";
fields[ind++] = standardField->timeStamp();
if(descriptor) {
names[ind] = "descriptor";
fields[ind++] = fieldCreate->createScalar(pvString);
}
if(alarm) {
names[ind] = "alarm";
fields[ind++] = standardField->alarm();
}
if(descriptor) {
names[ind] = "descriptor";
fields[ind++] = fieldCreate->createScalar(pvString);
if(timeStamp) {
names[ind] = "timeStamp";
fields[ind++] = standardField->timeStamp();
}
if(severity) {
names[ind] = "severity";
@@ -148,6 +152,10 @@ StructureConstPtr NTMultiChannelBuilder::createStructure()
names[ind] = "userTag";
fields[ind++] = fieldCreate->createScalarArray(pvInt);
}
if(isConnected) {
names[ind] = "isConnected";
fields[ind++] = fieldCreate->createScalarArray(pvBoolean);
}
for (size_t i = 0; i< extraCount; i++) {
names[ind] = extraFieldNames[i];
fields[ind++] = extraFields[i];
@@ -187,6 +195,7 @@ void NTMultiChannelBuilder::reset()
secondsPastEpoch = false;
nanoseconds = false;
userTag = false;
isConnected = false;
}
@@ -200,15 +209,15 @@ NTMultiChannelBuilder::shared_pointer NTMultiChannelBuilder::add(string const &
const std::string NTMultiChannel::URI("epics:nt/NTMultiChannel:1.0");
NTMultiChannel::shared_pointer NTMultiChannel::wrap(PVStructurePtr const & structure)
NTMultiChannel::shared_pointer NTMultiChannel::wrap(PVStructurePtr const & pvStructure)
{
if(!isCompatible(structure)) return shared_pointer();
return wrapUnsafe(structure);
if(!isCompatible(pvStructure)) return shared_pointer();
return wrapUnsafe(pvStructure);
}
NTMultiChannel::shared_pointer NTMultiChannel::wrapUnsafe(PVStructurePtr const & structure)
NTMultiChannel::shared_pointer NTMultiChannel::wrapUnsafe(PVStructurePtr const & pvStructure)
{
return shared_pointer(new NTMultiChannel(structure));
return shared_pointer(new NTMultiChannel(pvStructure));
}
bool NTMultiChannel::is_a(StructureConstPtr const &structure)
@@ -216,38 +225,128 @@ bool NTMultiChannel::is_a(StructureConstPtr const &structure)
return NTUtils::is_a(structure->getID(), URI);
}
bool NTMultiChannel::isCompatible(PVStructurePtr const &pvStructure)
bool NTMultiChannel::is_a(PVStructurePtr const & pvStructure)
{
if(!pvStructure) return false;
PVUnionArrayPtr pvValue = pvStructure->getSubField<PVUnionArray>("value");
if(!pvValue) return false;
PVFieldPtr pvField = pvStructure->getSubField("descriptor");
if(pvField && !pvStructure->getSubField<PVString>("descriptor")) return false;
pvField = pvStructure->getSubField("alarm");
if(pvField && !ntField->isAlarm(pvField->getField())) return false;
pvField = pvStructure->getSubField("timeStamp");
if(pvField && !ntField->isTimeStamp(pvField->getField())) return false;
pvField = pvStructure->getSubField("severity");
if(pvField && !pvStructure->getSubField<PVIntArray>("severity")) return false;
pvField = pvStructure->getSubField("status");
if(pvField && !pvStructure->getSubField<PVIntArray>("status")) return false;
pvField = pvStructure->getSubField("message");
if(pvField && !pvStructure->getSubField<PVStringArray>("message")) return false;
pvField = pvStructure->getSubField("secondsPastEpoch");
if(pvField && !pvStructure->getSubField<PVLongArray>("secondsPastEpoch")) return false;
pvField = pvStructure->getSubField("nanoseconds");
if(pvField && !pvStructure->getSubField<PVIntArray>("nanoseconds")) return false;
pvField = pvStructure->getSubField("userTag");
if(pvField && !pvStructure->getSubField<PVIntArray>("userTag")) return false;
return is_a(pvStructure->getStructure());
}
bool NTMultiChannel::isCompatible(StructureConstPtr const & structure)
{
if (!structure.get()) return false;
UnionArrayConstPtr valueField = structure->getField<UnionArray>("value");
if (!valueField.get()) return false;
ScalarArrayConstPtr channelNameField = structure->getField<ScalarArray>(
"channelName");
if (!channelNameField.get()) return false;
if (channelNameField->getElementType() != pvString) return false;
FieldConstPtr field = structure->getField("severity");
if (field.get())
{
ScalarArrayConstPtr severityField = structure->getField<ScalarArray>("severity");
if (!severityField.get() || severityField->getElementType() != pvInt)
return false;
}
field = structure->getField("status");
if (field.get())
{
ScalarArrayConstPtr statusField = structure->getField<ScalarArray>("status");
if (!statusField.get() || statusField->getElementType() != pvInt)
return false;
}
field = structure->getField("message");
if (field.get())
{
ScalarArrayConstPtr messageField = structure->getField<ScalarArray>("message");
if (!messageField.get() || messageField->getElementType() != pvString)
return false;
}
field = structure->getField("secondsPastEpoch");
if (field.get())
{
ScalarArrayConstPtr secondsPastEpochField = structure->getField<ScalarArray>("secondsPastEpoch");
if (!secondsPastEpochField.get() || secondsPastEpochField->getElementType() != pvLong)
return false;
}
field = structure->getField("nanoseconds");
if (field.get())
{
ScalarArrayConstPtr nanosecondsField = structure->getField<ScalarArray>("nanoseconds");
if (!nanosecondsField.get() || nanosecondsField->getElementType() != pvInt)
return false;
}
field = structure->getField("userTag");
if (field.get())
{
ScalarArrayConstPtr userTagField = structure->getField<ScalarArray>("userTag");
if (!userTagField.get() || userTagField->getElementType() != pvInt)
return false;
}
field = structure->getField("descriptor");
if (field.get())
{
ScalarConstPtr descriptorField = structure->getField<Scalar>("descriptor");
if (!descriptorField.get() || descriptorField->getScalarType() != pvString)
return false;
}
NTFieldPtr ntField = NTField::get();
field = structure->getField("alarm");
if (field.get() && !ntField->isAlarm(field))
return false;
field = structure->getField("timeStamp");
if (field.get() && !ntField->isTimeStamp(field))
return false;
return true;
}
bool NTMultiChannel::isCompatible(PVStructurePtr const &pvStructure)
{
if(!pvStructure.get()) return false;
return isCompatible(pvStructure->getStructure());
}
bool NTMultiChannel::isValid()
{
size_t valueLength = getValue()->getLength();
if (getChannelName()->getLength() != valueLength) return false;
PVScalarArrayPtr arrayFields[] = {
getSeverity(), getStatus(), getMessage(),
getSecondsPastEpoch(), getNanoseconds(), getUserTag()
};
size_t N = sizeof(arrayFields)/sizeof(arrayFields[0]);
PVScalarArrayPtr arrayField;
for (PVScalarArrayPtr * pa = arrayFields; pa != arrayFields+N; ++pa)
{
arrayField = *pa;
if (arrayField.get() && arrayField->getLength() != valueLength)
return false;
}
return true;
}
NTMultiChannelBuilderPtr NTMultiChannel::createBuilder()
{
return NTMultiChannelBuilderPtr(new detail::NTMultiChannelBuilder());
}
NTMultiChannel::NTMultiChannel(PVStructurePtr const & pvStructure)
: pvNTMultiChannel(pvStructure),
pvTimeStamp(pvStructure->getSubField<PVStructure>("timeStamp")),
@@ -266,16 +365,20 @@ NTMultiChannel::NTMultiChannel(PVStructurePtr const & pvStructure)
}
void NTMultiChannel::attachTimeStamp(PVTimeStamp &pv) const
bool NTMultiChannel::attachTimeStamp(PVTimeStamp &pv) const
{
if(!pvTimeStamp) return;
pv.attach(pvTimeStamp);
if (pvTimeStamp)
return pv.attach(pvTimeStamp);
else
return false;
}
void NTMultiChannel::attachAlarm(PVAlarm &pv) const
bool NTMultiChannel::attachAlarm(PVAlarm &pv) const
{
if(!pvAlarm) return;
pv.attach(pvAlarm);
if (pvAlarm)
return pv.attach(pvAlarm);
else
return false;
}
}}

View File

@@ -1,8 +1,7 @@
/* ntnameValue.cpp */
/**
* Copyright - See the COPYRIGHT that is included with this distribution.
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#define epicsExportSharedSymbols
@@ -112,10 +111,10 @@ NTNameValueBuilder::shared_pointer NTNameValueBuilder::add(string const & name,
const std::string NTNameValue::URI("epics:nt/NTNameValue:1.0");
NTNameValue::shared_pointer NTNameValue::wrap(PVStructurePtr const & structure)
NTNameValue::shared_pointer NTNameValue::wrap(PVStructurePtr const & pvStructure)
{
if(!isCompatible(structure)) return shared_pointer();
return wrapUnsafe(structure);
if(!isCompatible(pvStructure)) return shared_pointer();
return wrapUnsafe(pvStructure);
}
NTNameValue::shared_pointer NTNameValue::wrapUnsafe(PVStructurePtr const & structure)
@@ -128,20 +127,54 @@ bool NTNameValue::is_a(StructureConstPtr const & structure)
return NTUtils::is_a(structure->getID(), URI);
}
bool NTNameValue::is_a(PVStructurePtr const & pvStructure)
{
return is_a(pvStructure->getStructure());
}
bool NTNameValue::isCompatible(StructureConstPtr const & structure)
{
if (structure.get() == 0) return false;
ScalarArrayConstPtr nameField = structure->getField<ScalarArray>("name");
if (nameField.get() == 0 || nameField->getElementType() != pvString)
return false;
ScalarArrayConstPtr valueField = structure->getField<ScalarArray>("value");
if (valueField.get() == 0)
return false;
FieldConstPtr field = structure->getField("descriptor");
if (field.get())
{
ScalarConstPtr descriptorField = structure->getField<Scalar>("descriptor");
if (!descriptorField || descriptorField->getScalarType() != pvString)
return false;
}
NTFieldPtr ntField = NTField::get();
field = structure->getField("alarm");
if (field && !ntField->isAlarm(field))
return false;
field = structure->getField("timeStamp");
if (field && !ntField->isTimeStamp(field))
return false;
return true;
}
bool NTNameValue::isCompatible(PVStructurePtr const & pvStructure)
{
if(!pvStructure) return false;
PVStringArrayPtr pvName = pvStructure->getSubField<PVStringArray>("name");
if(!pvName) return false;
PVFieldPtr pvValue = pvStructure->getSubField("value");
if(!pvValue) return false;
PVFieldPtr pvField = pvStructure->getSubField("descriptor");
if(pvField && !pvStructure->getSubField<PVString>("descriptor")) return false;
pvField = pvStructure->getSubField("alarm");
if(pvField && !ntField->isAlarm(pvField->getField())) return false;
pvField = pvStructure->getSubField("timeStamp");
if(pvField && !ntField->isTimeStamp(pvField->getField())) return false;
return true;
return isCompatible(pvStructure->getStructure());
}
bool NTNameValue::isValid()
{
return (getValue<PVScalarArray>()->getLength() == getName()->getLength());
}
NTNameValueBuilderPtr NTNameValue::createBuilder()

595
src/ntndarray.cpp Normal file
View File

@@ -0,0 +1,595 @@
/* ntndarray.cpp */
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#include <algorithm>
#include <pv/lock.h>
#define epicsExportSharedSymbols
#include <pv/ntndarray.h>
#include <pv/ntndarrayAttribute.h>
#include <pv/ntutils.h>
using namespace std;
using namespace epics::pvData;
namespace epics { namespace nt {
static NTFieldPtr ntField = NTField::get();
namespace detail {
static FieldCreatePtr fieldCreate = getFieldCreate();
static PVDataCreatePtr pvDataCreate = getPVDataCreate();
static Mutex mutex;
StructureConstPtr NTNDArrayBuilder::createStructure()
{
enum
{
DISCRIPTOR_INDEX,
TIMESTAMP_INDEX,
ALARM_INDEX,
DISPLAY_INDEX
};
const size_t NUMBER_OF_INDICES = DISPLAY_INDEX+1;
const size_t NUMBER_OF_STRUCTURES = 1 << NUMBER_OF_INDICES;
Lock xx(mutex);
static StructureConstPtr ntndarrayStruc[NUMBER_OF_STRUCTURES];
static UnionConstPtr valueType;
static StructureConstPtr codecStruc;
static StructureConstPtr dimensionStruc;
static StructureConstPtr attributeStruc;
StructureConstPtr returnedStruc;
size_t index = 0;
if (descriptor) index |= 1 << DISCRIPTOR_INDEX;
if (timeStamp) index |= 1 << TIMESTAMP_INDEX;
if (alarm) index |= 1 << ALARM_INDEX;
if (display) index |= 1 << DISPLAY_INDEX;
bool isExtended = !extraFieldNames.empty();
if (isExtended || !ntndarrayStruc[index])
{
StandardFieldPtr standardField = getStandardField();
FieldBuilderPtr fb = fieldCreate->createFieldBuilder();
if (!valueType)
{
for (int i = pvBoolean; i < pvString; ++i)
{
ScalarType st = static_cast<ScalarType>(i);
fb->addArray(std::string(ScalarTypeFunc::name(st)) + "Value", st);
}
valueType = fb->createUnion();
}
if (!codecStruc)
{
codecStruc = fb->setId("codec_t")->
add("name", pvString)->
add("parameters", fieldCreate->createVariantUnion())->
createStructure();
}
if (!dimensionStruc)
{
dimensionStruc = fb->setId("dimension_t")->
add("size", pvInt)->
add("offset", pvInt)->
add("fullSize", pvInt)->
add("binning", pvInt)->
add("reverse", pvBoolean)->
createStructure();
}
if (!attributeStruc)
{
attributeStruc = NTNDArrayAttribute::createBuilder()->createStructure();
}
fb->setId(NTNDArray::URI)->
add("value", valueType)->
add("codec", codecStruc)->
add("compressedSize", pvLong)->
add("uncompressedSize", pvLong)->
addArray("dimension", dimensionStruc)->
add("uniqueId", pvInt)->
add("dataTimeStamp", standardField->timeStamp())->
addArray("attribute", attributeStruc);
if (descriptor)
fb->add("descriptor", pvString);
if (alarm)
fb->add("alarm", standardField->alarm());
if (timeStamp)
fb->add("timeStamp", standardField->timeStamp());
if (display)
fb->add("display", standardField->display());
size_t extraCount = extraFieldNames.size();
for (size_t i = 0; i< extraCount; i++)
fb->add(extraFieldNames[i], extraFields[i]);
returnedStruc = fb->createStructure();
if (!isExtended)
ntndarrayStruc[index] = returnedStruc;
}
else
{
return ntndarrayStruc[index];
}
return returnedStruc;
}
NTNDArrayBuilder::shared_pointer NTNDArrayBuilder::addDescriptor()
{
descriptor = true;
return shared_from_this();
}
NTNDArrayBuilder::shared_pointer NTNDArrayBuilder::addAlarm()
{
alarm = true;
return shared_from_this();
}
NTNDArrayBuilder::shared_pointer NTNDArrayBuilder::addTimeStamp()
{
timeStamp = true;
return shared_from_this();
}
NTNDArrayBuilder::shared_pointer NTNDArrayBuilder::addDisplay()
{
display = true;
return shared_from_this();
}
PVStructurePtr NTNDArrayBuilder::createPVStructure()
{
return getPVDataCreate()->createPVStructure(createStructure());
}
NTNDArrayPtr NTNDArrayBuilder::create()
{
return NTNDArrayPtr(new NTNDArray(createPVStructure()));
}
NTNDArrayBuilder::NTNDArrayBuilder()
{
reset();
}
void NTNDArrayBuilder::reset()
{
descriptor = false;
timeStamp = false;
alarm = false;
display = false;
extraFieldNames.clear();
extraFields.clear();
}
NTNDArrayBuilder::shared_pointer NTNDArrayBuilder::add(string const & name, FieldConstPtr const & field)
{
extraFields.push_back(field); extraFieldNames.push_back(name);
return shared_from_this();
}
}
const std::string NTNDArray::URI("epics:nt/NTNDArray:1.0");
const std::string ntAttrStr("epics:nt/NTAttribute:1.0");
static FieldCreatePtr fieldCreate = getFieldCreate();
static PVDataCreatePtr pvDataCreate = getPVDataCreate();
class NTValueType
{
public:
static bool isCompatible(UnionConstPtr const &u)
{
if(!u.get()) return false;
if (u->getID() != Union::defaultId()) return false;
if (u->isVariant()) return false;
for (int i = pvBoolean; i != pvString; ++i)
{
ScalarType scalarType = static_cast<ScalarType>(i);
std::string name(ScalarTypeFunc::name(scalarType));
name += "Value";
ScalarArrayConstPtr scalarField = u->getField<ScalarArray>(name);
if (scalarField.get() == 0 ||
scalarField->getElementType() != scalarType)
return false;
}
return true;
}
};
class NTCodec
{
public:
static bool isCompatible(StructureConstPtr const &structure)
{
if(!structure.get()) return false;
if (structure->getID() != "codec_t") return false;
ScalarConstPtr scalarField = structure->getField<Scalar>("name");
if (scalarField.get() == 0 || scalarField->getScalarType() != pvString)
return false;
UnionConstPtr paramField = structure->getField<Union>("parameters");
if (paramField.get() == 0 || !paramField->isVariant())
return false;
return true;
}
};
class NTDimension
{
public:
static bool isCompatible(StructureConstPtr const &structure)
{
if(!structure.get()) return false;
if (structure->getID() != "dimension_t") return false;
ScalarConstPtr scalarField = structure->getField<Scalar>("size");
if (scalarField.get() == 0 || scalarField->getScalarType() != pvInt)
return false;
scalarField = structure->getField<Scalar>("offset");
if (scalarField.get() == 0 || scalarField->getScalarType() != pvInt)
return false;
scalarField = structure->getField<Scalar>("fullSize");
if (scalarField.get() == 0 || scalarField->getScalarType() != pvInt)
return false;
scalarField = structure->getField<Scalar>("binning");
if (scalarField.get() == 0 || scalarField->getScalarType() != pvInt)
return false;
scalarField = structure->getField<Scalar>("reverse");
if (scalarField.get() == 0 || scalarField->getScalarType() != pvBoolean)
return false;
return true;
}
};
NTNDArray::shared_pointer NTNDArray::wrap(PVStructurePtr const & pvStructure)
{
if(!isCompatible(pvStructure)) return shared_pointer();
return wrapUnsafe(pvStructure);
}
NTNDArray::shared_pointer NTNDArray::wrapUnsafe(PVStructurePtr const & pvStructure)
{
return shared_pointer(new NTNDArray(pvStructure));
}
bool NTNDArray::is_a(StructureConstPtr const & structure)
{
return NTUtils::is_a(structure->getID(), URI);
}
bool NTNDArray::is_a(PVStructurePtr const & pvStructure)
{
return is_a(pvStructure->getStructure());
}
bool NTNDArray::isCompatible(StructureConstPtr const &structure)
{
if(!structure.get()) return false;
UnionConstPtr valueField = structure->getField<Union>("value");
if(!NTValueType::isCompatible(valueField)) return false;
StructureConstPtr codecField = structure->getField<Structure>("codec");
if(!NTCodec::isCompatible(codecField)) return false;
ScalarConstPtr compressedSizeField = structure->getField<Scalar>("compressedSize");
if (compressedSizeField.get() == 0)
return false;
if (compressedSizeField->getScalarType() != pvLong)
return false;
ScalarConstPtr uncompressedSizeField = structure->getField<Scalar>("uncompressedSize");
if (uncompressedSizeField.get() == 0)
return false;
if (uncompressedSizeField->getScalarType() != pvLong)
return false;
StructureArrayConstPtr dimensionField = structure->getField<StructureArray>("dimension");
if (dimensionField.get() == 0)
return false;
StructureConstPtr dimElementStruc = dimensionField->getStructure();
if(!NTDimension::isCompatible(dimElementStruc))
return false;
NTFieldPtr ntField = NTField::get();
StructureConstPtr dataTimeStampField = structure->getField<Structure>(
"dataTimeStamp");
if (dataTimeStampField.get() == 0 || !ntField->isTimeStamp(dataTimeStampField))
return false;
ScalarConstPtr uniqueIdField = structure->getField<Scalar>("uniqueId");
if (uniqueIdField.get() == 0)
return false;
if (uniqueIdField->getScalarType() != pvInt)
return false;
StructureArrayConstPtr attributeField = structure->getField<StructureArray>( "attribute");
if (!attributeField)
return false;
if (!NTNDArrayAttribute::isCompatible(attributeField->getStructure()))
return false;
FieldConstPtr field = structure->getField("descriptor");
if (field.get())
{
ScalarConstPtr descriptorField = structure->getField<Scalar>("descriptor");
if (!descriptorField || descriptorField->getScalarType() != pvString)
return false;
}
field = structure->getField("alarm");
if (field.get() && !ntField->isAlarm(field))
return false;
field = structure->getField("timeStamp");
if (field.get() && !ntField->isTimeStamp(field))
return false;
field = structure->getField("display");
if (field.get() && !ntField->isDisplay(field))
return false;
return true;
}
bool NTNDArray::isCompatible(PVStructurePtr const & pvStructure)
{
if(!pvStructure.get()) return false;
return isCompatible(pvStructure->getStructure());
}
bool NTNDArray::isValid()
{
int64 valueSize = getValueSize();
int64 compressedSize = getCompressedDataSize()->get();
if (valueSize != compressedSize)
return false;
long expectedUncompressed = getExpectedUncompressedSize();
long uncompressedSize = getUncompressedDataSize()->get();
if (uncompressedSize != expectedUncompressed)
return false;
std::string codecName = getCodec()->getSubField<PVString>("name")->get();
if (codecName == "" && valueSize < uncompressedSize)
return false;
return true;
}
int64 NTNDArray::getExpectedUncompressedSize()
{
int64 size = 0;
PVStructureArrayPtr pvDim = getDimension();
if (pvDim->getLength() != 0)
{
PVStructureArray::const_svector data = pvDim->view();
size = getValueTypeSize();
for (PVStructureArray::const_svector::const_iterator it = data.begin();
it != data.end(); ++it )
{
PVStructurePtr dim = *it;
size *= dim->getSubField<PVInt>("size")->get();
}
}
return size;
}
int64 NTNDArray::getValueSize()
{
int64 size = 0;
PVScalarArrayPtr storedValue = getValue()->get<PVScalarArray>();
if (!storedValue.get())
{
size = storedValue->getLength()*getValueTypeSize();
}
return size;
}
int64 NTNDArray::getValueTypeSize()
{
int64 typeSize = 0;
PVScalarArrayPtr storedValue = getValue()->get<PVScalarArray>();
if (storedValue.get())
{
switch (storedValue->getScalarArray()->getElementType())
{
case pvBoolean:
case pvByte:
case pvUByte:
typeSize = 1;
break;
case pvShort:
case pvUShort:
typeSize = 2;
break;
case pvInt:
case pvUInt:
case pvFloat:
typeSize = 4;
break;
case pvLong:
case pvULong:
case pvDouble:
typeSize = 8;
break;
default:
break;
}
}
return typeSize;
}
NTNDArrayBuilderPtr NTNDArray::createBuilder()
{
return NTNDArrayBuilderPtr(new detail::NTNDArrayBuilder());
}
bool NTNDArray::attachTimeStamp(PVTimeStamp &pvTimeStamp) const
{
PVStructurePtr ts = getTimeStamp();
if (ts)
return pvTimeStamp.attach(ts);
else
return false;
}
bool NTNDArray::attachDataTimeStamp(PVTimeStamp &pvTimeStamp) const
{
PVStructurePtr ts = getDataTimeStamp();
if (ts)
return pvTimeStamp.attach(ts);
else
return false;
}
bool NTNDArray::attachAlarm(PVAlarm &pvAlarm) const
{
PVStructurePtr al = getAlarm();
if (al)
return pvAlarm.attach(al);
else
return false;
}
bool NTNDArray::attachDisplay(PVDisplay &pvDisplay) const
{
PVStructurePtr dp = getDisplay();
if (dp)
return pvDisplay.attach(dp);
else
return false;
}
PVStructurePtr NTNDArray::getPVStructure() const
{
return pvNTNDArray;
}
PVUnionPtr NTNDArray::getValue() const
{
return pvNTNDArray->getSubField<PVUnion>("value");
}
PVStructurePtr NTNDArray::getCodec() const
{
return pvNTNDArray->getSubField<PVStructure>("codec");
}
PVLongPtr NTNDArray::getCompressedDataSize() const
{
return pvNTNDArray->getSubField<PVLong>("compressedSize");
}
PVLongPtr NTNDArray::getUncompressedDataSize() const
{
return pvNTNDArray->getSubField<PVLong>("uncompressedSize");
}
PVStructureArrayPtr NTNDArray::getDimension() const
{
return pvNTNDArray->getSubField<PVStructureArray>("dimension");
}
PVIntPtr NTNDArray::getUniqueId() const
{
return pvNTNDArray->getSubField<PVInt>("uniqueId");
}
PVStructurePtr NTNDArray::getDataTimeStamp() const
{
return pvNTNDArray->getSubField<PVStructure>("dataTimeStamp");
}
PVStructureArrayPtr NTNDArray::getAttribute() const
{
return pvNTNDArray->getSubField<PVStructureArray>("attribute");
}
PVStringPtr NTNDArray::getDescriptor() const
{
return pvNTNDArray->getSubField<PVString>("descriptor");
}
PVStructurePtr NTNDArray::getTimeStamp() const
{
return pvNTNDArray->getSubField<PVStructure>("timeStamp");
}
PVStructurePtr NTNDArray::getAlarm() const
{
return pvNTNDArray->getSubField<PVStructure>("alarm");
}
PVStructurePtr NTNDArray::getDisplay() const
{
return pvNTNDArray->getSubField<PVStructure>("display");
}
NTNDArray::NTNDArray(PVStructurePtr const & pvStructure) :
pvNTNDArray(pvStructure)
{}
}}

242
src/ntndarrayAttribute.cpp Normal file
View File

@@ -0,0 +1,242 @@
/* ntndarrayAttribute.cpp */
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#define epicsExportSharedSymbols
#include <pv/ntndarrayAttribute.h>
#include <pv/ntattribute.h>
#include <pv/ntutils.h>
using namespace std;
using namespace epics::pvData;
namespace epics { namespace nt {
static NTFieldPtr ntField = NTField::get();
namespace detail {
StructureConstPtr NTNDArrayAttributeBuilder::createStructure()
{
FieldBuilderPtr builder =
getFieldCreate()->createFieldBuilder()->
setId(NTNDArrayAttribute::URI)->
add("name", pvString)->
add("value", getFieldCreate()->createVariantUnion());
if (tags)
builder->addArray("tags", pvString);
builder->add("descriptor", pvString);
builder->add("sourceType", pvInt);
builder->add("source", pvString);
if (alarm)
builder->add("alarm", ntField->createAlarm());
if (timeStamp)
builder->add("timeStamp", ntField->createTimeStamp());
size_t extraCount = extraFieldNames.size();
for (size_t i = 0; i< extraCount; i++)
builder->add(extraFieldNames[i], extraFields[i]);
StructureConstPtr s = builder->createStructure();
reset();
return s;
}
NTNDArrayAttributeBuilder::shared_pointer NTNDArrayAttributeBuilder::addTags()
{
tags = true;
return shared_from_this();
}
NTNDArrayAttributeBuilder::shared_pointer NTNDArrayAttributeBuilder::addDescriptor()
{
descriptor = true;
return shared_from_this();
}
NTNDArrayAttributeBuilder::shared_pointer NTNDArrayAttributeBuilder::addAlarm()
{
alarm = true;
return shared_from_this();
}
NTNDArrayAttributeBuilder::shared_pointer NTNDArrayAttributeBuilder::addTimeStamp()
{
timeStamp = true;
return shared_from_this();
}
PVStructurePtr NTNDArrayAttributeBuilder::createPVStructure()
{
return getPVDataCreate()->createPVStructure(createStructure());
}
NTNDArrayAttributePtr NTNDArrayAttributeBuilder::create()
{
return NTNDArrayAttributePtr(new NTNDArrayAttribute(createPVStructure()));
}
NTNDArrayAttributeBuilder::NTNDArrayAttributeBuilder()
{
reset();
}
void NTNDArrayAttributeBuilder::reset()
{
tags = false;
descriptor = false;
alarm = false;
timeStamp = false;
extraFieldNames.clear();
extraFields.clear();
}
NTNDArrayAttributeBuilder::shared_pointer NTNDArrayAttributeBuilder::add(string const & name, FieldConstPtr const & field)
{
extraFields.push_back(field); extraFieldNames.push_back(name);
return shared_from_this();
}
}
const std::string NTNDArrayAttribute::URI("epics:nt/NTAttribute:1.0");
NTNDArrayAttribute::shared_pointer NTNDArrayAttribute::wrap(PVStructurePtr const & pvStructure)
{
if(!isCompatible(pvStructure)) return shared_pointer();
return wrapUnsafe(pvStructure);
}
NTNDArrayAttribute::shared_pointer NTNDArrayAttribute::wrapUnsafe(PVStructurePtr const & pvStructure)
{
return shared_pointer(new NTNDArrayAttribute(pvStructure));
}
bool NTNDArrayAttribute::is_a(StructureConstPtr const & structure)
{
return NTUtils::is_a(structure->getID(), URI);
}
bool NTNDArrayAttribute::is_a(PVStructurePtr const & pvStructure)
{
return is_a(pvStructure->getStructure());
}
bool NTNDArrayAttribute::isCompatible(StructureConstPtr const & structure)
{
if (!NTAttribute::isCompatible(structure)) return false;
// descriptor required field for attibute in an ndarray
ScalarConstPtr descriptorField = structure->getField<Scalar>("descriptor");
if (descriptorField.get() == 0 || descriptorField->getScalarType() != pvString)
return false;
ScalarConstPtr sourcedTypeField = structure->getField<Scalar>("sourceType");
if (sourcedTypeField.get() == 0 || sourcedTypeField->getScalarType() != pvInt)
return false;
ScalarConstPtr sourcedField = structure->getField<Scalar>("source");
if (sourcedField.get() == 0 || sourcedField->getScalarType() != pvString)
return false;
return true;
}
bool NTNDArrayAttribute::isCompatible(PVStructurePtr const & pvStructure)
{
if(!pvStructure) return false;
return isCompatible(pvStructure->getStructure());
}
bool NTNDArrayAttribute::isValid()
{
return true;
}
NTNDArrayAttributeBuilderPtr NTNDArrayAttribute::createBuilder()
{
return NTNDArrayAttributeBuilderPtr(new detail::NTNDArrayAttributeBuilder());
}
bool NTNDArrayAttribute::attachTimeStamp(PVTimeStamp &pvTimeStamp) const
{
PVStructurePtr ts = getTimeStamp();
if (ts)
return pvTimeStamp.attach(ts);
else
return false;
}
bool NTNDArrayAttribute::attachAlarm(PVAlarm &pvAlarm) const
{
PVStructurePtr al = getAlarm();
if (al)
return pvAlarm.attach(al);
else
return false;
}
PVStructurePtr NTNDArrayAttribute::getPVStructure() const
{
return pvNTNDArrayAttribute;
}
PVStringPtr NTNDArrayAttribute::getDescriptor() const
{
return pvNTNDArrayAttribute->getSubField<PVString>("descriptor");
}
PVStructurePtr NTNDArrayAttribute::getTimeStamp() const
{
return pvNTNDArrayAttribute->getSubField<PVStructure>("timeStamp");
}
PVStructurePtr NTNDArrayAttribute::getAlarm() const
{
return pvNTNDArrayAttribute->getSubField<PVStructure>("alarm");
}
PVStringPtr NTNDArrayAttribute::getName() const
{
return pvNTNDArrayAttribute->getSubField<PVString>("name");
}
PVUnionPtr NTNDArrayAttribute::getValue() const
{
return pvValue;
}
PVStringArrayPtr NTNDArrayAttribute::getTags() const
{
return pvNTNDArrayAttribute->getSubField<PVStringArray>("tags");
}
PVIntPtr NTNDArrayAttribute::getSourceType() const
{
return pvNTNDArrayAttribute->getSubField<PVInt>("sourceType");
}
PVStringPtr NTNDArrayAttribute::getSource() const
{
return pvNTNDArrayAttribute->getSubField<PVString>("source");
}
NTNDArrayAttribute::NTNDArrayAttribute(PVStructurePtr const & pvStructure) :
pvNTNDArrayAttribute(pvStructure), pvValue(pvNTNDArrayAttribute->getSubField<PVUnion>("value"))
{
}
}}

View File

@@ -1,8 +1,7 @@
/* ntscalar.cpp */
/**
* Copyright - See the COPYRIGHT that is included with this distribution.
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#define epicsExportSharedSymbols
@@ -18,8 +17,6 @@ static NTFieldPtr ntField = NTField::get();
namespace detail {
static NTFieldPtr ntField = NTField::get();
NTScalarBuilder::shared_pointer NTScalarBuilder::value(
epics::pvData::ScalarType scalarType
)
@@ -132,15 +129,15 @@ NTScalarBuilder::shared_pointer NTScalarBuilder::add(string const & name, FieldC
const std::string NTScalar::URI("epics:nt/NTScalar:1.0");
NTScalar::shared_pointer NTScalar::wrap(PVStructurePtr const & structure)
NTScalar::shared_pointer NTScalar::wrap(PVStructurePtr const & pvStructure)
{
if(!isCompatible(structure)) return shared_pointer();
return wrapUnsafe(structure);
if(!isCompatible(pvStructure)) return shared_pointer();
return wrapUnsafe(pvStructure);
}
NTScalar::shared_pointer NTScalar::wrapUnsafe(PVStructurePtr const & structure)
NTScalar::shared_pointer NTScalar::wrapUnsafe(PVStructurePtr const & pvStructure)
{
return shared_pointer(new NTScalar(structure));
return shared_pointer(new NTScalar(pvStructure));
}
bool NTScalar::is_a(StructureConstPtr const & structure)
@@ -148,21 +145,58 @@ bool NTScalar::is_a(StructureConstPtr const & structure)
return NTUtils::is_a(structure->getID(), URI);
}
bool NTScalar::is_a(PVStructurePtr const & pvStructure)
{
return is_a(pvStructure->getStructure());
}
bool NTScalar::isCompatible(StructureConstPtr const &structure)
{
if (structure.get() == 0) return false;
ScalarConstPtr valueField = structure->getField<Scalar>("value");
if (valueField.get() == 0)
return false;
FieldConstPtr field = structure->getField("descriptor");
if (field.get())
{
ScalarConstPtr descriptorField = structure->getField<Scalar>("descriptor");
if (!descriptorField.get() || descriptorField->getScalarType() != pvString)
return false;
}
NTFieldPtr ntField = NTField::get();
field = structure->getField("alarm");
if (field.get() && !ntField->isAlarm(field))
return false;
field = structure->getField("timeStamp");
if (field.get() && !ntField->isTimeStamp(field))
return false;
field = structure->getField("display");
if (field.get() && !ntField->isDisplay(field))
return false;
field = structure->getField("control");
if (field.get() && !ntField->isControl(field))
return false;
return true;
}
bool NTScalar::isCompatible(PVStructurePtr const & pvStructure)
{
if(!pvStructure) return false;
PVScalarPtr pvValue = pvStructure->getSubField<PVScalar>("value");
if(!pvValue) return false;
PVFieldPtr pvField = pvStructure->getSubField("descriptor");
if(pvField && !pvStructure->getSubField<PVString>("descriptor")) return false;
pvField = pvStructure->getSubField("alarm");
if(pvField && !ntField->isAlarm(pvField->getField())) return false;
pvField = pvStructure->getSubField("timeStamp");
if(pvField && !ntField->isTimeStamp(pvField->getField())) return false;
pvField = pvStructure->getSubField("display");
if(pvField && !ntField->isDisplay(pvField->getField())) return false;
pvField = pvStructure->getSubField("control");
if(pvField && !ntField->isControl(pvField->getField())) return false;
return isCompatible(pvStructure->getStructure());
}
bool NTScalar::isValid()
{
return true;
}

View File

@@ -1,8 +1,7 @@
/* ntscalarArray.cpp */
/**
* Copyright - See the COPYRIGHT that is included with this distribution.
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#define epicsExportSharedSymbols
@@ -18,6 +17,16 @@ static NTFieldPtr ntField = NTField::get();
namespace detail {
NTScalarArrayBuilder::shared_pointer NTScalarArrayBuilder::value(
epics::pvData::ScalarType elementType
)
{
valueType = elementType;
valueTypeSet = true;
return shared_from_this();
}
NTScalarArrayBuilder::shared_pointer NTScalarArrayBuilder::arrayValue(
epics::pvData::ScalarType elementType
)
@@ -129,15 +138,15 @@ NTScalarArrayBuilder::shared_pointer NTScalarArrayBuilder::add(string const & na
const std::string NTScalarArray::URI("epics:nt/NTScalarArray:1.0");
NTScalarArray::shared_pointer NTScalarArray::wrap(PVStructurePtr const & structure)
NTScalarArray::shared_pointer NTScalarArray::wrap(PVStructurePtr const & pvStructure)
{
if(!isCompatible(structure)) return shared_pointer();
return wrapUnsafe(structure);
if(!isCompatible(pvStructure)) return shared_pointer();
return wrapUnsafe(pvStructure);
}
NTScalarArray::shared_pointer NTScalarArray::wrapUnsafe(PVStructurePtr const & structure)
NTScalarArray::shared_pointer NTScalarArray::wrapUnsafe(PVStructurePtr const & pvStructure)
{
return shared_pointer(new NTScalarArray(structure));
return shared_pointer(new NTScalarArray(pvStructure));
}
bool NTScalarArray::is_a(StructureConstPtr const & structure)
@@ -145,24 +154,59 @@ bool NTScalarArray::is_a(StructureConstPtr const & structure)
return NTUtils::is_a(structure->getID(), URI);
}
bool NTScalarArray::isCompatible(PVStructurePtr const & pvStructure)
bool NTScalarArray::is_a(PVStructurePtr const & pvStructure)
{
if(!pvStructure) return false;
PVScalarArrayPtr pvValue = pvStructure->getSubField<PVScalarArray>("value");
if(!pvValue) return false;
PVFieldPtr pvField = pvStructure->getSubField("descriptor");
if(pvField && !pvStructure->getSubField<PVString>("descriptor")) return false;
pvField = pvStructure->getSubField("alarm");
if(pvField && !ntField->isAlarm(pvField->getField())) return false;
pvField = pvStructure->getSubField("timeStamp");
if(pvField && !ntField->isTimeStamp(pvField->getField())) return false;
pvField = pvStructure->getSubField("display");
if(pvField && !ntField->isDisplay(pvField->getField())) return false;
pvField = pvStructure->getSubField("control");
if(pvField && !ntField->isControl(pvField->getField())) return false;
return is_a(pvStructure->getStructure());
}
bool NTScalarArray::isCompatible(StructureConstPtr const & structure)
{
if (structure.get() == 0) return false;
ScalarArrayConstPtr valueField = structure->getField<ScalarArray>("value");
if (valueField.get() == 0)
return false;
FieldConstPtr field = structure->getField("descriptor");
if (field.get())
{
ScalarConstPtr descriptorField = structure->getField<Scalar>("descriptor");
if (!descriptorField.get() || descriptorField->getScalarType() != pvString)
return false;
}
NTFieldPtr ntField = NTField::get();
field = structure->getField("alarm");
if (field.get() && !ntField->isAlarm(field))
return false;
field = structure->getField("timeStamp");
if (field.get() && !ntField->isTimeStamp(field))
return false;
field = structure->getField("display");
if (field.get() && !ntField->isDisplay(field))
return false;
field = structure->getField("control");
if (field.get() && !ntField->isControl(field))
return false;
return true;
}
bool NTScalarArray::isCompatible(PVStructurePtr const & pvStructure)
{
if(!pvStructure) return false;
return isCompatible(pvStructure->getStructure());
}
bool NTScalarArray::isValid()
{
return true;
}
NTScalarArrayBuilderPtr NTScalarArray::createBuilder()
{

View File

@@ -0,0 +1,379 @@
/* ntscalarMultiChannel.cpp */
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#include <algorithm>
#define epicsExportSharedSymbols
#include <pv/ntscalarMultiChannel.h>
#include <pv/ntutils.h>
using namespace std;
using namespace epics::pvData;
namespace epics { namespace nt {
static FieldCreatePtr fieldCreate = getFieldCreate();
static PVDataCreatePtr pvDataCreate = getPVDataCreate();
static NTFieldPtr ntField = NTField::get();
namespace detail {
NTScalarMultiChannelBuilder::shared_pointer NTScalarMultiChannelBuilder::value(ScalarType scalarType)
{
valueType = scalarType;
return shared_from_this();
}
NTScalarMultiChannelBuilder::shared_pointer NTScalarMultiChannelBuilder::addDescriptor()
{
descriptor = true;
return shared_from_this();
}
NTScalarMultiChannelBuilder::shared_pointer NTScalarMultiChannelBuilder::addAlarm()
{
alarm = true;
return shared_from_this();
}
NTScalarMultiChannelBuilder::shared_pointer NTScalarMultiChannelBuilder::addTimeStamp()
{
timeStamp = true;
return shared_from_this();
}
NTScalarMultiChannelBuilder::shared_pointer NTScalarMultiChannelBuilder::addSeverity()
{
severity = true;
return shared_from_this();
}
NTScalarMultiChannelBuilder::shared_pointer NTScalarMultiChannelBuilder::addStatus()
{
status = true;
return shared_from_this();
}
NTScalarMultiChannelBuilder::shared_pointer NTScalarMultiChannelBuilder::addMessage()
{
message = true;
return shared_from_this();
}
NTScalarMultiChannelBuilder::shared_pointer NTScalarMultiChannelBuilder::addSecondsPastEpoch()
{
secondsPastEpoch = true;
return shared_from_this();
}
NTScalarMultiChannelBuilder::shared_pointer NTScalarMultiChannelBuilder::addNanoseconds()
{
nanoseconds = true;
return shared_from_this();
}
NTScalarMultiChannelBuilder::shared_pointer NTScalarMultiChannelBuilder::addUserTag()
{
userTag = true;
return shared_from_this();
}
NTScalarMultiChannelBuilder::shared_pointer NTScalarMultiChannelBuilder::addIsConnected()
{
isConnected = true;
return shared_from_this();
}
StructureConstPtr NTScalarMultiChannelBuilder::createStructure()
{
StandardFieldPtr standardField = getStandardField();
size_t nfields = 2;
size_t extraCount = extraFieldNames.size();
nfields += extraCount;
if(descriptor) ++nfields;
if(alarm) ++nfields;
if(timeStamp) ++nfields;
if(severity) ++nfields;
if(status) ++nfields;
if(message) ++nfields;
if(secondsPastEpoch) ++nfields;
if(nanoseconds) ++nfields;
if(userTag) ++nfields;
if(isConnected) ++nfields;
FieldConstPtrArray fields(nfields);
StringArray names(nfields);
size_t ind = 0;
names[ind] = "value";
fields[ind++] = fieldCreate->createScalarArray(valueType);
names[ind] = "channelName";
fields[ind++] = fieldCreate->createScalarArray(pvString);
if(descriptor) {
names[ind] = "descriptor";
fields[ind++] = fieldCreate->createScalar(pvString);
}
if(alarm) {
names[ind] = "alarm";
fields[ind++] = standardField->alarm();
}
if(timeStamp) {
names[ind] = "timeStamp";
fields[ind++] = standardField->timeStamp();
}
if(severity) {
names[ind] = "severity";
fields[ind++] = fieldCreate->createScalarArray(pvInt);
}
if(status) {
names[ind] = "status";
fields[ind++] = fieldCreate->createScalarArray(pvInt);
}
if(message) {
names[ind] = "message";
fields[ind++] = fieldCreate->createScalarArray(pvString);
}
if(secondsPastEpoch) {
names[ind] = "secondsPastEpoch";
fields[ind++] = fieldCreate->createScalarArray(pvLong);
}
if(nanoseconds) {
names[ind] = "nanoseconds";
fields[ind++] = fieldCreate->createScalarArray(pvInt);
}
if(userTag) {
names[ind] = "userTag";
fields[ind++] = fieldCreate->createScalarArray(pvInt);
}
if(isConnected) {
names[ind] = "isConnected";
fields[ind++] = fieldCreate->createScalarArray(pvBoolean);
}
for (size_t i = 0; i< extraCount; i++) {
names[ind] = extraFieldNames[i];
fields[ind++] = extraFields[i];
}
StructureConstPtr st = fieldCreate->createStructure(NTScalarMultiChannel::URI,names,fields);
reset();
return st;
}
PVStructurePtr NTScalarMultiChannelBuilder::createPVStructure()
{
return pvDataCreate->createPVStructure(createStructure());
}
NTScalarMultiChannelPtr NTScalarMultiChannelBuilder::create()
{
return NTScalarMultiChannelPtr(new NTScalarMultiChannel(createPVStructure()));
}
NTScalarMultiChannelBuilder::NTScalarMultiChannelBuilder()
: valueType(pvDouble)
{
reset();
}
void NTScalarMultiChannelBuilder::reset()
{
extraFieldNames.clear();
extraFields.clear();
valueType = pvDouble;
descriptor = false;
alarm = false;
timeStamp = false;
severity = false;
status = false;
message = false;
secondsPastEpoch = false;
nanoseconds = false;
userTag = false;
isConnected = false;
}
NTScalarMultiChannelBuilder::shared_pointer NTScalarMultiChannelBuilder::add(string const & name, FieldConstPtr const & field)
{
extraFields.push_back(field); extraFieldNames.push_back(name);
return shared_from_this();
}
}
const std::string NTScalarMultiChannel::URI("epics:nt/NTScalarMultiChannel:1.0");
NTScalarMultiChannel::shared_pointer NTScalarMultiChannel::wrap(PVStructurePtr const & pvStructure)
{
if(!isCompatible(pvStructure)) return shared_pointer();
return wrapUnsafe(pvStructure);
}
NTScalarMultiChannel::shared_pointer NTScalarMultiChannel::wrapUnsafe(PVStructurePtr const & pvStructure)
{
return shared_pointer(new NTScalarMultiChannel(pvStructure));
}
bool NTScalarMultiChannel::is_a(StructureConstPtr const &structure)
{
return NTUtils::is_a(structure->getID(), URI);
}
bool NTScalarMultiChannel::is_a(PVStructurePtr const & pvStructure)
{
return is_a(pvStructure->getStructure());
}
bool NTScalarMultiChannel::isCompatible(StructureConstPtr const & structure)
{
if (!structure.get()) return false;
ScalarArrayConstPtr valueField = structure->getField<ScalarArray>("value");
if (!valueField.get()) return false;
ScalarArrayConstPtr channelNameField = structure->getField<ScalarArray>(
"channelName");
if (!channelNameField.get()) return false;
if (channelNameField->getElementType() != pvString) return false;
FieldConstPtr field = structure->getField("severity");
if (field.get())
{
ScalarArrayConstPtr severityField = structure->getField<ScalarArray>("severity");
if (!severityField.get() || severityField->getElementType() != pvInt)
return false;
}
field = structure->getField("status");
if (field.get())
{
ScalarArrayConstPtr statusField = structure->getField<ScalarArray>("status");
if (!statusField.get() || statusField->getElementType() != pvInt)
return false;
}
field = structure->getField("message");
if (field.get())
{
ScalarArrayConstPtr messageField = structure->getField<ScalarArray>("message");
if (!messageField.get() || messageField->getElementType() != pvString)
return false;
}
field = structure->getField("secondsPastEpoch");
if (field.get())
{
ScalarArrayConstPtr secondsPastEpochField = structure->getField<ScalarArray>("secondsPastEpoch");
if (!secondsPastEpochField.get() || secondsPastEpochField->getElementType() != pvLong)
return false;
}
field = structure->getField("nanoseconds");
if (field.get())
{
ScalarArrayConstPtr nanosecondsField = structure->getField<ScalarArray>("nanoseconds");
if (!nanosecondsField.get() || nanosecondsField->getElementType() != pvInt)
return false;
}
field = structure->getField("userTag");
if (field.get())
{
ScalarArrayConstPtr userTagField = structure->getField<ScalarArray>("userTag");
if (!userTagField.get() || userTagField->getElementType() != pvInt)
return false;
}
field = structure->getField("descriptor");
if (field.get())
{
ScalarConstPtr descriptorField = structure->getField<Scalar>("descriptor");
if (!descriptorField.get() || descriptorField->getScalarType() != pvString)
return false;
}
NTFieldPtr ntField = NTField::get();
field = structure->getField("alarm");
if (field.get() && !ntField->isAlarm(field))
return false;
field = structure->getField("timeStamp");
if (field.get() && !ntField->isTimeStamp(field))
return false;
return true;
}
bool NTScalarMultiChannel::isCompatible(PVStructurePtr const &pvStructure)
{
if(!pvStructure.get()) return false;
return isCompatible(pvStructure->getStructure());
}
bool NTScalarMultiChannel::isValid()
{
size_t valueLength = getValue()->getLength();
if (getChannelName()->getLength() != valueLength) return false;
PVScalarArrayPtr arrayFields[] = {
getSeverity(), getStatus(), getMessage(),
getSecondsPastEpoch(), getNanoseconds(), getUserTag()
};
size_t N = sizeof(arrayFields)/sizeof(arrayFields[0]);
PVScalarArrayPtr arrayField;
for (PVScalarArrayPtr * pa = arrayFields; pa != arrayFields+N; ++pa)
{
arrayField = *pa;
if (arrayField.get() && arrayField->getLength() != valueLength)
return false;
}
return true;
}
NTScalarMultiChannelBuilderPtr NTScalarMultiChannel::createBuilder()
{
return NTScalarMultiChannelBuilderPtr(new detail::NTScalarMultiChannelBuilder());
}
NTScalarMultiChannel::NTScalarMultiChannel(PVStructurePtr const & pvStructure)
: pvNTScalarMultiChannel(pvStructure),
pvTimeStamp(pvStructure->getSubField<PVStructure>("timeStamp")),
pvAlarm(pvStructure->getSubField<PVStructure>("alarm")),
pvValue(pvStructure->getSubField<PVScalarArray>("value")),
pvChannelName(pvStructure->getSubField<PVStringArray>("channelName")),
pvIsConnected(pvStructure->getSubField<PVBooleanArray>("isConnected")),
pvSeverity(pvStructure->getSubField<PVIntArray>("severity")),
pvStatus(pvStructure->getSubField<PVIntArray>("status")),
pvMessage(pvStructure->getSubField<PVStringArray>("message")),
pvSecondsPastEpoch(pvStructure->getSubField<PVLongArray>("secondsPastEpoch")),
pvNanoseconds(pvStructure->getSubField<PVIntArray>("nanoseconds")),
pvUserTag(pvStructure->getSubField<PVIntArray>("userTag")),
pvDescriptor(pvStructure->getSubField<PVString>("descriptor"))
{
}
bool NTScalarMultiChannel::attachTimeStamp(PVTimeStamp &pv) const
{
if (pvTimeStamp)
return pv.attach(pvTimeStamp);
else
return false;
}
bool NTScalarMultiChannel::attachAlarm(PVAlarm &pv) const
{
if (pvAlarm)
return pv.attach(pvAlarm);
else
return false;
}
}}

View File

@@ -1,8 +1,7 @@
/* nttable.cpp */
/**
* Copyright - See the COPYRIGHT that is included with this distribution.
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#include <algorithm>
@@ -20,14 +19,14 @@ static NTFieldPtr ntField = NTField::get();
namespace detail {
NTTableBuilder::shared_pointer NTTableBuilder::add(
NTTableBuilder::shared_pointer NTTableBuilder::addColumn(
std::string const & name, epics::pvData::ScalarType scalarType
)
{
if (std::find(labels.begin(), labels.end(), name) != labels.end())
if (std::find(columnNames.begin(), columnNames.end(), name) != columnNames.end())
throw std::runtime_error("duplicate column name");
labels.push_back(name);
columnNames.push_back(name);
types.push_back(scalarType);
return shared_from_this();
@@ -43,9 +42,9 @@ StructureConstPtr NTTableBuilder::createStructure()
addArray("labels", pvString)->
addNestedStructure("value");
vector<string>::size_type len = labels.size();
vector<string>::size_type len = columnNames.size();
for (vector<string>::size_type i = 0; i < len; i++)
nestedBuilder->addArray(labels[i], types[i]);
nestedBuilder->addArray(columnNames[i], types[i]);
builder = nestedBuilder->endNested();
@@ -58,12 +57,11 @@ StructureConstPtr NTTableBuilder::createStructure()
if (timeStamp)
builder->add("timeStamp", ntField->createTimeStamp());
StructureConstPtr s = builder->createStructure();
size_t extraCount = extraFieldNames.size();
for (size_t i = 0; i< extraCount; i++)
builder->add(extraFieldNames[i], extraFields[i]);
StructureConstPtr s = builder->createStructure();
reset();
return s;
@@ -89,9 +87,10 @@ NTTableBuilder::shared_pointer NTTableBuilder::addTimeStamp()
PVStructurePtr NTTableBuilder::createPVStructure()
{
size_t len = labels.size();
// fill in labels with default values (the column names)
size_t len = columnNames.size();
shared_vector<string> l(len);
for(size_t i=0; i<len; ++i) l[i] = labels[i];
for(size_t i=0; i<len; ++i) l[i] = columnNames[i];
PVStructurePtr s = getPVDataCreate()->createPVStructure(createStructure());
s->getSubField<PVStringArray>("labels")->replace(freeze(l));
return s;
@@ -109,7 +108,7 @@ NTTableBuilder::NTTableBuilder()
void NTTableBuilder::reset()
{
labels.clear();
columnNames.clear();
types.clear();
descriptor = false;
alarm = false;
@@ -127,15 +126,15 @@ NTTableBuilder::shared_pointer NTTableBuilder::add(string const & name, FieldCon
const std::string NTTable::URI("epics:nt/NTTable:1.0");
NTTable::shared_pointer NTTable::wrap(PVStructurePtr const & structure)
NTTable::shared_pointer NTTable::wrap(PVStructurePtr const & pvStructure)
{
if(!isCompatible(structure)) return shared_pointer();
return wrapUnsafe(structure);
if(!isCompatible(pvStructure)) return shared_pointer();
return wrapUnsafe(pvStructure);
}
NTTable::shared_pointer NTTable::wrapUnsafe(PVStructurePtr const & structure)
NTTable::shared_pointer NTTable::wrapUnsafe(PVStructurePtr const & pvStructure)
{
return shared_pointer(new NTTable(structure));
return shared_pointer(new NTTable(pvStructure));
}
bool NTTable::is_a(StructureConstPtr const & structure)
@@ -143,18 +142,84 @@ bool NTTable::is_a(StructureConstPtr const & structure)
return NTUtils::is_a(structure->getID(), URI);
}
bool NTTable::is_a(PVStructurePtr const & pvStructure)
{
return is_a(pvStructure->getStructure());
}
bool NTTable::isCompatible(StructureConstPtr const & structure)
{
if (!structure.get()) return false;
StructureConstPtr valueField = structure->getField<Structure>("value");
if (!valueField.get())
return false;
FieldConstPtrArray const & fields = valueField->getFields();
for (FieldConstPtrArray::const_iterator it = fields.begin();
it != fields.end(); ++it)
{
if ((*it)->getType() != scalarArray) return false;
}
ScalarArrayConstPtr labelsField = structure->getField<ScalarArray>("labels");
if (!labelsField.get() || labelsField->getElementType() != pvString)
return false;
FieldConstPtr field = structure->getField("descriptor");
if (field.get())
{
ScalarConstPtr descriptorField = structure->getField<Scalar>("descriptor");
if (!descriptorField.get() || descriptorField->getScalarType() != pvString)
return false;
}
NTFieldPtr ntField = NTField::get();
field = structure->getField("alarm");
if (field.get() && !ntField->isAlarm(field))
return false;
field = structure->getField("timeStamp");
if (field.get() && !ntField->isTimeStamp(field))
return false;
return true;
}
bool NTTable::isCompatible(PVStructurePtr const & pvStructure)
{
if(!pvStructure) return false;
PVFieldPtr pvField = pvStructure->getSubField("alarm");
if(pvField && !ntField->isAlarm(pvField->getField())) return false;
pvField = pvStructure->getSubField("timeStamp");
if(pvField && !ntField->isTimeStamp(pvField->getField())) return false;
PVStringArrayPtr pvLabel = pvStructure->getSubField<PVStringArray>("labels");
if(!pvLabel) return false;
return isCompatible(pvStructure->getStructure());
}
bool NTTable::isValid()
{
PVFieldPtrArray const & columns = pvValue->getPVFields();
if (getLabels()->getLength() != columns.size()) return false;
bool first = true;
int length = 0;
for (PVFieldPtrArray::const_iterator it = columns.begin();
it != columns.end();++it)
{
PVScalarArrayPtr column = std::tr1::dynamic_pointer_cast<PVScalarArray>(*it);
if (!column.get()) return false;
int colLength = column->getLength();
if (first)
{
length = colLength;
first = false;
}
else if (length != colLength)
return false;
}
return true;
}
NTTableBuilderPtr NTTable::createBuilder()
{
return NTTableBuilderPtr(new detail::NTTableBuilder());
@@ -203,13 +268,18 @@ PVStringArrayPtr NTTable::getLabels() const
return pvNTTable->getSubField<PVStringArray>("labels");
}
StringArray const & NTTable::getColumnNames() const
{
return pvValue->getStructure()->getFieldNames();
}
PVFieldPtr NTTable::getColumn(std::string const & columnName) const
{
return pvNTTable->getSubField("value." + columnName);
return pvValue->getSubField(columnName);
}
NTTable::NTTable(PVStructurePtr const & pvStructure) :
pvNTTable(pvStructure)
pvNTTable(pvStructure), pvValue(pvNTTable->getSubField<PVStructure>("value"))
{}

223
src/ntunion.cpp Normal file
View File

@@ -0,0 +1,223 @@
/* ntunion.cpp */
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#define epicsExportSharedSymbols
#include <pv/ntunion.h>
#include <pv/ntutils.h>
using namespace std;
using namespace epics::pvData;
namespace epics { namespace nt {
static NTFieldPtr ntField = NTField::get();
namespace detail {
NTUnionBuilder::shared_pointer NTUnionBuilder::value(UnionConstPtr unionType)
{
valueType = unionType;
return shared_from_this();
}
StructureConstPtr NTUnionBuilder::createStructure()
{
FieldBuilderPtr builder =
getFieldCreate()->createFieldBuilder()->
setId(NTUnion::URI)->
add("value", valueType);
if (descriptor)
builder->add("descriptor", pvString);
if (alarm)
builder->add("alarm", ntField->createAlarm());
if (timeStamp)
builder->add("timeStamp", ntField->createTimeStamp());
size_t extraCount = extraFieldNames.size();
for (size_t i = 0; i< extraCount; i++)
builder->add(extraFieldNames[i], extraFields[i]);
StructureConstPtr s = builder->createStructure();
reset();
return s;
}
NTUnionBuilder::shared_pointer NTUnionBuilder::addDescriptor()
{
descriptor = true;
return shared_from_this();
}
NTUnionBuilder::shared_pointer NTUnionBuilder::addAlarm()
{
alarm = true;
return shared_from_this();
}
NTUnionBuilder::shared_pointer NTUnionBuilder::addTimeStamp()
{
timeStamp = true;
return shared_from_this();
}
PVStructurePtr NTUnionBuilder::createPVStructure()
{
return getPVDataCreate()->createPVStructure(createStructure());
}
NTUnionPtr NTUnionBuilder::create()
{
return NTUnionPtr(new NTUnion(createPVStructure()));
}
NTUnionBuilder::NTUnionBuilder()
{
reset();
}
void NTUnionBuilder::reset()
{
valueType = getFieldCreate()->createVariantUnion();
descriptor = false;
alarm = false;
timeStamp = false;
extraFieldNames.clear();
extraFields.clear();
}
NTUnionBuilder::shared_pointer NTUnionBuilder::add(string const & name, FieldConstPtr const & field)
{
extraFields.push_back(field); extraFieldNames.push_back(name);
return shared_from_this();
}
}
const std::string NTUnion::URI("epics:nt/NTUnion:1.0");
NTUnion::shared_pointer NTUnion::wrap(PVStructurePtr const & pvStructure)
{
if(!isCompatible(pvStructure)) return shared_pointer();
return wrapUnsafe(pvStructure);
}
NTUnion::shared_pointer NTUnion::wrapUnsafe(PVStructurePtr const & pvStructure)
{
return shared_pointer(new NTUnion(pvStructure));
}
bool NTUnion::is_a(StructureConstPtr const & structure)
{
return NTUtils::is_a(structure->getID(), URI);
}
bool NTUnion::is_a(PVStructurePtr const & pvStructure)
{
return is_a(pvStructure->getStructure());
}
bool NTUnion::isCompatible(StructureConstPtr const &structure)
{
if (structure.get() == 0) return false;
UnionConstPtr valueField = structure->getField<Union>("value");
if (valueField.get() == 0)
return false;
FieldConstPtr field = structure->getField("descriptor");
if (field.get())
{
ScalarConstPtr descriptorField = structure->getField<Scalar>("descriptor");
if (!descriptorField.get() || descriptorField->getScalarType() != pvString)
return false;
}
NTFieldPtr ntField = NTField::get();
field = structure->getField("alarm");
if (field.get() && !ntField->isAlarm(field))
return false;
field = structure->getField("timeStamp");
if (field.get() && !ntField->isTimeStamp(field))
return false;
return true;
}
bool NTUnion::isCompatible(PVStructurePtr const & pvStructure)
{
if(!pvStructure) return false;
return isCompatible(pvStructure->getStructure());
}
bool NTUnion::isValid()
{
return true;
}
NTUnionBuilderPtr NTUnion::createBuilder()
{
return NTUnionBuilderPtr(new detail::NTUnionBuilder());
}
bool NTUnion::attachTimeStamp(PVTimeStamp &pvTimeStamp) const
{
PVStructurePtr ts = getTimeStamp();
if (ts)
return pvTimeStamp.attach(ts);
else
return false;
}
bool NTUnion::attachAlarm(PVAlarm &pvAlarm) const
{
PVStructurePtr al = getAlarm();
if (al)
return pvAlarm.attach(al);
else
return false;
}
PVStructurePtr NTUnion::getPVStructure() const
{
return pvNTUnion;
}
PVStringPtr NTUnion::getDescriptor() const
{
return pvNTUnion->getSubField<PVString>("descriptor");
}
PVStructurePtr NTUnion::getTimeStamp() const
{
return pvNTUnion->getSubField<PVStructure>("timeStamp");
}
PVStructurePtr NTUnion::getAlarm() const
{
return pvNTUnion->getSubField<PVStructure>("alarm");
}
PVUnionPtr NTUnion::getValue() const
{
return pvValue;
}
NTUnion::NTUnion(PVStructurePtr const & pvStructure) :
pvNTUnion(pvStructure), pvValue(pvNTUnion->getSubField<PVUnion>("value"))
{}
}}

253
src/nturi.cpp Normal file
View File

@@ -0,0 +1,253 @@
/* nturi.cpp */
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#include <algorithm>
#define epicsExportSharedSymbols
#include <pv/nturi.h>
#include <pv/ntutils.h>
using namespace std;
using namespace epics::pvData;
namespace epics { namespace nt {
static NTFieldPtr ntField = NTField::get();
namespace detail {
NTURIBuilder::shared_pointer NTURIBuilder::addQueryString(std::string const & name)
{
if (std::find(queryFieldNames.begin(), queryFieldNames.end(), name) != queryFieldNames.end())
throw std::runtime_error("duplicate query field name");
queryFieldNames.push_back(name);
queryTypes.push_back(pvString);
return shared_from_this();
}
NTURIBuilder::shared_pointer NTURIBuilder::addQueryDouble(std::string const & name)
{
if (std::find(queryFieldNames.begin(), queryFieldNames.end(), name) != queryFieldNames.end())
throw std::runtime_error("duplicate query field name");
queryFieldNames.push_back(name);
queryTypes.push_back(pvDouble);
return shared_from_this();
}
NTURIBuilder::shared_pointer NTURIBuilder::addQueryInt(std::string const & name)
{
if (std::find(queryFieldNames.begin(), queryFieldNames.end(), name) != queryFieldNames.end())
throw std::runtime_error("duplicate query field name");
queryFieldNames.push_back(name);
queryTypes.push_back(pvInt);
return shared_from_this();
}
StructureConstPtr NTURIBuilder::createStructure()
{
FieldBuilderPtr builder = getFieldCreate()->
createFieldBuilder()->
setId(NTURI::URI)->
add("scheme", pvString);
if (authority)
builder->add("authority", pvString);
builder->add("path", pvString);
if (!queryFieldNames.empty())
{
FieldBuilderPtr nestedBuilder = builder->
addNestedStructure("query");
vector<string>::size_type len = queryFieldNames.size();
for (vector<string>::size_type i = 0; i < len; i++)
nestedBuilder->add(queryFieldNames[i], queryTypes[i]);
builder = nestedBuilder->endNested();
}
size_t extraCount = extraFieldNames.size();
for (size_t i = 0; i< extraCount; i++)
builder->add(extraFieldNames[i], extraFields[i]);
StructureConstPtr s = builder->createStructure();
reset();
return s;
}
NTURIBuilder::shared_pointer NTURIBuilder::addAuthority()
{
authority = true;
return shared_from_this();
}
PVStructurePtr NTURIBuilder::createPVStructure()
{
return getPVDataCreate()->createPVStructure(createStructure());
}
NTURIPtr NTURIBuilder::create()
{
return NTURIPtr(new NTURI(createPVStructure()));
}
NTURIBuilder::NTURIBuilder()
{
reset();
}
void NTURIBuilder::reset()
{
queryFieldNames.clear();
queryTypes.clear();
authority = false;
}
NTURIBuilder::shared_pointer NTURIBuilder::add(string const & name, FieldConstPtr const & field)
{
extraFields.push_back(field);
extraFieldNames.push_back(name);
return shared_from_this();
}
}
const std::string NTURI::URI("epics:nt/NTURI:1.0");
NTURI::shared_pointer NTURI::wrap(PVStructurePtr const & pvStructure)
{
if(!isCompatible(pvStructure)) return shared_pointer();
return wrapUnsafe(pvStructure);
}
NTURI::shared_pointer NTURI::wrapUnsafe(PVStructurePtr const & pvStructure)
{
return shared_pointer(new NTURI(pvStructure));
}
bool NTURI::is_a(StructureConstPtr const & structure)
{
return NTUtils::is_a(structure->getID(), URI);
}
bool NTURI::is_a(PVStructurePtr const & pvStructure)
{
return is_a(pvStructure->getStructure());
}
bool NTURI::isCompatible(StructureConstPtr const & structure)
{
if (!structure.get()) return false;
ScalarConstPtr schemeField = structure->getField<Scalar>("scheme");
if (schemeField.get() == 0 || schemeField->getScalarType() != pvString)
return false;
ScalarConstPtr pathField = structure->getField<Scalar>("path");
if (pathField.get() == 0 || pathField->getScalarType() != pvString)
return false;
FieldConstPtr field = structure->getField("authority");
if (field.get())
{
ScalarConstPtr authorityField = structure->getField<Scalar>("authority");
if (!authorityField.get() || authorityField->getScalarType() != pvString)
return false;
}
field = structure->getField("query");
if (field.get())
{
StructureConstPtr queryField = structure->getField<Structure>("query");
if (!queryField.get())
return false;
FieldConstPtrArray const & fields = queryField->getFields();
for (FieldConstPtrArray::const_iterator it = fields.begin();
it != fields.end(); ++it)
{
if ((*it)->getType() != scalar) return false;
ScalarType scalarType = std::tr1::dynamic_pointer_cast<const Scalar>(
(*it))->getScalarType();
if (scalarType != pvString &&
scalarType != pvInt &&
scalarType != pvDouble) return false;
}
}
return true;
}
bool NTURI::isCompatible(PVStructurePtr const & pvStructure)
{
if(!pvStructure) return false;
return isCompatible(pvStructure->getStructure());
}
bool NTURI::isValid()
{
return true;
}
NTURIBuilderPtr NTURI::createBuilder()
{
return NTURIBuilderPtr(new detail::NTURIBuilder());
}
PVStructurePtr NTURI::getPVStructure() const
{
return pvNTURI;
}
PVStringPtr NTURI::getScheme() const
{
return pvNTURI->getSubField<PVString>("scheme");
}
PVStringPtr NTURI::getAuthority() const
{
return pvNTURI->getSubField<PVString>("authority");
}
PVStringPtr NTURI::getPath() const
{
return pvNTURI->getSubField<PVString>("path");
}
PVStructurePtr NTURI::getQuery() const
{
return pvNTURI->getSubField<PVStructure>("query");
}
StringArray const & NTURI::getQueryNames() const
{
return pvNTURI->getSubField<PVStructure>("query")->getStructure()->getFieldNames();
}
PVFieldPtr NTURI::getQueryField(std::string const & name) const
{
return pvNTURI->getSubField("query." + name);
}
NTURI::NTURI(PVStructurePtr const & pvStructure) :
pvNTURI(pvStructure)
{}
}}

27
src/ntutils.cpp Normal file
View File

@@ -0,0 +1,27 @@
/* ntutils.cpp */
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#define epicsExportSharedSymbols
#include <pv/ntutils.h>
using namespace std;
namespace epics { namespace nt {
bool NTUtils::is_a(const std::string &u1, const std::string &u2)
{
// remove minor for the u1
size_t pos1 = u1.find_last_of('.');
std::string su1 = (pos1 == string::npos) ? u1 : u1.substr(0, pos1);
// remove minor for the u2
size_t pos2 = u2.find_last_of('.');
std::string su2 = (pos2 == string::npos) ? u2 : u2.substr(0, pos2);
return su2 == su1;
}
}}

37
src/pv/nt.h Normal file
View File

@@ -0,0 +1,37 @@
/* nt.h */
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#ifndef NT_H
#define NT_H
/*
* Include all the normative types here.
*/
#include <pv/ntfield.h>
#include <pv/ntscalar.h>
#include <pv/ntscalarArray.h>
#include <pv/ntnameValue.h>
#include <pv/nttable.h>
#include <pv/ntndarray.h>
#include <pv/ntmultiChannel.h>
#include <pv/ntscalarMultiChannel.h>
#include <pv/ntmatrix.h>
#include <pv/ntenum.h>
#include <pv/ntunion.h>
#include <pv/ntaggregate.h>
#include <pv/ntattribute.h>
#include <pv/ntcontinuum.h>
#include <pv/nthistogram.h>
#include <pv/nturi.h>
#include <pv/ntndarrayAttribute.h>
#endif /* NT_H */
/** @page Overview Documentation
*
* <a href = "ntCPP.html">ntCPP.html</a>
*
*/

372
src/pv/ntaggregate.h Normal file
View File

@@ -0,0 +1,372 @@
/* ntaggregate.h */
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#ifndef NTAGGREGATE_H
#define NTAGGREGATE_H
#ifdef epicsExportSharedSymbols
# define ntaggregateEpicsExportSharedSymbols
# undef epicsExportSharedSymbols
#endif
#ifdef ntaggregateEpicsExportSharedSymbols
# define epicsExportSharedSymbols
# undef ntaggregateEpicsExportSharedSymbols
#endif
#include <pv/ntfield.h>
#include <shareLib.h>
namespace epics { namespace nt {
class NTAggregate;
typedef std::tr1::shared_ptr<NTAggregate> NTAggregatePtr;
namespace detail {
/**
* @brief Interface for in-line creating of NTAggregate.
*
* One instance can be used to create multiple instances.
* An instance of this object must not be used concurrently (an object has a state).
* @author dgh
*/
class epicsShareClass NTAggregateBuilder :
public std::tr1::enable_shared_from_this<NTAggregateBuilder>
{
public:
POINTER_DEFINITIONS(NTAggregateBuilder);
/**
* Adds dispersion field to the NTAggregate.
* @return this instance of <b>NTAggregateBuilder</b>.
*/
shared_pointer addDispersion();
/**
* Adds first field to the NTAggregate.
* @return this instance of <b>NTAggregateBuilder</b>.
*/
shared_pointer addFirst();
/**
* Adds firstTimeStamp field to the NTAggregate.
* @return this instance of <b>NTAggregateBuilder</b>.
*/
shared_pointer addFirstTimeStamp();
/**
* Adds last field to the NTAggregate.
* @return this instance of <b>NTAggregateBuilder</b>.
*/
shared_pointer addLast();
/**
* Adds lastTimeStamp field to the NTAggregate.
* @return this instance of <b>NTAggregateBuilder</b>.
*/
shared_pointer addLastTimeStamp();
/**
* Adds max field to the NTAggregate.
* @return this instance of <b>NTAggregateBuilder</b>.
*/
shared_pointer addMax();
/**
* Adds min field to the NTAggregate.
* @return this instance of <b>NTAggregateBuilder</b>.
*/
shared_pointer addMin();
/**
* Adds descriptor field to the NTAggregate.
* @return this instance of <b>NTAggregateBuilder</b>.
*/
shared_pointer addDescriptor();
/**
* Adds alarm field to the NTAggregate.
* @return this instance of <b>NTAggregateBuilder</b>.
*/
shared_pointer addAlarm();
/**
* Adds timeStamp field to the NTAggregate.
* @return this instance of <b>NTAggregateBuilder</b>.
*/
shared_pointer addTimeStamp();
/**
* Creates a <b>Structure</b> that represents NTAggregate.
* This resets this instance state and allows new instance to be created.
* @return a new instance of a <b>Structure</b>.
*/
epics::pvData::StructureConstPtr createStructure();
/**
* Creates a <b>PVStructure</b> that represents NTAggregate.
* This resets this instance state and allows new instance to be created.
* @return a new instance of a <b>PVStructure</b>.
*/
epics::pvData::PVStructurePtr createPVStructure();
/**
* Creates a <b>NTAggregate</b> instance.
* This resets this instance state and allows new instance to be created.
* @return a new instance of a <b>NTAggregate</b>.
*/
NTAggregatePtr create();
/**
* Adds extra <b>Field</b> to the type.
* @param name the name of the field.
* @param field the field to be added.
* @return this instance of <b>NTAggregateBuilder</b>.
*/
shared_pointer add(std::string const & name, epics::pvData::FieldConstPtr const & field);
private:
NTAggregateBuilder();
void reset();
bool dispersion;
bool first;
bool firstTimeStamp;
bool last;
bool lastTimeStamp;
bool max;
bool min;
bool descriptor;
bool alarm;
bool timeStamp;
// NOTE: this preserves order, however it does not handle duplicates
epics::pvData::StringArray extraFieldNames;
epics::pvData::FieldConstPtrArray extraFields;
friend class ::epics::nt::NTAggregate;
};
}
typedef std::tr1::shared_ptr<detail::NTAggregateBuilder> NTAggregateBuilderPtr;
/**
* @brief Convenience Class for NTAggregate
*
* @author dgh
*/
class epicsShareClass NTAggregate
{
public:
POINTER_DEFINITIONS(NTAggregate);
static const std::string URI;
/**
* Creates an NTAggregate wrapping the specified PVStructure if the latter is compatible.
* <p>
* Checks the supplied PVStructure is compatible with NTAggregate
* and if so returns an NTAggregate which wraps it.
* This method will return null if the structure is is not compatible
* or is null.
*
* @param pvStructure the PVStructure to be wrapped
* @return the NTAggregate instance on success, null otherwise
*/
static shared_pointer wrap(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Creates an NTAggregate wrapping the specified PVStructure, regardless of the latter's compatibility.
* <p>
* No checks are made as to whether the specified PVStructure
* is compatible with NTAggregate or is non-null.
*
* @param pvStructure the PVStructure to be wrapped
* @return the NTAggregate instance
*/
static shared_pointer wrapUnsafe(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Returns whether the specified Structure reports to be a compatible NTAggregate.
* <p>
* Checks if the specified Structure reports compatibility with this
* version of NTAggregate through its type ID, including checking version numbers.
* The return value does not depend on whether the structure is actually
* compatible in terms of its introspection type.
*
* @param structure the Structure to test
* @return (false,true) if the specified Structure (is not, is) a compatible NTAggregate
*/
static bool is_a(epics::pvData::StructureConstPtr const & structure);
/**
* Returns whether the specified PVStructure reports to be a compatible NTAggregate.
* <p>
* Checks if the specified PVStructure reports compatibility with this
* version of NTAggregate through its type ID, including checking version numbers.
* The return value does not depend on whether the structure is actually
* compatible in terms of its introspection type.
*
* @param pvStructure the PVStructure to test.
* @return (false,true) if the specified PVStructure (is not, is) a compatible NTAggregate.
*/
static bool is_a(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Returns whether the specified Structure is compatible with NTAggregate.
* <p>
* Checks if the specified Structure is compatible with this version
* of NTAggregate through introspection interface.
*
* @param structure the Structure to test
* @return (false,true) if the specified Structure (is not, is) a compatible NTAggregate
*/
static bool isCompatible(
epics::pvData::StructureConstPtr const &structure);
/**
* Returns whether the specified PVStructure is compatible with NTAggregate.
* <p>
* Checks if the specified PVStructure is compatible with this version
* of NTAggregate through introspection interface.
*
* @param pvStructure the PVStructure to test
* @return (false,true) if the specified PVStructure (is not, is) a compatible NTAggregate
*/
static bool isCompatible(
epics::pvData::PVStructurePtr const &pvStructure);
/**
* Returns whether the wrapped PVStructure is valid with respect to this
* version of NTAggregate.
* <p>
* Unlike isCompatible(), isValid() may perform checks on the value data as
* well as the introspection data.
*
* @return (false,true) if wrapped PVStructure a valid NTAggregate
*/
bool isValid();
/**
* Creates an NTAggregate builder instance.
* @return builder instance.
*/
static NTAggregateBuilderPtr createBuilder();
/**
* Destructor.
*/
~NTAggregate() {}
/**
* Attaches a PVTimeStamp to the wrapped PVStructure.
* Does nothing if no timeStamp field.
* @param pvTimeStamp the PVTimeStamp that will be attached.
* @return true if the operation was successfull (i.e. this instance has a timeStamp field), otherwise false.
*/
bool attachTimeStamp(epics::pvData::PVTimeStamp &pvTimeStamp) const;
/**
* Attaches a PVAlarm to the wrapped PVStructure.
* Does nothing if no alarm field.
* @param pvAlarm the PVAlarm that will be attached.
* @return true if the operation was successfull (i.e. this instance has an alarm field), otherwise false.
*/
bool attachAlarm(epics::pvData::PVAlarm &pvAlarm) const;
/**
* Returns the PVStructure wrapped by this instance.
* @return the PVStructure wrapped by this instance.
*/
epics::pvData::PVStructurePtr getPVStructure() const;
/**
* Returns the descriptor field.
* @return the descriptor field or null if no such field.
*/
epics::pvData::PVStringPtr getDescriptor() const;
/**
* Returns the timeStamp field.
* @return the timStamp field or null if no such field.
*/
epics::pvData::PVStructurePtr getTimeStamp() const;
/**
* Returns the alarm field.
* @return the alarm field or null if no such field.
*/
epics::pvData::PVStructurePtr getAlarm() const;
/**
* Returns the value field.
* @return the value field.
*/
epics::pvData::PVDoublePtr getValue() const;
/**
* Returns the N field.
* @return the N field.
*/
epics::pvData::PVLongPtr getN() const;
/**
* Returns the dispersion field.
* @return the dispersion or null if no such field.
*/
epics::pvData::PVDoublePtr getDispersion() const;
/**
* Returns the first field.
* @return the first field or null if no such field.
*/
epics::pvData::PVDoublePtr getFirst() const;
/**
* Returns the firstTimeStamp field.
* @return the firstTimeStamp field or null if no such field.
*/
epics::pvData::PVStructurePtr getFirstTimeStamp() const;
/**
* Returns the last field.
* @return the last field or null if no such field.
*/
epics::pvData::PVDoublePtr getLast() const;
/**
* Returns the lastTimeStamp field.
* @return the lastTimeStamp field or null if no such field.
*/
epics::pvData::PVStructurePtr getLastTimeStamp() const;
/**
* Returns the max field.
* @return the max field or null if no such field.
*/
epics::pvData::PVDoublePtr getMax() const;
/**
* Returns the min field.
* @return the min field or null if no such field.
*/
epics::pvData::PVDoublePtr getMin() const;
private:
NTAggregate(epics::pvData::PVStructurePtr const & pvStructure);
epics::pvData::PVStructurePtr pvNTAggregate;
epics::pvData::PVDoublePtr pvValue;
friend class detail::NTAggregateBuilder;
};
}}
#endif /* NTAGGREGATE_H */

294
src/pv/ntattribute.h Normal file
View File

@@ -0,0 +1,294 @@
/* ntattribute.h */
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#ifndef NTATTRIBUTE_H
#define NTATTRIBUTE_H
#ifdef epicsExportSharedSymbols
# define ntattributeEpicsExportSharedSymbols
# undef epicsExportSharedSymbols
#endif
#ifdef ntattributeEpicsExportSharedSymbols
# define epicsExportSharedSymbols
# undef ntattributeEpicsExportSharedSymbols
#endif
#include <pv/ntfield.h>
#include <shareLib.h>
namespace epics { namespace nt {
class NTAttribute;
typedef std::tr1::shared_ptr<NTAttribute> NTAttributePtr;
namespace detail {
/**
* @brief Interface for in-line creating of NTAttribute.
*
* One instance can be used to create multiple instances.
* An instance of this object must not be used concurrently (an object has a state).
* @author dgh
*/
class epicsShareClass NTAttributeBuilder :
public std::tr1::enable_shared_from_this<NTAttributeBuilder>
{
public:
POINTER_DEFINITIONS(NTAttributeBuilder);
/**
* Adds tags field to the NTAttribute.
* @return this instance of <b>NTAttributeBuilder</b>.
*/
shared_pointer addTags();
/**
* Adds descriptor field to the NTAttribute.
* @return this instance of <b>NTAttributeBuilder</b>.
*/
shared_pointer addDescriptor();
/**
* Adds alarm field to the NTAttribute.
* @return this instance of <b>NTAttributeBuilder</b>.
*/
shared_pointer addAlarm();
/**
* Adds timeStamp field to the NTAttribute.
* @return this instance of <b>NTAttributeBuilder</b>.
*/
shared_pointer addTimeStamp();
/**
* Creates a <b>Structure</b> that represents NTAttribute.
* This resets this instance state and allows new instance to be created.
* @return a new instance of a <b>Structure</b>.
*/
epics::pvData::StructureConstPtr createStructure();
/**
* Creates a <b>PVStructure</b> that represents NTAttribute.
* This resets this instance state and allows new instance to be created.
* @return a new instance of a <b>PVStructure</b>.
*/
epics::pvData::PVStructurePtr createPVStructure();
/**
* Creates a <b>NTAttribute</b> instance.
* This resets this instance state and allows new instance to be created.
* @return a new instance of a <b>NTAttribute</b>.
*/
NTAttributePtr create();
/**
* Adds extra <b>Field</b> to the type.
* @param name the name of the field.
* @param field the field to be added.
* @return this instance of <b>NTAttributeBuilder</b>.
*/
shared_pointer add(std::string const & name, epics::pvData::FieldConstPtr const & field);
protected://private:
NTAttributeBuilder();
void reset();
bool tags;
bool descriptor;
bool alarm;
bool timeStamp;
// NOTE: this preserves order, however it does not handle duplicates
epics::pvData::StringArray extraFieldNames;
epics::pvData::FieldConstPtrArray extraFields;
friend class ::epics::nt::NTAttribute;
};
}
typedef std::tr1::shared_ptr<detail::NTAttributeBuilder> NTAttributeBuilderPtr;
/**
* @brief Convenience Class for NTAttribute
*
* @author dgh
*/
class epicsShareClass NTAttribute
{
public:
POINTER_DEFINITIONS(NTAttribute);
static const std::string URI;
/**
* Creates an NTAttribute wrapping the specified PVStructure if the latter is compatible.
* <p>
* Checks the supplied PVStructure is compatible with NTAttribute
* and if so returns an NTAttribute which wraps it.
* This method will return null if the structure is is not compatible
* or is null.
*
* @param pvStructure the PVStructure to be wrapped
* @return NTAttribute instance wrapping pvStructure on success, null otherwise
*/
static shared_pointer wrap(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Creates an NTAttribute wrapping the specified PVStructure, regardless of the latter's compatibility.
* <p>
* No checks are made as to whether the specified PVStructure
* is compatible with NTAttribute or is non-null.
*
* @param pvStructure the PVStructure to be wrapped
* @return NTAttribute instance wrapping pvStructure
*/
static shared_pointer wrapUnsafe(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Returns whether the specified Structure reports to be a compatible NTAttribute.
* <p>
* Checks if the specified Structure reports compatibility with this
* version of NTAttribute through its type ID, including checking version numbers.
* The return value does not depend on whether the structure is actually
* compatible in terms of its introspection type.
*
* @param structure the Structure to test
* @return (false,true) if the specified Structure (is not, is) a compatible NTAttribute
*/
static bool is_a(epics::pvData::StructureConstPtr const & structure);
/**
* Returns whether the specified PVStructure reports to be a compatible NTAttribute.
* <p>
* Checks if the specified PVStructure reports compatibility with this
* version of NTAttribute through its type ID, including checking version numbers.
* The return value does not depend on whether the structure is actually
* compatible in terms of its introspection type.
*
* @param pvStructure the PVStructure to test
* @return (false,true) if the specified PVStructure (is not, is) a compatible NTAttribute
*/
static bool is_a(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Returns whether the specified Structure is compatible with NTAttribute.
* <p>
* Checks if the specified Structure is compatible with this version
* of NTAttribute through the introspection interface.
*
* @param structure the Structure to test
* @return (false,true) if the specified Structure (is not, is) a compatible NTAttribute
*/
static bool isCompatible(
epics::pvData::StructureConstPtr const &structure);
/**
* Returns whether the specified PVStructure is compatible with NTAttribute.
* <p>
* Checks if the specified tructure is compatible with this version
* of NTAttribute through the introspection interface.
* @param pvStructure the PVStructure to test
* @return (false,true) if the specified PVStructure (is not, is) a compatible NTAttribute
*/
static bool isCompatible(
epics::pvData::PVStructurePtr const &pvStructure);
/**
* Returns whether the wrapped PVStructure is valid with respect to this
* version of NTAttribute.
* <p>
* Unlike isCompatible(), isValid() may perform checks on the value
* data as well as the introspection data.
*
* @return (false,true) if the wrapped PVStructure (is not, is) a valid NTAttribute
*/
bool isValid();
/**
* Creates an NTAttribute builder instance.
* @return builder instance.
*/
static NTAttributeBuilderPtr createBuilder();
/**
* Destructor.
*/
~NTAttribute() {}
/**
* Attaches a PVTimeStamp to the wrapped PVStructure.
* Does nothing if no timeStamp field.
* @param pvTimeStamp the PVTimeStamp that will be attached.
* @return true if the operation was successfull (i.e. this instance has a timeStamp field), otherwise false.
*/
bool attachTimeStamp(epics::pvData::PVTimeStamp &pvTimeStamp) const;
/**
* Attaches a PVAlarm to the wrapped PVStructure.
* Does nothing if no alarm field.
* @param pvAlarm the PVAlarm that will be attached.
* @return true if the operation was successfull (i.e. this instance has an alarm field), otherwise false.
*/
bool attachAlarm(epics::pvData::PVAlarm &pvAlarm) const;
/**
* Returns the PVStructure wrapped by this instance.
* @return the PVStructure wrapped by this instance.
*/
epics::pvData::PVStructurePtr getPVStructure() const;
/**
* Returns the descriptor field.
* @return the descriptor field or null if no such field.
*/
epics::pvData::PVStringPtr getDescriptor() const;
/**
* Returns the timeStamp field.
* @return the timStamp field or null if no such field.
*/
epics::pvData::PVStructurePtr getTimeStamp() const;
/**
* Returns the alarm field.
* @return the alarm field or null if no such field.
*/
epics::pvData::PVStructurePtr getAlarm() const;
/**
* Returns the name field.
* @return the name field.
*/
epics::pvData::PVStringPtr getName() const;
/**
* Returns the value field.
* @return the value field.
*/
epics::pvData::PVUnionPtr getValue() const;
/**
* Returns the tags field.
* @return the tags field or null if no such field.
*/
epics::pvData::PVStringArrayPtr getTags() const;
private:
NTAttribute(epics::pvData::PVStructurePtr const & pvStructure);
epics::pvData::PVStructurePtr pvNTAttribute;
epics::pvData::PVUnionPtr pvValue;
friend class detail::NTAttributeBuilder;
};
}}
#endif /* NTATTRIBUTE_H */

288
src/pv/ntcontinuum.h Normal file
View File

@@ -0,0 +1,288 @@
/* ntcontinuum.h */
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#ifndef NTCONTINUUM_H
#define NTCONTINUUM_H
#ifdef epicsExportSharedSymbols
# define ntcontinuumEpicsExportSharedSymbols
# undef epicsExportSharedSymbols
#endif
#ifdef ntcontinuumEpicsExportSharedSymbols
# define epicsExportSharedSymbols
# undef ntcontinuumEpicsExportSharedSymbols
#endif
#include <pv/ntfield.h>
#include <shareLib.h>
namespace epics { namespace nt {
class NTContinuum;
typedef std::tr1::shared_ptr<NTContinuum> NTContinuumPtr;
namespace detail {
/**
* @brief Interface for in-line creating of NTContinuum.
*
* One instance can be used to create multiple instances.
* An instance of this object must not be used concurrently (an object has a state).
* @author dgh
*/
class epicsShareClass NTContinuumBuilder :
public std::tr1::enable_shared_from_this<NTContinuumBuilder>
{
public:
POINTER_DEFINITIONS(NTContinuumBuilder);
/**
* Adds descriptor field to the NTContinuum.
* @return this instance of <b>NTContinuumBuilder</b>.
*/
shared_pointer addDescriptor();
/**
* Adds alarm field to the NTContinuum.
* @return this instance of <b>NTContinuumBuilder</b>.
*/
shared_pointer addAlarm();
/**
* Adds timeStamp field to the NTContinuum.
* @return this instance of <b>NTContinuumBuilder</b>.
*/
shared_pointer addTimeStamp();
/**
* Creates a <b>Structure</b> that represents NTContinuum.
* This resets this instance state and allows new instance to be created.
* @return a new instance of <b>Structure</b>.
*/
epics::pvData::StructureConstPtr createStructure();
/**
* Creates a <b>PVStructure</b> that represents NTContinuum.
* This resets this instance state and allows new instance to be created.
* @return a new instance of <b>PVStructure</b>.
*/
epics::pvData::PVStructurePtr createPVStructure();
/**
* Creates a <b>NTContinuum</b> instance.
* This resets this instance state and allows new instance to be created.
* @return a new instance of <b>NTContinuum</b>.
*/
NTContinuumPtr create();
/**
* Adds extra <b>Field</b> to the type.
* @param name the name of the field.
* @param field the field to be added.
* @return this instance of <b>NTContinuumBuilder</b>.
*/
shared_pointer add(std::string const & name, epics::pvData::FieldConstPtr const & field);
private:
NTContinuumBuilder();
void reset();
bool descriptor;
bool alarm;
bool timeStamp;
// NOTE: this preserves order, however it does not handle duplicates
epics::pvData::StringArray extraFieldNames;
epics::pvData::FieldConstPtrArray extraFields;
friend class ::epics::nt::NTContinuum;
};
}
typedef std::tr1::shared_ptr<detail::NTContinuumBuilder> NTContinuumBuilderPtr;
/**
* @brief Convenience Class for NTContinuum
*
* @author dgh
*/
class epicsShareClass NTContinuum
{
public:
POINTER_DEFINITIONS(NTContinuum);
static const std::string URI;
/**
* Creates an NTContinuum wrapping the specified PVStructure if the latter is compatible.
* <p>
* Checks the supplied structure is compatible with NTContinuum
* and if so returns an NTContinuum which wraps it.
* This method will return null if the structure is is not compatible
* or is null.
*
* @param pvStructure the PVStructure to be wrapped
* @return NTContinuum instance wrapping pvStructure on success, null otherwise
*/
static shared_pointer wrap(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Creates an NTContinuum wrapping the specified PVStructure, regardless of the latter's compatibility.
* <p>
* No checks are made as to whether the specified PVStructure
* is compatible with NTContinuum or is non-null.
*
* @param pvStructure the PVStructure to be wrapped
* @return NTContinuum instance wrapping pvStructure.
*/
static shared_pointer wrapUnsafe(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Returns whether the specified Structure reports to be a compatible NTContinuum.
* <p>
* Checks if the specified Structure reports compatibility with this
* version of NTContinuum through its type ID, including checking version numbers.
* The return value does not depend on whether the structure is actually
* compatible in terms of its introspection type
*
* @param structure the Structure to test
* @return (false,true) if the specified Structure (is not, is) a compatible NTContinuum
*/
static bool is_a(epics::pvData::StructureConstPtr const & structure);
/**
* Returns whether the specified PVStructure reports to be a compatible NTContinuum.
* <p>
* Checks if the specified Structure reports compatibility with this
* version of NTContinuum through its type ID, including checking version numbers.
* The return value does not depend on whether the structure is actually
* compatible in terms of its introspection type
*
* @param pvStructure The PVStructure to test
* @return (false,true) if the specified PVStructure (is not, is) a compatible NTContinuum
*/
static bool is_a(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Returns whether the specified Structure is compatible with NTContinuum.
* <p>
* Checks if the specified Structure is compatible with this version
* of NTContinuum through the introspection interface.
*
* @param structure the Structure to test
* @return (false,true) if the specified Structure (is not, is) a compatible NTContinuum
*/
static bool isCompatible(
epics::pvData::StructureConstPtr const &structure);
/**
* Returns whether the specified PVStructure is compatible with NTContinuum.
* <p>
* Checks if the specified PVStructure is compatible with this version
* of NTContinuum through the introspection interface.
*
* @param pvStructure the PVStructure to test
* @return (false,true) if the specified PVStructure (is not, is) a compatible NTContinuum
*/
static bool isCompatible(
epics::pvData::PVStructurePtr const &pvStructure);
/**
* Returns whether the wrapped structure is valid with respect to this
* version of NTContinuum.
* <p>
* Unlike isCompatible(), isValid() may perform checks on the value
* data as well as the introspection data.
*
* @return (false,true) if the wrapped PVStructure (is not, is) a valid NTContinuum
*/
bool isValid();
/**
* Creates an NTContinuum builder instance.
* @return builder instance.
*/
static NTContinuumBuilderPtr createBuilder();
/**
* Destructor.
*/
~NTContinuum() {}
/**
* Attaches a PVTimeStamp to the wrapped PVStructure.
* Does nothing if no timeStamp field.
* @param pvTimeStamp the PVTimeStamp that will be attached.
* @return true if the operation was successfull (i.e. this instance has a timeStamp field), otherwise false.
*/
bool attachTimeStamp(epics::pvData::PVTimeStamp &pvTimeStamp) const;
/**
* Attaches a PVAlarm to the wrapped PVStructure.
* Does nothing if no alarm field.
* @param pvAlarm the PVAlarm that will be attached.
* @return true if the operation was successfull (i.e. this instance has an alarm field), otherwise false.
*/
bool attachAlarm(epics::pvData::PVAlarm &pvAlarm) const;
/**
* Returns the PVStructure wrapped by this instance.
* @return the PVStructure wrapped by this instance.
*/
epics::pvData::PVStructurePtr getPVStructure() const;
/**
* Returns the descriptor field.
* @return the descriptor field or null if no such field.
*/
epics::pvData::PVStringPtr getDescriptor() const;
/**
* Returns the timeStamp field.
* @return the timStamp field or null if no such field.
*/
epics::pvData::PVStructurePtr getTimeStamp() const;
/**
* Returns the alarm field.
* @return the alarm field or null if no such field.
*/
epics::pvData::PVStructurePtr getAlarm() const;
/**
* Returns the base field.
* @return the base field.
*/
epics::pvData::PVDoubleArrayPtr getBase() const;
/**
* Returns the value field.
* @return the value field.
*/
epics::pvData::PVDoubleArrayPtr getValue() const;
/**
* Returns the units field.
* @return the units field.
*/
epics::pvData::PVStringArrayPtr getUnits() const;
private:
NTContinuum(epics::pvData::PVStructurePtr const & pvStructure);
epics::pvData::PVStructurePtr pvNTContinuum;
epics::pvData::PVDoubleArrayPtr pvValue;
friend class detail::NTContinuumBuilder;
};
}}
#endif /* NTCONTINUUM_H */

273
src/pv/ntenum.h Normal file
View File

@@ -0,0 +1,273 @@
/* ntenum.h */
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#ifndef NTENUM_H
#define NTENUM_H
#ifdef epicsExportSharedSymbols
# define ntenumEpicsExportSharedSymbols
# undef epicsExportSharedSymbols
#endif
#ifdef ntenumEpicsExportSharedSymbols
# define epicsExportSharedSymbols
# undef ntenumEpicsExportSharedSymbols
#endif
#include <pv/ntfield.h>
#include <shareLib.h>
namespace epics { namespace nt {
class NTEnum;
typedef std::tr1::shared_ptr<NTEnum> NTEnumPtr;
namespace detail {
/**
* @brief Interface for in-line creating of NTEnum.
*
* One instance can be used to create multiple instances.
* An instance of this object must not be used concurrently (an object has a state).
* @author dgh
*/
class epicsShareClass NTEnumBuilder :
public std::tr1::enable_shared_from_this<NTEnumBuilder>
{
public:
POINTER_DEFINITIONS(NTEnumBuilder);
/**
* Adds descriptor field to the NTEnum.
* @return this instance of <b>NTEnumBuilder</b>.
*/
shared_pointer addDescriptor();
/**
* Adds alarm field to the NTEnum.
* @return this instance of <b>NTEnumBuilder</b>.
*/
shared_pointer addAlarm();
/**
* Adds timeStamp field to the NTEnum.
* @return this instance of <b>NTEnumBuilder</b>.
*/
shared_pointer addTimeStamp();
/**
* Creates a <b>Structure</b> that represents NTEnum.
* This resets this instance state and allows new instance to be created.
* @return a new instance of a <b>Structure</b>.
*/
epics::pvData::StructureConstPtr createStructure();
/**
* Creates a <b>PVStructure</b> that represents NTEnum.
* This resets this instance state and allows new instance to be created.
* @return a new instance of a <b>PVStructure</b>.
*/
epics::pvData::PVStructurePtr createPVStructure();
/**
* Creates a <b>NTEnum</b> instance.
* This resets this instance state and allows new instance to be created.
* @return a new instance of a <b>NTEnum</b>.
*/
NTEnumPtr create();
/**
* Adds extra <b>Field</b> to the type.
* @param name the name of the field.
* @param field the field to be added.
* @return this instance of <b>NTEnumBuilder</b>.
*/
shared_pointer add(std::string const & name, epics::pvData::FieldConstPtr const & field);
private:
NTEnumBuilder();
void reset();
bool descriptor;
bool alarm;
bool timeStamp;
// NOTE: this preserves order, however it does not handle duplicates
epics::pvData::StringArray extraFieldNames;
epics::pvData::FieldConstPtrArray extraFields;
friend class ::epics::nt::NTEnum;
};
}
typedef std::tr1::shared_ptr<detail::NTEnumBuilder> NTEnumBuilderPtr;
/**
* @brief Convenience Class for NTEnum
*
* @author dgh
*/
class epicsShareClass NTEnum
{
public:
POINTER_DEFINITIONS(NTEnum);
static const std::string URI;
/**
* Creates an NTEnum wrapping the specified PVStructure, regardless of the latter's compatibility.
* <p>
* No checks are made as to whether the specified PVStructure
* is compatible with NTEnum or is non-null.
*
* @param pvStructure the PVStructure to be wrapped
* @return NTEnum instance wrapping pvStructure
*/
static shared_pointer wrap(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Creates an NTEnum wrapping the specified PVStructure, regardless of the latter's compatibility.
* <p>
* No checks are made as to whether the specified PVStructure
* is compatible with NTEnum or is non-null.
*
* @param pvStructure the PVStructure to be wrapped
* @return NTEnum instance wrapping pvStructure
*/
static shared_pointer wrapUnsafe(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Returns whether the specified Structure reports to be a compatible NTEnum.
* <p>
* Checks if the specified Structure reports compatibility with this
* version of NTEnum through its type ID, including checking version numbers.
* The return value does not depend on whether the structure is actually
* compatible in terms of its introspection type.
*
* @param structure the Structure to test.
* @return (false,true) if the specified Structure (is not, is) a compatible NTEnum.
*/
static bool is_a(epics::pvData::StructureConstPtr const & structure);
/**
* Returns whether the specified PVStructure reports to be a compatible NTEnum.
* <p>
* Checks if the specified PVStructure reports compatibility with this
* version of NTEnum through its type ID, including checking version numbers.
* The return value does not depend on whether the structure is actually
* compatible in terms of its introspection type.
*
* @param pvStructure the PVStructure to test
* @return (false,true) if the specified PVStructure (is not, is) a compatible NTEnum
*/
static bool is_a(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Returns whether the specified Structure is compatible with NTEnum.
* <p>
* Checks if the specified Structure is compatible with this version
* of NTEnum through the introspection interface.
*
* @param structure The Structure to test
* @return (false,true) if the specified Structure (is not, is) a compatible NTEnum
*/
static bool isCompatible(
epics::pvData::StructureConstPtr const &structure);
/**
* Returns whether the specified PVStructure is compatible with NTEnum.
* <p>
* Checks if the specified PVStructure is compatible with this version
* of NTEnum through the introspection interface.
*
* @param pvStructure the PVStructure to test
* @return (false,true) if the specified PVStructure (is not, is) a compatible NTEnum
*/
static bool isCompatible(
epics::pvData::PVStructurePtr const &pvStructure);
/**
* Returns whether the wrapped PVStructure is valid with respect to this
* version of NTEnum.
* <p>
* Unlike isCompatible(), isValid() may perform checks on the value
* data as well as the introspection data.
*
* @return (false,true) if the wrapped PVStructure (is not, is) a valid NTEnum
*/
bool isValid();
/**
* Creates an NTEnum builder instance.
* @return builder instance.
*/
static NTEnumBuilderPtr createBuilder();
/**
* Destructor.
*/
~NTEnum() {}
/**
* Attaches a PVTimeStamp to the wrapped PVStructure.
* Does nothing if no timeStamp field.
* @param pvTimeStamp the PVTimeStamp that will be attached.
* @return true if the operation was successfull (i.e. this instance has a timeStamp field), otherwise false.
*/
bool attachTimeStamp(epics::pvData::PVTimeStamp &pvTimeStamp) const;
/**
* Attaches a PVAlarm to the wrapped PVStructure.
* Does nothing if no alarm field.
* @param pvAlarm the PVAlarm that will be attached.
* @return true if the operation was successfull (i.e. this instance has an alarm field), otherwise false.
*/
bool attachAlarm(epics::pvData::PVAlarm &pvAlarm) const;
/**
* Returns the PVStructure wrapped by this instance.
* @return the PVStructure wrapped by this instance.
*/
epics::pvData::PVStructurePtr getPVStructure() const;
/**
* Returns the descriptor field.
* @return the descriptor field or null if no such field.
*/
epics::pvData::PVStringPtr getDescriptor() const;
/**
* Returns the timeStamp field.
* @return the timStamp field or or null if no such field.
*/
epics::pvData::PVStructurePtr getTimeStamp() const;
/**
* Returns the alarm field.
* @return the alarm field or or null if no such field.
*/
epics::pvData::PVStructurePtr getAlarm() const;
/**
* Get the value field.
* @return the value field.
*/
epics::pvData::PVStructurePtr getValue() const;
private:
NTEnum(epics::pvData::PVStructurePtr const & pvStructure);
epics::pvData::PVStructurePtr pvNTEnum;
epics::pvData::PVStructurePtr pvValue;
friend class detail::NTEnumBuilder;
};
}}
#endif /* NTENUM_H */

View File

@@ -1,8 +1,7 @@
/* ntfield.h */
/**
* Copyright - See the COPYRIGHT that is included with this distribution.
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#ifndef NTFIELD_H
#define NTFIELD_H
@@ -30,11 +29,6 @@
#include <shareLib.h>
namespace epics { namespace nt {
/**
* Convenience Class for introspection fields of a Normative Type
* @author mrk
*
*/
class NTField;
typedef std::tr1::shared_ptr<NTField> NTFieldPtr;
@@ -42,11 +36,17 @@ typedef std::tr1::shared_ptr<NTField> NTFieldPtr;
class PVNTField;
typedef std::tr1::shared_ptr<PVNTField> PVNTFieldPtr;
/**
* @brief Convenience Class for introspection fields of a Normative Type
*
* @author mrk
*
*/
class epicsShareClass NTField {
public:
POINTER_DEFINITIONS(NTField);
/**
* get the single implementation of this class.
* Gets the single implementation of this class.
* @return the implementation
*/
static NTFieldPtr get();
@@ -54,84 +54,97 @@ public:
* destructor
*/
~NTField() {}
/**
* Is field an enumerated structure.
* @param field The field to test.
* @param field the field to test.
* @return (false,true) if field (is not,is) an enumerated structure.
*/
bool isEnumerated(epics::pvData::FieldConstPtr const & field);
/**
* Is field a timeStamp structure.
* @param field The field to test.
* @param field the field to test.
* @return (false,true) if field (is not,is) a timeStamp structure.
*/
bool isTimeStamp(epics::pvData::FieldConstPtr const & field);
/**
* Is field an alarm structure.
* @param field The field to test.
* @param field the field to test.
* @return (false,true) if field (is not,is) an alarm structure.
*/
bool isAlarm(epics::pvData::FieldConstPtr const & field);
/**
* Is field a display structure.
* @param field The field to test.
* @param field the field to test.
* @return (false,true) if field (is not,is) a display structure.
*/
bool isDisplay(epics::pvData::FieldConstPtr const & field);
/**
* Is field an alarmLimit structure.
* @param field The field to test.
* @param field the field to test.
* @return (false,true) if field (is not,is) an alarmLimit structure.
*/
bool isAlarmLimit(epics::pvData::FieldConstPtr const & field);
/**
* Is field a control structure.
* @param field The field to test.
* @param field the field to test.
* @return (false,true) if field (is not,is) a control structure.
*/
bool isControl(epics::pvData::FieldConstPtr const & field);
/**
* Create an enumerated structure.
* Creates an enumerated structure.
* @return an enumerated structure.
*/
epics::pvData::StructureConstPtr createEnumerated();
/**
* Create a timeStamp structure.
* Creates a timeStamp structure.
* @return a timeStamp structure.
*/
epics::pvData::StructureConstPtr createTimeStamp();
/**
* Create an alarm structure.
* Creates an alarm structure.
* @return an alarm structure.
*/
epics::pvData::StructureConstPtr createAlarm();
/**
* Create a display structure.
* Creates a display structure.
* @return a displayalarm structure.
*/
epics::pvData::StructureConstPtr createDisplay();
/**
* Create a control structure.
* Creates a control structure.
* @return a control structure.
*/
epics::pvData::StructureConstPtr createControl();
/**
* Create an array of enumerated structures.
* Creates an array of enumerated structures.
* @return an array of enumerated structures.
*/
epics::pvData::StructureArrayConstPtr createEnumeratedArray();
/**
* Create an array of timeStamp structures.
* Creates an array of timeStamp structures.
* @return an array of timeStamp structures.
*/
epics::pvData::StructureArrayConstPtr createTimeStampArray();
/**
* Create an array of alarm structures.
* Creates an array of alarm structures.
* @return an array of alarm structures.
*/
epics::pvData::StructureArrayConstPtr createAlarmArray();
private:
NTField();
epics::pvData::FieldCreatePtr fieldCreate;
@@ -139,7 +152,8 @@ private:
};
/**
* Convenience Class for data fields of a Normative Type
* @brief Convenience Class for data fields of a Normative Type
*
* @author mrk
*
*/
@@ -147,62 +161,66 @@ class epicsShareClass PVNTField {
public:
POINTER_DEFINITIONS(PVNTField);
/**
* get the single implementation of this class.
* Returns the single implementation of this class.
* @return the implementation
*/
static PVNTFieldPtr get();
/**
* destructor
*/
~PVNTField() {}
/**
* Create an enumerated PVStructure.
* Creates an enumerated PVStructure.
* @param choices The array of choices.
* @return an enumerated PVStructure..
* @return an enumerated PVStructure.
*/
epics::pvData::PVStructurePtr createEnumerated(
epics::pvData::StringArray const & choices);
/**
* Create a timeStamp PVStructure.
* @return a timeStamp PVStructure..
* Creates a timeStamp PVStructure.
* @return a timeStamp PVStructure.
*/
epics::pvData::PVStructurePtr createTimeStamp();
/**
* Create an alarm PVStructure.
* @return an alarm PVStructure..
* Creates an alarm PVStructure.
* @return an alarm PVStructure.
*/
epics::pvData::PVStructurePtr createAlarm();
/**
* Create a display PVStructure.
* @return a display PVStructure..
* Creates a display PVStructure.
* @return a display PVStructure.
*/
epics::pvData::PVStructurePtr createDisplay();
/**
* Create an alarmLimit PVStructure.
* @return an alarmLimit PVStructure..
*/
epics::pvData::PVStructurePtr createAlarmLimit();
/**
* Create a control PVStructure.
* @return a control PVStructure..
* Creates a control PVStructure.
* @return a control PVStructure.
*/
epics::pvData::PVStructurePtr createControl();
/**
* Create an enumerated PVStructureArray.
* @return an enumerated PVStructureArray..
* Creates an enumerated PVStructureArray.
* @return an enumerated PVStructureArray.
*/
epics::pvData::PVStructureArrayPtr createEnumeratedArray();
/**
* Create a timeStamp PVStructureArray.
* @return a timeStamp PVStructureArray
* Creates a timeStamp PVStructureArray.
* @return a timeStamp PVStructureArray.
*/
epics::pvData::PVStructureArrayPtr createTimeStampArray();
/**
* Create an alarm PVStructureArray.
* @return an alarm PVStructureArray..
* Creates an alarm PVStructureArray.
* @return an alarm PVStructureArray.
*/
epics::pvData::PVStructureArrayPtr createAlarmArray();
private:
PVNTField();
epics::pvData::PVDataCreatePtr pvDataCreate;
@@ -212,4 +230,5 @@ private:
};
}}
#endif /* NTFIELD_H */

305
src/pv/nthistogram.h Normal file
View File

@@ -0,0 +1,305 @@
/* nthistogram.h */
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#ifndef NTHISTOGRAM_H
#define NTHISTOGRAM_H
#ifdef epicsExportSharedSymbols
# define nthistogramEpicsExportSharedSymbols
# undef epicsExportSharedSymbols
#endif
#ifdef nthistogramEpicsExportSharedSymbols
# define epicsExportSharedSymbols
# undef nthistogramEpicsExportSharedSymbols
#endif
#include <pv/ntfield.h>
#include <shareLib.h>
namespace epics { namespace nt {
class NTHistogram;
typedef std::tr1::shared_ptr<NTHistogram> NTHistogramPtr;
namespace detail {
/**
* @brief Interface for in-line creating of NTHistogram.
*
* One instance can be used to create multiple instances.
* An instance of this object must not be used concurrently (an object has a state).
* @author dgh
*/
class epicsShareClass NTHistogramBuilder :
public std::tr1::enable_shared_from_this<NTHistogramBuilder>
{
public:
POINTER_DEFINITIONS(NTHistogramBuilder);
/**
* Sets the scalar type of the value field array.
* @param scalarType the scalar type of the value field array.
* @return this instance of <b>NTHistogramBuilder</b>.
*/
shared_pointer value(epics::pvData::ScalarType scalarType);
/**
* Adds descriptor field to the NTHistogram.
* @return this instance of <b>NTHistogramBuilder</b>.
*/
shared_pointer addDescriptor();
/**
* Adds alarm field to the NTHistogram.
* @return this instance of <b>NTHistogramBuilder</b>.
*/
shared_pointer addAlarm();
/**
* Adds timeStamp field to the NTHistogram.
* @return this instance of <b>NTHistogramBuilder</b>.
*/
shared_pointer addTimeStamp();
/**
* Creates a <b>Structure</b> that represents NTHistogram.
* This resets this instance state and allows new instance to be created.
* @return a new instance of <b>Structure</b>.
*/
epics::pvData::StructureConstPtr createStructure();
/**
* Creates a <b>PVStructure</b> that represents NTHistogram.
* This resets this instance state and allows new instance to be created.
* @return a new instance of <b>PVStructure</b>.
*/
epics::pvData::PVStructurePtr createPVStructure();
/**
* Creates a <b>NTHistogram</b> instance.
* This resets this instance state and allows new instance to be created.
* @return a new instance of <b>NTHistogram</b>.
*/
NTHistogramPtr create();
/**
* Adds extra <b>Field</b> to the type.
* @param name the name of the field.
* @param field the field to be added.
* @return this instance of <b>NTHistogramBuilder</b>.
*/
shared_pointer add(std::string const & name, epics::pvData::FieldConstPtr const & field);
private:
NTHistogramBuilder();
void reset();
bool valueTypeSet;
epics::pvData::ScalarType valueType;
bool descriptor;
bool alarm;
bool timeStamp;
// NOTE: this preserves order, however it does not handle duplicates
epics::pvData::StringArray extraFieldNames;
epics::pvData::FieldConstPtrArray extraFields;
friend class ::epics::nt::NTHistogram;
};
}
typedef std::tr1::shared_ptr<detail::NTHistogramBuilder> NTHistogramBuilderPtr;
/**
* @brief Convenience Class for NTHistogram
*
* @author dgh
*/
class epicsShareClass NTHistogram
{
public:
POINTER_DEFINITIONS(NTHistogram);
static const std::string URI;
/**
* Creates an NTHistogram wrapping the specified PVStructure if the latter is compatible.
* <p>
* Checks the supplied PVStructure is compatible with NTHistogram
* and if so returns an NTHistogram which wraps it.
* This method will return null if the structure is is not compatible
* or is null.
*
* @param pvStructure the PVStructure to be wrapped
* @return NTHistogram instance wrapping pvStructure on success, null otherwise
*/
static shared_pointer wrap(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Creates an NTHistogram wrapping the specified PVStructure, regardless of the latter's compatibility.
* <p>
* No checks are made as to whether the specified PVStructure
* is compatible with NTHistogram or is non-null.
*
* @param pvStructure the PVStructure to be wrapped.
* @return NTHistogram instance wrapping pvStructure.
*/
static shared_pointer wrapUnsafe(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Returns whether the specified Structure reports to be a compatible NTHistogram.
* <p>
* Checks whether the specified Structure reports compatibility with this
* version of NTHistogram through its type ID, including checking version numbers.
* The return value does not depend on whether the structure is actually
* compatible in terms of its introspection type.
*
* @param structure the Structure to test.
* @return (false,true) if the specified Structure (is not, is) a compatible NTHistogram
*/
static bool is_a(epics::pvData::StructureConstPtr const & structure);
/**
* Returns whether the specified PVStructure reports to be a compatible NTHistogram.
* <p>
* Checks whether the specified PVStructure reports compatibility with this
* version of NTHistogram through its type ID, including checking version numbers.
* The return value does not depend on whether the structure is actually
* compatible in terms of its introspection type.
*
* @param pvStructure the PVStructure to test
* @return (false,true) if the specified PVStructure (is not, is) a compatible NTHistogram
*/
static bool is_a(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Returns whether the specified Structure is compatible with NTHistogram.
* <p>
* Checks whether the specified Structure is compatible with this version
* of NTHistogram through the introspection interface.
*
* @param structure the Structure to test
* @return (false,true) if the specified Structure (is not, is) a compatible NTHistogram
*/
static bool isCompatible(
epics::pvData::StructureConstPtr const &structure);
/**
* Returns whether the specified PVStructure is compatible with NTHistogram.
* <p>
* Checks whether the specified PVStructure is compatible with this version
* of NTHistogram through the introspection interface.
*
* @param pvStructure the PVStructure to test
* @return (false,true) if the specified PVStructure (is not, is) a compatible NTHistogram
*/
static bool isCompatible(
epics::pvData::PVStructurePtr const &pvStructure);
/**
* Returns whether the wrapped structure is valid with respect to this
* version of NTHistogram.
* <p>
* Unlike isCompatible(), isValid() may perform checks on the value
* data as well as the introspection data.
*
* @return (false,true) if the wrapped PVStructure (is not, is) a valid NTHistogram
*/
bool isValid();
/**
* Creates an NTHistogram builder instance.
* @return builder instance.
*/
static NTHistogramBuilderPtr createBuilder();
/**
* Destructor.
*/
~NTHistogram() {}
/**
* Attaches a PVTimeStamp to the wrapped PVStructure.
* Does nothing if no timeStamp field.
* @param pvTimeStamp the PVTimeStamp that will be attached.
* @return true if the operation was successfull (i.e. this instance has a timeStamp field), otherwise false.
*/
bool attachTimeStamp(epics::pvData::PVTimeStamp &pvTimeStamp) const;
/**
* Attaches a PVAlarm to the wrapped PVStructure.
* Does nothing if no alarm field.
* @param pvAlarm the PVAlarm that will be attached.
* @return true if the operation was successfull (i.e. this instance has an alarm field), otherwise false.
*/
bool attachAlarm(epics::pvData::PVAlarm &pvAlarm) const;
/**
* Get the PVStructure wrapped by this instance.
* @return the PVStructure wrapped by this instance.
*/
epics::pvData::PVStructurePtr getPVStructure() const;
/**
* Returns the descriptor field.
* @return the descriptor field or null if no such field.
*/
epics::pvData::PVStringPtr getDescriptor() const;
/**
* Returns the timeStamp field.
* @return the timStamp field or null if no such field.
*/
epics::pvData::PVStructurePtr getTimeStamp() const;
/**
* Returns the alarm field.
* @return the alarm field or null if no such field.
*/
epics::pvData::PVStructurePtr getAlarm() const;
/**
* Returns the ranges field.
* @return the ranges field.
*/
epics::pvData::PVDoubleArrayPtr getRanges() const;
/**
* Returns the value field.
* @return the value field.
*/
epics::pvData::PVScalarArrayPtr getValue() const;
/**
* Returns the value field of a specified type (e.g. PVIntArray).
* @tparam PVT the expected type of the value field which should be
* be PVShortArray, PVIntArray pr PVLongArray.
* @return the value field or null if it is not of the expected type.
*/
template<typename PVT>
std::tr1::shared_ptr<PVT> getValue() const
{
return std::tr1::dynamic_pointer_cast<PVT>(pvValue);
}
private:
NTHistogram(epics::pvData::PVStructurePtr const & pvStructure);
epics::pvData::PVStructurePtr pvNTHistogram;
epics::pvData::PVScalarArrayPtr pvValue;
friend class detail::NTHistogramBuilder;
};
}}
#endif /* NTHISTOGRAM_H */

153
src/pv/ntid.h Normal file
View File

@@ -0,0 +1,153 @@
/* ntid.h */
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#ifndef NTID_H
#define NTID_H
#include <string>
namespace epics {
namespace nt {
/**
* @brief Utility class for parsing a type ID that follows the NT type ID conventions
*
* An NT type ID will be of the from
@code
epics:nt/<type-name>:<Major>.<Minor>
@endcode
* e.g.
@code
epics:nt/NTNDArray:1.2
@endcode
* @author dgh
*/
class NTID
{
public:
/**
* Creates an NTID from the specified type ID.
*
* @param id the the ID to be parsed.
* @return NTNDArray instance on success, null otherwise.
*/
NTID(const std::string &id);
/**
* Returns the full name of the id, i.e. the original ID
* <p>
* For example above returns "epics:nt/NTNDArray:1.2".
* @return the full name
*/
std::string getFullName();
/**
* Returns the fully qualified name including namespaces, but excluding version numbers.
* <p>
* For example above return "epics:nt/NTNDArray"
* @return the fully qualified name
*/
std::string getQualifiedName();
/**
* Returns the namespace
* <p>
* For example above return "epics:nt".
* @return the namespace
*/
std::string getNamespace();
/**
* Returns the unqualified name, without namespace or version.
* <p>
* For example above return "NTNDArray".
* @return the unqualified name
*/
std::string getName();
/**
* Returns the version as a string.
* <p>
* For example above return "NTNDArray".
* @return the the version string
*/
std::string getVersion();
/**
* Returns the Major version as a string.
* <p>
* For example above return "1".
* @return the Major string
*/
std::string getMajorVersionString();
/**
* Does the ID contain a major version and is it a number.
* <p>
* @return true if it contains a major version number
*/
bool hasMajorVersion();
/**
* Returns the Major version as an integer.
* <p>
* For example above return 1.
* @return the Major string
*/
int getMajorVersion();
/**
* Returns the Major version as a string.
* <p>
* For example above return "1".
* @return the Major string
*/
std::string getMinorVersionString();
/**
* Does the ID contain a minor version and is it a number.
* <p>
* @return true if it contains a minor version number
*/
bool hasMinorVersion();
/**
* Returns the Minor version as an integer.
* <p>
* For example above return 1.
* @return the Minor string
*/
int getMinorVersion();
private:
std::string fullName;
std::string qualifiedName;
std::string namespaceStr;
std::string name;
std::string version;
size_t nsSepIndex;
size_t versionSepIndex;
bool nsQualified;
bool hasVersion;
size_t endMajorIndex;
std::string majorVersionStr;
bool majorVersionParsed;
bool hasMajor;
int majorVersion;
size_t endMinorIndex;
std::string minorVersionStr;
bool minorVersionParsed;
bool hasMinor;
int minorVersion;
};
}}
#endif

312
src/pv/ntmatrix.h Normal file
View File

@@ -0,0 +1,312 @@
/* ntmatrix.h */
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#ifndef NTMATRIX_H
#define NTMATRIX_H
#ifdef epicsExportSharedSymbols
# define ntmatrixEpicsExportSharedSymbols
# undef epicsExportSharedSymbols
#endif
#include <pv/pvDisplay.h>
#ifdef ntmatrixEpicsExportSharedSymbols
# define epicsExportSharedSymbols
# undef ntmatrixEpicsExportSharedSymbols
#endif
#include <pv/ntfield.h>
#include <shareLib.h>
namespace epics { namespace nt {
class NTMatrix;
typedef std::tr1::shared_ptr<NTMatrix> NTMatrixPtr;
namespace detail {
/**
* @brief Interface for in-line creating of NTMatrix.
*
* One instance can be used to create multiple instances.
* An instance of this object must not be used concurrently (an object has a state).
* @author dgh
*/
class epicsShareClass NTMatrixBuilder :
public std::tr1::enable_shared_from_this<NTMatrixBuilder>
{
public:
POINTER_DEFINITIONS(NTMatrixBuilder);
/**
* Adds dimension field to the NTMatrix.
* @return this instance of <b>NTMatrixBuilder</b>.
*/
shared_pointer addDim();
/**
* Adds descriptor field to the NTMatrix.
* @return this instance of <b>NTMatrixBuilder</b>.
*/
shared_pointer addDescriptor();
/**
* Adds alarm field to the NTMatrix.
* @return this instance of <b>NTMatrixBuilder</b>.
*/
shared_pointer addAlarm();
/**
* Adds timeStamp field to the NTMatrix.
* @return this instance of <b>NTMatrixBuilder</b>.
*/
shared_pointer addTimeStamp();
/**
* Adds display field to the NTMatrix.
* @return this instance of <b>NTMatrixBuilder</b>.
*/
shared_pointer addDisplay();
/**
* Creates a <b>Structure</b> that represents NTMatrix.
* This resets this instance state and allows new instance to be created.
* @return a new instance of <b>Structure</b>.
*/
epics::pvData::StructureConstPtr createStructure();
/**
* Creates a <b>PVStructure</b> that represents NTMatrix.
* This resets this instance state and allows new instance to be created.
* @return a new instance of <b>PVStructure</b>.
*/
epics::pvData::PVStructurePtr createPVStructure();
/**
* Creates a <b>NTMatrix</b> instance.
* This resets this instance state and allows new instance to be created.
* @return a new instance of <b>NTMatrix</b>.
*/
NTMatrixPtr create();
/**
* Adds extra <b>Field</b> to the type.
* @param name the name of the field.
* @param field the field to be added.
* @return this instance of <b>NTMatrixBuilder</b>.
*/
shared_pointer add(std::string const & name, epics::pvData::FieldConstPtr const & field);
private:
NTMatrixBuilder();
void reset();
bool dim;
bool descriptor;
bool alarm;
bool timeStamp;
bool display;
// NOTE: this preserves order, however it does not handle duplicates
epics::pvData::StringArray extraFieldNames;
epics::pvData::FieldConstPtrArray extraFields;
friend class ::epics::nt::NTMatrix;
};
}
typedef std::tr1::shared_ptr<detail::NTMatrixBuilder> NTMatrixBuilderPtr;
/**
* @brief Convenience Class for NTMatrix
*
* @author dgh
*/
class epicsShareClass NTMatrix
{
public:
POINTER_DEFINITIONS(NTMatrix);
static const std::string URI;
/**
* Creates an NTMatrix wrapping the specified PVStructure if the latter is compatible.
* <p>
* Checks the supplied PVStructure is compatible with NTMatrix
* and if so returns an NTMatrix which wraps it.
* This method will return null if the structure is is not compatible
* or is null.
*
* @param pvStructure the PVStructure to be wrapped
* @return NTMatrix instance wrapping pvStructure on success, null otherwise
*/
static shared_pointer wrap(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Creates an NTMatrix wrapping the specified PVStructure, regardless of the latter's compatibility.
* <p>
* No checks are made as to whether the specified PVStructure
* is compatible with NTMatrix or is non-null.
*
* @param pvStructure the PVStructure to be wrapped
* @return NTMatrix instance wrapping pvStructure
*/
static shared_pointer wrapUnsafe(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Returns whether the specified Structure reports to be a compatible NTMatrix.
* <p>
* Checks if the specified Structure reports compatibility with this
* version of NTMatrix through its type ID, including checking version numbers.
* The return value does not depend on whether the structure is actually
* compatible in terms of its introspection type.
*
* @param structure the structure to test
* @return (false,true) if the specified Structure (is not, is) a compatible NTMatrix
*/
static bool is_a(epics::pvData::StructureConstPtr const & structure);
/**
* Returns whether the specified PVStructure reports to be a compatible NTMatrix.
* <p>
* Checks if the specified PVStructure reports compatibility with this
* version of NTMatrix through its type ID, including checking version numbers.
* The return value does not depend on whether the structure is actually
* compatible in terms of its introspection type.
*
* @param pvStructure the PVStructure to test
* @return (false,true) if the specified PVStructure (is not, is) a compatible NTMatrix
*/
static bool is_a(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Returns whether the specified Structure is compatible with NTMatrix.
* <p>
* Checks if the specified Structure is compatible with this version
* of NTMatrix through the introspection interface.
*
* @param structure the Structure to test
* @return (false,true) if the specified Structure (is not, is) a compatible NTMatrix
*/
static bool isCompatible(
epics::pvData::StructureConstPtr const &structure);
/**
* Returns whether the specified PVStructure is compatible with NTMatrix.
* <p>
* Checks if the specified PVStructure is compatible with this version
* of NTMatrix through the introspection interface.
*
* @param pvStructure the PVStructure to test
* @return (false,true) if the specified PVStructure (is not, is) a compatible NTMatrix
*/
static bool isCompatible(
epics::pvData::PVStructurePtr const &pvStructure);
/**
* Returns whether the wrapped PVStructure is valid with respect to this
* version of NTMatrix.
* <p>
* Unlike isCompatible(), isValid() may perform checks on the value
* data as well as the introspection data.
*
* @return (false,true) if the wrapped PVStructure (is not, is) a valid NTMatrix
*/
bool isValid();
/**
* Creates an NTMatrix builder instance.
* @return builder instance.
*/
static NTMatrixBuilderPtr createBuilder();
/**
* Destructor.
*/
~NTMatrix() {}
/**
* Attaches a PVTimeStamp to the wrapped PVStructure.
* Does nothing if no timeStamp field.
* @param pvTimeStamp the PVTimeStamp that will be attached.
* @return true if the operation was successfull (i.e. this instance has a timeStamp field), otherwise false.
*/
bool attachTimeStamp(epics::pvData::PVTimeStamp &pvTimeStamp) const;
/**
* Attaches a PVAlarm to the wrapped PVStructure.
* Does nothing if no alarm field.
* @param pvAlarm the PVAlarm that will be attached.
* @return true if the operation was successfull (i.e. this instance has an alarm field), otherwise false.
*/
bool attachAlarm(epics::pvData::PVAlarm &pvAlarm) const;
/**
* Attaches a PVDisplay to the wrapped PVStructure.
* Does nothing if no display.
* @param pvDisplay the PVDisplay that will be attached.
* @return true if the operation was successfull (i.e. this instance has a display field), otherwise false.
*/
bool attachDisplay(epics::pvData::PVDisplay &pvDisplay) const;
/**
* Get the PVStructure wrapped by this instance.
* @return the PVStructure wrapped by this instance.
*/
epics::pvData::PVStructurePtr getPVStructure() const;
/**
* Returns the descriptor field.
* @return the descriptor field or null if no such field.
*/
epics::pvData::PVStringPtr getDescriptor() const;
/**
* Returns the timeStamp field.
* @return the timStamp field or null if no such field.
*/
epics::pvData::PVStructurePtr getTimeStamp() const;
/**
* Returns the alarm field.
* @return the alarm field or null if no such field.
*/
epics::pvData::PVStructurePtr getAlarm() const;
/**
* Returns the display field.
* @return the display field or null if no such field.
*/
epics::pvData::PVStructurePtr getDisplay() const;
/**
* Returns the value field.
* @return the value field.
*/
epics::pvData::PVDoubleArrayPtr getValue() const;
/**
* Returns the dim field.
* @return the dim field or or null if no such field.
*/
epics::pvData::PVIntArrayPtr getDim() const;
private:
NTMatrix(epics::pvData::PVStructurePtr const & pvStructure);
epics::pvData::PVStructurePtr pvNTMatrix;
epics::pvData::PVDoubleArrayPtr pvValue;
friend class detail::NTMatrixBuilder;
};
}}
#endif /* NTMATRIX_H */

409
src/pv/ntmultiChannel.h Normal file
View File

@@ -0,0 +1,409 @@
/* ntmultiChannel.h */
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#ifndef NTMULTICHANNEL_H
#define NTMULTICHANNEL_H
#include <vector>
#include <string>
#ifdef epicsExportSharedSymbols
# define ntmultiChannelEpicsExportSharedSymbols
# undef epicsExportSharedSymbols
#endif
#include <pv/pvDisplay.h>
#include <pv/pvControl.h>
#ifdef ntmultiChannelEpicsExportSharedSymbols
# define epicsExportSharedSymbols
# undef ntmultiChannelEpicsExportSharedSymbols
#endif
#include <pv/ntfield.h>
#include <shareLib.h>
namespace epics { namespace nt {
class NTMultiChannel;
typedef std::tr1::shared_ptr<NTMultiChannel> NTMultiChannelPtr;
namespace detail {
/**
* @brief Interface for in-line creating of NTMultiChannel.
*
* One instance can be used to create multiple instances.
* An instance of this object must not be used concurrently (an object has a state).
* @author mse
*/
class epicsShareClass NTMultiChannelBuilder :
public std::tr1::enable_shared_from_this<NTMultiChannelBuilder>
{
public:
POINTER_DEFINITIONS(NTMultiChannelBuilder);
/**
* specify the union for the value field.
* If this is not called then a variantUnion is the default.
* @return this instance of <b>NTMultiChannelBuilder</b>.
*/
shared_pointer value(epics::pvData::UnionConstPtr valuePtr);
/**
* Adds descriptor field to the NTMultiChannel.
* @return this instance of <b>NTMultiChannelBuilder</b>.
*/
shared_pointer addDescriptor();
/**
* Adds alarm field to the NTMultiChannel.
* @return this instance of <b>NTMultiChannelBuilder</b>.
*/
shared_pointer addAlarm();
/**
* Adds timeStamp field to the NTMultiChannel.
* @return this instance of <b>NTMultiChannelBuilder</b>.
*/
shared_pointer addTimeStamp();
/**
* Adds severity array to the NTMultiChannel.
* @return this instance of <b>NTMultiChannelBuilder</b>.
*/
shared_pointer addSeverity();
/**
* Adds status array to the NTMultiChannel.
* @return this instance of <b>NTMultiChannelBuilder</b>.
*/
shared_pointer addStatus();
/**
* Adds message array to the NTMultiChannel.
* @return this instance of <b>NTMultiChannelBuilder</b>.
*/
shared_pointer addMessage();
/**
* Adds secondsPastEpoch array to the NTMultiChannel.
* @return this instance of <b>NTMultiChannelBuilder</b>.
*/
shared_pointer addSecondsPastEpoch();
/**
* Adds nanoseconds array to the NTMultiChannel.
* @return this instance of <b>NTMultiChannelBuilder</b>.
*/
shared_pointer addNanoseconds();
/**
* Adds userTag array to the NTMultiChannel.
* @return this instance of <b>NTMultiChannelBuilder</b>.
*/
shared_pointer addUserTag();
/**
* Adds isConnected array to the NTMultiChannel.
* @return this instance of <b>NTMultiChannelBuilder</b>.
*/
shared_pointer addIsConnected();
/**
* Creates a <b>Structure</b> that represents NTMultiChannel.
* This resets this instance state and allows new instance to be created.
* @return a new instance of a <b>Structure</b>.
*/
epics::pvData::StructureConstPtr createStructure();
/**
* Creates a <b>PVStructure</b> that represents NTMultiChannel.
* This resets this instance state and allows new instance to be created.
* @return a new instance of a <b>PVStructure</b>
*/
epics::pvData::PVStructurePtr createPVStructure();
/**
* Creates a <b>NTMultiChannel</b> instance.
* This resets this instance state and allows new instance to be created.
* @return a new instance of a <b>NTMultiChannel</b>
*/
NTMultiChannelPtr create();
/**
* Adds extra <b>Field</b> to the type.
* @param name the name of the field.
* @param field the field to be added.
* @return this instance of a <b>NTMultiChannelBuilder</b>
*/
shared_pointer add(std::string const & name, epics::pvData::FieldConstPtr const & field);
private:
NTMultiChannelBuilder();
void reset();
epics::pvData::UnionConstPtr valueType;
bool descriptor;
bool alarm;
bool timeStamp;
bool severity;
bool status;
bool message;
bool secondsPastEpoch;
bool nanoseconds;
bool userTag;
bool isConnected;
// NOTE: this preserves order, however it does not handle duplicates
epics::pvData::StringArray extraFieldNames;
epics::pvData::FieldConstPtrArray extraFields;
friend class ::epics::nt::NTMultiChannel;
};
}
typedef std::tr1::shared_ptr<detail::NTMultiChannelBuilder> NTMultiChannelBuilderPtr;
/**
* @brief Convenience Class for NTMultiChannel
*
* @author mrk
*
*/
class epicsShareClass NTMultiChannel
{
public:
POINTER_DEFINITIONS(NTMultiChannel);
static const std::string URI;
/**
* Creates an NTMultiChannel wrapping the specified PVStructure if the latter is compatible.
* <p>
* Checks the supplied PVStructure is compatible with NTMultiChannel
* and if so returns an NTMultiChannel which wraps it.
* This method will return null if the structure is is not compatible
* or is null.
*
* @param pvStructure the PVStructure to be wrapped
* @return NTMultiChannel instance wrapping pvStructure on success, null otherwise
*/
static shared_pointer wrap(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Creates an NTMultiChannel wrapping the specified PVStructure, regardless of the latter's compatibility.
* <p>
* No checks are made as to whether the specified PVStructure
* is compatible with NTMultiChannel or is non-null.
*
* @param pvStructure the PVStructure to be wrapped
* @return NTMultiChannel instance wrapping pvStructure
*/
static shared_pointer wrapUnsafe(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Returns whether the specified Structure reports to be a compatible NTMultiChannel.
* <p>
* Checks whether the specified Structure reports compatibility with this
* version of NTMultiChannel through its type ID, including checking version numbers.
* The return value does not depend on whether the structure is actually
* compatible in terms of its introspection type.
*
* @param structure the Structure to test
* @return (false,true) if the specified Structure (is not, is) a compatible NTMultiChannel
*/
static bool is_a(epics::pvData::StructureConstPtr const & structure);
/**
* Returns whether the specified PVStructure reports to be a compatible NTMultiChannel.
* <p>
* Checks whether the specified PVStructure reports compatibility with this
* version of NTMultiChannel through its type ID, including checking version numbers.
* The return value does not depend on whether the structure is actually
* compatible in terms of its introspection type.
*
* @param pvStructure the PVStructure to test
* @return (false,true) if the specified PVStructure (is not, is) a compatible NTMultiChannel
*/
static bool is_a(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Returns whether the specified Structure is compatible with NTMultiChannel.
* <p>
* Checks whether the specified Structure is compatible with this version
* of NTMultiChannel through the introspection interface.
*
* @param structure the Structure to test
* @return (false,true) if the specified Structure (is not, is) a compatible NTMultiChannel
*/
static bool isCompatible(
epics::pvData::StructureConstPtr const &structure);
/**
* Returns whether the specified PVStructure is compatible with NTMultiChannel.
* <p>
* Checks whether the specified PVStructure is compatible with this version
* of NTMultiChannel through the introspection interface.
*
* @param pvStructure the PVStructure to test
* @return (false,true) if the specified PVStructure (is not, is) a compatible NTMultiChannel
*/
static bool isCompatible(
epics::pvData::PVStructurePtr const &pvStructure);
/**
* Checks whether the wrapped PVStructure is valid with respect to this
* version of NTMultiChannel.
* <p>
* Unlike isCompatible(), isValid() may perform checks on the value
* data as well as the introspection data.
*
* @return (false,true) if the wrapped PVStructure (is not, is) a valid NTMultiChannel
*/
bool isValid();
/**
* Creates an NTMultiChannelBuilder instance
* @return builder instance.
*/
static NTMultiChannelBuilderPtr createBuilder();
/**
* Destructor
*/
~NTMultiChannel() {}
/**
* Attaches a PVTimeStamp to the wrapped PVStructure.
* Does nothing if no timeStamp field.
* @param pvTimeStamp the PVTimeStamp that will be attached.
* @return true if the operation was successfull (i.e. this instance has a timeStamp field), otherwise false.
*/
bool attachTimeStamp(epics::pvData::PVTimeStamp &pvTimeStamp) const;
/**
* Attaches a PVAlarm to the wrapped PVStructure.
* Does nothing if no alarm field.
* @param pvAlarm the PVAlarm that will be attached.
* @return true if the operation was successfull (i.e. this instance has an alarm field), otherwise false.
*/
bool attachAlarm(epics::pvData::PVAlarm &pvAlarm) const;
/**
* Returns the PVStructure wrapped by this instance.
* @return the PVStructure wrapped by this instance.
*/
epics::pvData::PVStructurePtr getPVStructure() const
{return pvNTMultiChannel;}
/**
* Return the descriptor field.
* @return the descriptor field or null if no descriptor field.
*/
epics::pvData::PVStringPtr getDescriptor() const
{return pvDescriptor;}
/**
* Returns the timeStamp field.
* @return the timeStamp field or null if no such field.
*/
epics::pvData::PVStructurePtr getTimeStamp() const
{return pvTimeStamp;}
/**
* Returns the alarm field.
* @return the alarm field or null if no such field.
*/
epics::pvData::PVStructurePtr getAlarm() const
{return pvAlarm;}
/**
* Returns the field with the value of each channel.
* @return the value field.
*/
epics::pvData::PVUnionArrayPtr getValue() const
{return pvValue;}
/**
* Returns the field with the channelName of each channel.
* @return the channelName field
*/
epics::pvData::PVStringArrayPtr getChannelName() const
{ return pvChannelName;};
/**
* Returns the field with the connection state of each channel.
* @return the isConnected field or null if no such field
*/
epics::pvData::PVBooleanArrayPtr getIsConnected() const
{ return pvIsConnected;};
/**
* Returns the field with the severity of each channel.
* @return the severity field or null if no such field.
*/
epics::pvData::PVIntArrayPtr getSeverity() const
{return pvSeverity;}
/**
* Returns the field with the status of each channel.
* @return the status field or null if no such field
*/
epics::pvData::PVIntArrayPtr getStatus() const
{return pvStatus;}
/**
* Returns the field with the message of each channel.
* @return message field or null if no such field.
*/
epics::pvData::PVStringArrayPtr getMessage() const
{return pvMessage;}
/**
* Returns the field with the secondsPastEpoch of each channel.
* @return the secondsPastEpoch field or null if no such field.
*/
epics::pvData::PVLongArrayPtr getSecondsPastEpoch() const
{return pvSecondsPastEpoch;}
/**
* Returns the field with the nanoseconds of each channel.
* @return nanoseconds field or null if no such field.
*/
epics::pvData::PVIntArrayPtr getNanoseconds() const
{return pvNanoseconds;}
/**
* Returns the field with the userTag of each channel.
* @return the userTag field or null if no such field.
*/
epics::pvData::PVIntArrayPtr getUserTag() const
{return pvUserTag;}
private:
NTMultiChannel(epics::pvData::PVStructurePtr const & pvStructure);
epics::pvData::PVStructurePtr pvNTMultiChannel;
epics::pvData::PVStructurePtr pvTimeStamp;
epics::pvData::PVStructurePtr pvAlarm;
epics::pvData::PVUnionArrayPtr pvValue;
epics::pvData::PVStringArrayPtr pvChannelName;
epics::pvData::PVBooleanArrayPtr pvIsConnected;
epics::pvData::PVIntArrayPtr pvSeverity;
epics::pvData::PVIntArrayPtr pvStatus;
epics::pvData::PVStringArrayPtr pvMessage;
epics::pvData::PVLongArrayPtr pvSecondsPastEpoch;
epics::pvData::PVIntArrayPtr pvNanoseconds;
epics::pvData::PVIntArrayPtr pvUserTag;
epics::pvData::PVStringPtr pvDescriptor;
friend class detail::NTMultiChannelBuilder;
};
}}
#endif /* NTMULTICHANNEL_H */

305
src/pv/ntnameValue.h Normal file
View File

@@ -0,0 +1,305 @@
/* ntnameValue.h */
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#ifndef NTNAMEVALUE_H
#define NTNAMEVALUE_H
#ifdef epicsExportSharedSymbols
# define ntnameValueEpicsExportSharedSymbols
# undef epicsExportSharedSymbols
#endif
#include <pv/pvDisplay.h>
#include <pv/pvControl.h>
#ifdef ntnameValueEpicsExportSharedSymbols
# define epicsExportSharedSymbols
# undef ntnameValueEpicsExportSharedSymbols
#endif
#include <pv/ntfield.h>
#include <shareLib.h>
namespace epics { namespace nt {
class NTNameValue;
typedef std::tr1::shared_ptr<NTNameValue> NTNameValuePtr;
namespace detail {
/**
* @brief Interface for in-line creating of NTNameValue.
*
* One instance can be used to create multiple instances.
* An instance of this object must not be used concurrently (an object has a state).
* @author mse
*/
class epicsShareClass NTNameValueBuilder :
public std::tr1::enable_shared_from_this<NTNameValueBuilder>
{
public:
POINTER_DEFINITIONS(NTNameValueBuilder);
/**
* Sets the value array <b>Scalar</b> type.
* @param scalarType the value field element ScalarType
* @return this instance of <b>NTTableBuilder</b>.
*/
shared_pointer value(epics::pvData::ScalarType scalarType);
/**
* Adds descriptor field to the NTNameValue.
* @return this instance of <b>NTTableBuilder</b>.
*/
shared_pointer addDescriptor();
/**
* Adds alarm field to the NTNameValue.
* @return this instance of <b>NTTableBuilder</b>.
*/
shared_pointer addAlarm();
/**
* Adds timeStamp field to the NTNameValue.
* @return this instance of <b>NTTableBuilder</b>.
*/
shared_pointer addTimeStamp();
/**
* Creates a <b>Structure</b> that represents NTNameValue.
* This resets this instance state and allows new instance to be created.
* @return a new instance of <b>Structure</b>.
*/
epics::pvData::StructureConstPtr createStructure();
/**
* Creates a <b>PVStructure</b> that represents NTNameValue.
* This resets this instance state and allows new instance to be created.
* @return a new instance of <b>PVStructure</b>
*/
epics::pvData::PVStructurePtr createPVStructure();
/**
* Creates a <b>NTNameValue</b> instance.
* This resets this instance state and allows new instance to be created.
* @return a new instance of <b>NTNameValue</b>
*/
NTNameValuePtr create();
/**
* Adds extra <b>Field</b> to the type.
* @param name the name of the field.
* @param field the field to be added.
* @return this instance of <b>NTTableBuilder</b>.
*/
shared_pointer add(std::string const & name, epics::pvData::FieldConstPtr const & field);
private:
NTNameValueBuilder();
void reset();
bool valueTypeSet;
epics::pvData::ScalarType valueType;
bool descriptor;
bool alarm;
bool timeStamp;
// NOTE: this preserves order, however it does not handle duplicates
epics::pvData::StringArray extraFieldNames;
epics::pvData::FieldConstPtrArray extraFields;
friend class ::epics::nt::NTNameValue;
};
}
typedef std::tr1::shared_ptr<detail::NTNameValueBuilder> NTNameValueBuilderPtr;
/**
* @brief Convenience Class for NTNameValue
*
* @author mrk
*/
class epicsShareClass NTNameValue
{
public:
POINTER_DEFINITIONS(NTNameValue);
static const std::string URI;
/**
* Creates an NTNameValue wrapping the specified PVStructure if the latter is compatible.
* <p>
* Checks the supplied PVStructure is compatible with NTNameValue
* and if so returns an NTNameValue which wraps it.
* This method will return null if the structure is is not compatible
* or is null.
*
* @param pvStructure the PVStructure to be wrapped.
* @return NTNameValue instance wrapping pvStructure on success, null otherwise.
*/
static shared_pointer wrap(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Creates an NTNameValue wrapping the specified PVStructure, regardless of the latter's compatibility.
* <p>
* No checks are made as to whether the specified PVStructure
* is compatible with NTNameValue or is non-null.
*
* @param pvStructure the PVStructure to be wrapped.
* @return NTNameValue instance wrapping pvStructure.
*/
static shared_pointer wrapUnsafe(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Returns whether the specified Structure reports to be a compatible NTNameValue.
* <p>
* Checks if the specified Structure reports compatibility with this
* version of NTNameValue through its type ID, including checking version numbers.
* The return value does not depend on whether the structure is actually
* compatible in terms of its introspection type.
*
* @param structure the Structure to test.
* @return (false,true) if the specified Structure (is not, is) a compatible NTNameValue.
*/
static bool is_a(epics::pvData::StructureConstPtr const & structure);
/**
* Returns whether the specified PVStructure reports to be a compatible NTNameValue.
* <p>
* Checks if the specified PVStructure reports compatibility with this
* version of NTNameValue through its type ID, including checking version numbers.
* The return value does not depend on whether the structure is actually
* compatible in terms of its introspection type
* @param pvStructure The PVStructure to test.
* @return (false,true) if the specified PVStructure (is not, is) a compatible NTNameValue.
*/
static bool is_a(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Returns whether the specified Structure is compatible with NTNameValue.
* <p>
* Checks if the specified PVStructure is compatible with this version
* of NTNameValue through the introspection interface.
* @param structure the Structure to test.
* @return (false,true) if the specified Structure (is not, is) a compatible NTNameValue.
*/
static bool isCompatible(
epics::pvData::StructureConstPtr const &structure);
/**
* Returns whether the specified PVStructure is compatible with NTNameValue.
* <p>
* Checks if the specified PVStructure is compatible with this version
* of NTNameValue through the introspection interface.
*
* @param pvStructure the PVStructure to test
* @return (false,true) if the specified PVStructure (is not, is) a compatible NTNameValue
*/
static bool isCompatible(
epics::pvData::PVStructurePtr const &pvStructure);
/**
* Returns whether the wrapped PVStructure is valid with respect to this
* version of NTNameValue.
* <p>
* Unlike isCompatible(), isValid() may perform checks on the value
* data as well as the introspection data.
*
* @return (false,true) if the wrapped PVStructure (is not, is) a valid NTNameValue
*/
bool isValid();
/**
* Creates an NTNameValue builder instance.
* @return builder instance.
*/
static NTNameValueBuilderPtr createBuilder();
/**
* Destructor.
*/
~NTNameValue() {}
/**
* Attaches a PVTimeStamp to the wrapped PVStructure.
* Does nothing if no timeStamp field.
* @param pvTimeStamp the PVTimeStamp that will be attached.
* @return true if the operation was successfull (i.e. this instance has a timeStamp field), otherwise false.
*/
bool attachTimeStamp(epics::pvData::PVTimeStamp &pvTimeStamp) const;
/**
* Attaches a PVAlarm to the wrapped PVStructure.
* Does nothing if no alarm field.
* @param pvAlarm the PVAlarm that will be attached.
* @return true if the operation was successfull (i.e. this instance has an alarm field), otherwise false.
*/
bool attachAlarm(epics::pvData::PVAlarm &pvAlarm) const;
/**
* Returns the PVStructure wrapped by this instance.
* @return the PVStructure wrapped by this instance.
*/
epics::pvData::PVStructurePtr getPVStructure() const;
/**
* Returns the descriptor field.
* @return the descriptor field or null if no descriptor field.
*/
epics::pvData::PVStringPtr getDescriptor() const;
/**
* Returns the timeStamp field.
* @return the timStamp field or null if no timeStamp field.
*/
epics::pvData::PVStructurePtr getTimeStamp() const;
/**
* Returns the alarm field.
* @return the alarm field or null if no alarm field.
*/
epics::pvData::PVStructurePtr getAlarm() const;
/**
* Returns the name array field.
* @return The PVStringArray for the name.
*/
epics::pvData::PVStringArrayPtr getName() const;
/**
* Returns the value array field.
* @return The PVField for the value.
*/
epics::pvData::PVFieldPtr getValue() const;
/**
* Returns the value array field of a specified expected type (e.g. PVDoubleArray).
*
* @tparam PVT The expected type of the value field which should be
* be PVScalarArray or a derived class.
* @return The PVT array for the value.
*/
template<typename PVT>
std::tr1::shared_ptr<PVT> getValue() const
{
epics::pvData::PVFieldPtr pvField = getValue();
if (pvField.get())
return std::tr1::dynamic_pointer_cast<PVT>(pvField);
else
return std::tr1::shared_ptr<PVT>();
}
private:
NTNameValue(epics::pvData::PVStructurePtr const & pvStructure);
epics::pvData::PVStructurePtr pvNTNameValue;
friend class detail::NTNameValueBuilder;
};
}}
#endif /* NTNAMEVALUE_H */

353
src/pv/ntndarray.h Normal file
View File

@@ -0,0 +1,353 @@
/* ntndarray.h */
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#ifndef NTNDARRAY_H
#define NTNDARRAY_H
#include <vector>
#include <string>
#ifdef epicsExportSharedSymbols
# define ntscalarArrayEpicsExportSharedSymbols
# undef epicsExportSharedSymbols
#endif
#include <pv/pvDisplay.h>
#include <pv/pvControl.h>
#ifdef ntscalarArrayEpicsExportSharedSymbols
# define epicsExportSharedSymbols
# undef ntscalarArrayEpicsExportSharedSymbols
#endif
#include <pv/ntfield.h>
#include <shareLib.h>
namespace epics { namespace nt {
class NTNDArray;
typedef std::tr1::shared_ptr<NTNDArray> NTNDArrayPtr;
namespace detail {
/**
* @brief Interface for in-line creating of NTNDArray.
*
* One instance can be used to create multiple instances.
* An instance of this object must not be used concurrently (an object has a state).
* @author mse
*/
class epicsShareClass NTNDArrayBuilder :
public std::tr1::enable_shared_from_this<NTNDArrayBuilder>
{
public:
POINTER_DEFINITIONS(NTNDArrayBuilder);
/**
* Adds descriptor field to the NTNDArray.
* @return this instance of <b>NTNDArrayBuilder</b>.
*/
shared_pointer addDescriptor();
/**
* Adds alarm field to the NTNDArray.
* @return this instance of <b>NTNDArrayBuilder</b>.
*/
shared_pointer addAlarm();
/**
* Adds timeStamp field to the NTNDArray.
* @return this instance of <b>NTNDArrayBuilder</b>.
*/
shared_pointer addTimeStamp();
/**
* Adds display field to the NTNDArray.
* @return this instance of <b>NTNDArrayBuilder</b>.
*/
shared_pointer addDisplay();
/**
* Creates a <b>Structure</b> that represents NTNDArray.
* This resets this instance state and allows new instance to be created.
* @return a new instance of a <b>Structure</b>.
*/
epics::pvData::StructureConstPtr createStructure();
/**
* Creates a <b>PVStructure</b> that represents NTNDArray.
* This resets this instance state and allows new instance to be created.
* @return a new instance of a <b>PVStructure</b>
*/
epics::pvData::PVStructurePtr createPVStructure();
/**
* Creates a <b>NTNDArray</b> instance.
* This resets this instance state and allows new instance to be created.
* @return a new instance of a <b>NTNDArray</b>
*/
NTNDArrayPtr create();
/**
* Adds extra <b>Field</b> to the type.
* @param name the name of the field.
* @param field the field to be added.
* @return this instance of a <b>NTArrayBuilder</b>.
*/
shared_pointer add(std::string const & name, epics::pvData::FieldConstPtr const & field);
private:
NTNDArrayBuilder();
void reset();
bool descriptor;
bool timeStamp;
bool alarm;
bool display;
// NOTE: this preserves order, however it does not handle duplicates
epics::pvData::StringArray extraFieldNames;
epics::pvData::FieldConstPtrArray extraFields;
friend class ::epics::nt::NTNDArray;
};
}
typedef std::tr1::shared_ptr<detail::NTNDArrayBuilder> NTNDArrayBuilderPtr;
/**
* @brief Convenience Class for NTNDArray
*
* @author dgh
*/
class epicsShareClass NTNDArray
{
public:
POINTER_DEFINITIONS(NTNDArray);
static const std::string URI;
/**
* Creates an NTScalarArray wrapping the specified PVStructure if the latter is compatible.
* <p>
* Checks the supplied PVStructure is compatible with NTScalarArray
* and if so returns an NTScalarArray which wraps it.
* This method will return null if the structure is is not compatible
* or is null.
*
* @param pvStructure the PVStructure to be wrapped
* @return NTScalarArray instance wrapping pvStructure on success, null otherwise
*/
static shared_pointer wrap(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Creates an NTNDArray wrapping the specified PVStructure, regardless of the latter's compatibility.
* <p>
* No checks are made as to whether the specified PVStructure
* is compatible with NTNDArray or is non-null.
*
* @param pvStructure the PVStructure to be wrapped
* @return NTNDArray instance wrapping pvStructure
*/
static shared_pointer wrapUnsafe(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Returns whether the specified Structure reports to be a compatible NTNDArray.
* <p>
* Checks if the specified Structure reports compatibility with this
* version of NTNDArray through its type ID, including checking version numbers.
* The return value does not depend on whether the structure is actually
* compatible in terms of its introspection type.
*
* @param structure the pvStructure to test
* @return (false,true) if the specified Structure (is not, is) a compatible NTNDArray
*/
static bool is_a(epics::pvData::StructureConstPtr const & structure);
/**
* Returns whether the specified PVStructure reports to be a compatible NTNDArray.
*
* Checks if the specified PVStructure reports compatibility with this
* version of NTNDArray through its type ID, including checking version numbers.
* The return value does not depend on whether the structure is actually
* compatible in terms of its introspection type.
*
* @param pvStructure the PVStructure to test
* @return (false,true) if the specified PVStructure (is not, is) a compatible NTNDArray
*/
static bool is_a(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Returns whether the specified Structure is compatible with NTNDArray.
* <p>
* Checks if the specified Structure is compatible with this version
* of NTNDArray through the introspection interface.
*
* @param structure the Structure to test
* @return (false,true) if the specified Structure (is not, is) a compatible NTNDArray
*/
static bool isCompatible(
epics::pvData::StructureConstPtr const &structure);
/**
* Returns whether the specified PVStructure is compatible with NTNDArray.
* <p>
* Checks if the specified PVStructure is compatible with this version
* of NTNDArray through the introspection interface.
* @param pvStructure the PVStructure to test
* @return (false,true) if the specified PVStructure (is not, is) a compatible NTNDArray
*/
static bool isCompatible(
epics::pvData::PVStructurePtr const &pvStructure);
/**
* Returns whether the wrapped PVStructure is valid with respect to this
* version of NTNDArray.
* <p>
* Unlike isCompatible(), isValid() may perform checks on the value
* data as well as the introspection data.
*
* @return (false,true) if the wrapped PVStructure (is not, is) a valid NTNDArray
*/
bool isValid();
/**
* Creates an NTNDArrayBuilder instance
* @return builder instance.
*/
static NTNDArrayBuilderPtr createBuilder();
/**
* Destructor.
*/
~NTNDArray() {}
/**
* Attaches a PVTimeStamp to the wrapped PVStructure.
* Does nothing if no timeStamp field.
* @param pvTimeStamp the PVTimeStamp that will be attached.
* @return true if the operation was successfull (i.e. this instance has a timeStamp field), otherwise false.
*/
bool attachTimeStamp(epics::pvData::PVTimeStamp &pvTimeStamp) const;
/**
* Attaches a pvTimeStamp to dataTimeStamp field.
* @param pvTimeStamp The pvTimeStamp that will be attached.
* Does nothing if no timeStamp.
* @return true if the operation was successfull (i.e. this instance has a timeStamp field), otherwise false.
*/
bool attachDataTimeStamp(epics::pvData::PVTimeStamp &pvTimeStamp) const;
/**
* Attaches a PVAlarm to the wrapped PVStructure.
* Does nothing if no alarm field.
* @param pvAlarm the PVAlarm that will be attached.
* @return true if the operation was successfull (i.e. this instance has an alarm field), otherwise false.
*/
bool attachAlarm(epics::pvData::PVAlarm &pvAlarm) const;
/**
* Returns the PVStructure wrapped by this instance.
* @return the PVStructure wrapped by this instance.
*/
epics::pvData::PVStructurePtr getPVStructure() const;
/**
* Returns the value field.
* Returns the value field.
*/
epics::pvData::PVUnionPtr getValue() const;
/**
* Returns the codec field.
* @return the codec field.
*/
epics::pvData::PVStructurePtr getCodec() const;
/**
* Returns the compressedDataSize field.
* @return the compressedDataSize field.
*/
epics::pvData::PVLongPtr getCompressedDataSize() const;
/**
* Returns the uncompressedDataSize field.
* @return the uncompressedDataSize field.
*/
epics::pvData::PVLongPtr getUncompressedDataSize() const;
/**
* Returns the dimension field.
* @return the dimension field.
*/
epics::pvData::PVStructureArrayPtr getDimension() const;
/**
* Returns the uniqueId field.
* @return the uniqueId field.
*/
epics::pvData::PVIntPtr getUniqueId() const;
/**
* Returns the dataTimeStamp field.
* @return the dataTimeStamp field.
*/
epics::pvData::PVStructurePtr getDataTimeStamp() const;
/**
* Returns the attribute field.
* @return the attribute field.
*/
epics::pvData::PVStructureArrayPtr getAttribute() const;
/**
* Returns the descriptor field.
* @return the descriptor field or null if no descriptor field.
*/
epics::pvData::PVStringPtr getDescriptor() const;
/**
* Returns the timeStamp field.
* @return the timStamp field or null if no timeStamp field.
*/
epics::pvData::PVStructurePtr getTimeStamp() const;
/**
* Returns the alarm field.
* @return the alarm field or null if no alarm field.
*/
epics::pvData::PVStructurePtr getAlarm() const;
/**
* Attaches a PVDisplay to the wrapped PVStructure.
* Does nothing if no display.
* @param pvDisplay the PVDisplay that will be attached.
* @return true if the operation was successfull (i.e. this instance has a display field), otherwise false.
*/
bool attachDisplay(epics::pvData::PVDisplay &pvDisplay) const;
/**
* Returns the display field.
* @return PVStructurePtr or null if no alarm field.
*/
epics::pvData::PVStructurePtr getDisplay() const;
private:
NTNDArray(epics::pvData::PVStructurePtr const & pvStructure);
epics::pvData::int64 getExpectedUncompressedSize();
epics::pvData::int64 getValueSize();
epics::pvData::int64 getValueTypeSize();
epics::pvData::PVStructurePtr pvNTNDArray;
friend class detail::NTNDArrayBuilder;
};
}}
#endif /* NTNDARRAY_H */

312
src/pv/ntndarrayAttribute.h Normal file
View File

@@ -0,0 +1,312 @@
/* ntndarrayAttribute.h */
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#ifndef NTNDARRAYATTRIBUTE_H
#define NTNDARRAYATTRIBUTE_H
#ifdef epicsExportSharedSymbols
# define ntndarrayAttributeEpicsExportSharedSymbols
# undef epicsExportSharedSymbols
#endif
#ifdef ntndarrayAttributeEpicsExportSharedSymbols
# define epicsExportSharedSymbols
# undef ntndarrayAttributeEpicsExportSharedSymbols
#endif
#include <pv/ntfield.h>
#include <shareLib.h>
namespace epics { namespace nt {
class NTNDArrayAttribute;
typedef std::tr1::shared_ptr<NTNDArrayAttribute> NTNDArrayAttributePtr;
namespace detail {
/**
* @brief Interface for in-line creating of NTAttribute extended as required by NTNDArray
*
* One instance can be used to create multiple instances.
* An instance of this object must not be used concurrently (an object has a state).
* @author dgh
*/
class epicsShareClass NTNDArrayAttributeBuilder :
public std::tr1::enable_shared_from_this<NTNDArrayAttributeBuilder>
{
public:
POINTER_DEFINITIONS(NTNDArrayAttributeBuilder);
/**
* Adds tags field to the NTNDArrayAttribute.
* @return this instance of <b>NTNDArrayAttributeBuilder</b>.
*/
shared_pointer addTags();
/**
* Adds descriptor field to the NTNDArrayAttribute.
* @return this instance of <b>NTNDArrayAttributeBuilder</b>.
*/
shared_pointer addDescriptor();
/**
* Adds alarm field to the NTNDArrayAttribute.
* @return this instance of <b>NTNDArrayAttributeBuilder</b>.
*/
shared_pointer addAlarm();
/**
* Adds timeStamp field to the NTNDArrayAttribute.
* @return this instance of <b>NTNDArrayAttributeBuilder</b>.
*/
shared_pointer addTimeStamp();
/**
* Creates a <b>Structure</b> that represents NTNDArrayAttribute.
* This resets this instance state and allows new instance to be created.
* @return a new instance of a <b>Structure</b>.
*/
epics::pvData::StructureConstPtr createStructure();
/**
* Creates a <b>PVStructure</b> that represents NTNDArrayAttribute.
* This resets this instance state and allows new instance to be created.
* @return a new instance of a <b>PVStructure</b>.
*/
epics::pvData::PVStructurePtr createPVStructure();
/**
* Creates a <b>NTNDArrayAttribute</b> instance.
* This resets this instance state and allows new instance to be created.
* @return a new instance of a <b>NTNDArrayAttribute</b>.
*/
NTNDArrayAttributePtr create();
/**
* Adds extra <b>Field</b> to the type.
* @param name the name of the field.
* @param field the field to be added.
* @return this instance of <b>NTNDArrayAttributeBuilder</b>.
*/
shared_pointer add(std::string const & name, epics::pvData::FieldConstPtr const & field);
protected://private:
NTNDArrayAttributeBuilder();
void reset();
bool tags;
bool descriptor;
bool alarm;
bool timeStamp;
// NOTE: this preserves order, however it does not handle duplicates
epics::pvData::StringArray extraFieldNames;
epics::pvData::FieldConstPtrArray extraFields;
friend class ::epics::nt::NTNDArrayAttribute;
};
}
typedef std::tr1::shared_ptr<detail::NTNDArrayAttributeBuilder> NTNDArrayAttributeBuilderPtr;
/**
* @brief Convenience Class for NTNDArrayAttribute
*
* @author dgh
*/
class epicsShareClass NTNDArrayAttribute
{
public:
POINTER_DEFINITIONS(NTNDArrayAttribute);
static const std::string URI;
/**
* Creates an NTNDArrayAttribute wrapping the specified PVStructure if the latter is compatible.
* <p>
* Checks the supplied PVStructure is compatible with NTAttribute
* extended as required by NTNDArray and if so returns an
* NTNDArrayAttribute which wraps it.
* This method will return null if the structure is is not compatible
* or is null.
*
* @param pvStructure the PVStructure to be wrapped
* @return NTAttribute instance wrapping pvStructure on success, null otherwise
*/
static shared_pointer wrap(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Creates an NTNDArrayAttribute wrapping the specified PVStructure, regardless of the latter's compatibility.
* <p>
* No checks are made as to whether the specified PVStructure
* is compatible with NTAttribute extended as required by NTNDArray
* or is non-null.
*
* @param pvStructure the PVStructure to be wrapped
* @return NTAttribute instance wrapping pvStructure
*/
static shared_pointer wrapUnsafe(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Returns whether the specified Structure reports to be a compatible NTAttribute.
* <p>
* Checks if the specified Structure reports compatibility with this
* version of NTAttribute through its type ID, including checking version numbers.
* The return value does not depend on whether the structure is actually
* compatible in terms of its introspection type.
*
* @param structure the Structure to test
* @return (false,true) if the specified Structure (is not, is) a compatible NTAttribute
*/
static bool is_a(epics::pvData::StructureConstPtr const & structure);
/**
* Returns whether the specified PVStructure reports to be a compatible NTAttribute.
* <p>
* Checks if the specified PVStructure reports compatibility with this
* version of NTAttribute through its type ID, including checking version numbers.
* The return value does not depend on whether the structure is actually
* compatible in terms of its introspection type.
*
* @param pvStructure the PVStructure to test
* @return (false,true) if the specified PVStructure (is not, is) a compatible NTAttribute
*/
static bool is_a(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Returns whether the specified Structure is compatible with NTAttribute
* extended as required by NTNDArray.
* <p>
* Checks if the specified Structure is compatible with this version
* of NTAttribute extended as required by this version of NTNDArray
* through the introspection interface.
*
* @param structure the Structure to test
* @return (false,true) if the specified Structure (is not, is) a compatible NTAttribute
*/
static bool isCompatible(
epics::pvData::StructureConstPtr const &structure);
/**
* Returns whether the specified PVStructure is compatible with NTAttribute
* extended as required by NTNDArray.
* <p>
* Checks if the specified PVStructure is compatible with this version
* of NTAttribute extended as required by this version of NTNDArray
* through the introspection interface.
* @param pvStructure the PVStructure to test
* @return (false,true) if the specified PVStructure (is not, is) a compatible NTAttribute
*/
static bool isCompatible(
epics::pvData::PVStructurePtr const &pvStructure);
/**
* Returns whether the wrapped PVStructure is valid with respect to this
* version of NTAttribute extended as per this version of NTNDArray.
* <p>
* Unlike isCompatible(), isValid() may perform checks on the value
* data as well as the introspection data.
*
* @return (false,true) if the wrapped PVStructure (is not, is) a valid NTNDArrayAttribute
*/
bool isValid();
/**
* Creates an NTNDArrayAttribute builder instance.
* @return builder instance.
*/
static NTNDArrayAttributeBuilderPtr createBuilder();
/**
* Destructor.
*/
~NTNDArrayAttribute() {}
/**
* Attaches a PVTimeStamp to the wrapped PVStructure.
* Does nothing if no timeStamp field.
* @param pvTimeStamp the PVTimeStamp that will be attached.
* @return true if the operation was successfull (i.e. this instance has a timeStamp field), otherwise false.
*/
bool attachTimeStamp(epics::pvData::PVTimeStamp &pvTimeStamp) const;
/**
* Attaches a PVAlarm to the wrapped PVStructure.
* Does nothing if no alarm field.
* @param pvAlarm the PVAlarm that will be attached.
* @return true if the operation was successfull (i.e. this instance has an alarm field), otherwise false.
*/
bool attachAlarm(epics::pvData::PVAlarm &pvAlarm) const;
/**
* Returns the PVStructure wrapped by this instance.
* @return the PVStructure wrapped by this instance.
*/
epics::pvData::PVStructurePtr getPVStructure() const;
/**
* Returns the descriptor field.
* @return the descriptor field.
*/
epics::pvData::PVStringPtr getDescriptor() const;
/**
* Returns the timeStamp field.
* @return the timStamp field or null if no such field.
*/
epics::pvData::PVStructurePtr getTimeStamp() const;
/**
* Returns the alarm field.
* @return the alarm field or null if no alarm field.
*/
epics::pvData::PVStructurePtr getAlarm() const;
/**
* Returns the name field.
* @return the name field.
*/
epics::pvData::PVStringPtr getName() const;
/**
* Returns the value field.
* @return the value field.
*/
epics::pvData::PVUnionPtr getValue() const;
/**
* Returns the tags field.
* @return the tags field or null if no such field.
*/
epics::pvData::PVStringArrayPtr getTags() const;
/**
* Returns the sourceType field.
* @return the sourceType field.
*/
epics::pvData::PVIntPtr getSourceType() const;
/**
* Returns the source field.
* @return the source field.
*/
epics::pvData::PVStringPtr getSource() const;
private:
NTNDArrayAttribute(epics::pvData::PVStructurePtr const & pvStructure);
epics::pvData::PVStructurePtr pvNTNDArrayAttribute;
epics::pvData::PVUnionPtr pvValue;
friend class detail::NTNDArrayAttributeBuilder;
};
}}
#endif /* NTNDARRAYATTRIBUTE_H */

342
src/pv/ntscalar.h Normal file
View File

@@ -0,0 +1,342 @@
/* ntscalar.h */
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#ifndef NTSCALAR_H
#define NTSCALAR_H
#ifdef epicsExportSharedSymbols
# define ntscalarEpicsExportSharedSymbols
# undef epicsExportSharedSymbols
#endif
#include <pv/pvDisplay.h>
#include <pv/pvControl.h>
#ifdef ntscalarEpicsExportSharedSymbols
# define epicsExportSharedSymbols
# undef ntscalarEpicsExportSharedSymbols
#endif
#include <pv/ntfield.h>
#include <shareLib.h>
namespace epics { namespace nt {
class NTScalar;
typedef std::tr1::shared_ptr<NTScalar> NTScalarPtr;
namespace detail {
/**
* @brief Interface for in-line creating of NTScalar.
*
* One instance can be used to create multiple instances.
* An instance of this object must not be used concurrently (an object has a state).
* @author mse
*/
class epicsShareClass NTScalarBuilder :
public std::tr1::enable_shared_from_this<NTScalarBuilder>
{
public:
POINTER_DEFINITIONS(NTScalarBuilder);
/**
* Sets the value type of an NTScalar.
* @param scalarType the value type.
* @return this instance of <b>NTScalarBuilder</b>.
*/
shared_pointer value(epics::pvData::ScalarType scalarType);
/**
* Adds descriptor field to the NTScalar.
* @return this instance of <b>NTScalarBuilder</b>.
*/
shared_pointer addDescriptor();
/**
* Adds alarm field to the NTScalar.
* @return this instance of <b>NTScalarBuilder</b>.
*/
shared_pointer addAlarm();
/**
* Adds timeStamp field to the NTScalar.
* @return this instance of <b>NTScalarBuilder</b>.
*/
shared_pointer addTimeStamp();
/**
* Adds display field to the NTScalar.
* @return this instance of <b>NTScalarBuilder</b>.
*/
shared_pointer addDisplay();
/**
* Adds control field to the NTScalar.
* @return this instance of <b>NTScalarBuilder</b>.
*/
shared_pointer addControl();
/**
* Creates a <b>Structure</b> that represents NTScalar.
* This resets this instance state and allows new instance to be created.
* @return a new instance of a <b>Structure</b>.
*/
epics::pvData::StructureConstPtr createStructure();
/**
* Creates a <b>PVStructure</b> that represents NTScalar.
* This resets this instance state and allows new instance to be created.
* @return a new instance of a <b>PVStructure</b>.
*/
epics::pvData::PVStructurePtr createPVStructure();
/**
* Creates a <b>NTScalar</b> instance.
* This resets this instance state and allows new instance to be created.
* @return a new instance of a <b>NTScalar</b>.
*/
NTScalarPtr create();
/**
* Adds extra <b>Field</b> to the type.
* @param name the name of the field.
* @param field the field to be added.
* @return this instance of <b>NTScalarBuilder</b>.
*/
shared_pointer add(std::string const & name, epics::pvData::FieldConstPtr const & field);
private:
NTScalarBuilder();
void reset();
bool valueTypeSet;
epics::pvData::ScalarType valueType;
bool descriptor;
bool alarm;
bool timeStamp;
bool display;
bool control;
// NOTE: this preserves order, however it does not handle duplicates
epics::pvData::StringArray extraFieldNames;
epics::pvData::FieldConstPtrArray extraFields;
friend class ::epics::nt::NTScalar;
};
}
typedef std::tr1::shared_ptr<detail::NTScalarBuilder> NTScalarBuilderPtr;
/**
* @brief Convenience Class for NTScalar
*
* @author mrk
*/
class epicsShareClass NTScalar
{
public:
POINTER_DEFINITIONS(NTScalar);
static const std::string URI;
/**
* Creates an NTScalar wrapping the specified PVStructure if the latter is compatible.
* <p>
* Checks the supplied PVStructure is compatible with NTScalar
* and if so returns an NTScalar which wraps it.
* This method will return null if the structure is is not compatible
* or is null.
*
* @param pvStructure the PVStructure to be wrapped
* @return NTScalar instance wrapping pvStructure on success, null otherwise
*/
static shared_pointer wrap(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Creates an NTScalar wrapping the specified PVStructure, regardless of the latter's compatibility.
* <p>
* No checks are made as to whether the specified PVStructure
* is compatible with NTScalar or is non-null.
*
* @param pvStructure the PVStructure to be wrapped
* @return NTScalar instance wrapping pvStructure
*/
static shared_pointer wrapUnsafe(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Returns whether the specified Structure reports to be a compatible NTScalar.
* <p>
* Checks if the specified Structure reports compatibility with this
* version of NTScalar through its type ID, including checking version numbers.
* The return value does not depend on whether the structure is actually
* compatible in terms of its introspection type.
*
* @param structure the Structure to test
* @return (false,true) if the specified Structure (is not, is) a compatible NTScalar
*/
static bool is_a(epics::pvData::StructureConstPtr const & structure);
/**
* Returns whether the specified PVStructure reports to be a compatible NTScalar.
* <p>
* Checks if the specified PVStructure reports compatibility with this
* version of NTScalar through its type ID, including checking version numbers.
* The return value does not depend on whether the structure is actually
* compatible in terms of its introspection type.
*
* @param pvStructure the PVStructure to test
* @return (false,true) if the specified PVStructure (is not, is) a compatible NTScalar
*/
static bool is_a(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Returns whether the specified Structure is compatible with NTScalar.
* <p>
* Checks if the specified Structure is compatible with this version
* of NTScalar through the introspection interface.
*
* @param structure the Structure to test
* @return (false,true) if the specified Structure (is not, is) a compatible NTScalar
*/
static bool isCompatible(
epics::pvData::StructureConstPtr const &structure);
/**
* Returns whether the specified PVStructure is compatible with NTScalar.
* <p>
* Checks if the specified PVStructure is compatible with this version
* of NTScalar through the introspection interface.
*
* @param pvStructure the PVStructure to test
* @return (false,true) if the specified PVStructure (is not, is) a compatible NTScalar
*/
static bool isCompatible(
epics::pvData::PVStructurePtr const &pvStructure);
/**
* Returns whether the wrapped PVStructure is valid with respect to this
* version of NTScalar.
* <p>
* Unlike isCompatible(), isValid() may perform checks on the value
* data as well as the introspection data.
*
* @return (false,true) if wrapped PVStructure (is not, is) a valid NTScalar
*/
bool isValid();
/**
* Creates an NTScalar builder instance.
* @return builder instance.
*/
static NTScalarBuilderPtr createBuilder();
/**
* Destructor.
*/
~NTScalar() {}
/**
* Attaches a PVTimeStamp to the wrapped PVStructure.
* Does nothing if no timeStamp field.
* @param pvTimeStamp the PVTimeStamp that will be attached.
* @return true if the operation was successfull (i.e. this instance has a timeStamp field), otherwise false.
*/
bool attachTimeStamp(epics::pvData::PVTimeStamp &pvTimeStamp) const;
/**
* Attaches a PVAlarm to the wrapped PVStructure.
* Does nothing if no alarm field.
* @param pvAlarm the PVAlarm that will be attached.
* @return true if the operation was successfull (i.e. this instance has an alarm field), otherwise false.
*/
bool attachAlarm(epics::pvData::PVAlarm &pvAlarm) const;
/**
* Attaches a PVDisplay to the wrapped PVStructure.
* Does nothing if no display field.
* @param pvDisplay the PVDisplay that will be attached.
* @return true if the operation was successfull (i.e. this instance has a display field), otherwise false.
*/
bool attachDisplay(epics::pvData::PVDisplay &pvDisplay) const;
/**
* Attaches an PVControl to the wrapped PVStructure.
* Does nothing if no control field.
* @param pvControl The PVControl that will be attached.
* @return true if the operation was successfull (i.e. this instance has a control field), otherwise false.
*/
bool attachControl(epics::pvData::PVControl &pvControl) const;
/**
* Returns the PVStructure wrapped by this instance.
* @return the PVStructure wrapped by this instance.
*/
epics::pvData::PVStructurePtr getPVStructure() const;
/**
* Returns the descriptor field.
* @return the descriptor field or null if no descriptor field.
*/
epics::pvData::PVStringPtr getDescriptor() const;
/**
* Returns the timeStamp field.
* @return the timStamp field or null if no timeStamp field.
*/
epics::pvData::PVStructurePtr getTimeStamp() const;
/**
* Returns the alarm field.
* @return the alarm field or null if no alarm field.
*/
epics::pvData::PVStructurePtr getAlarm() const;
/**
* Returns the display.
* @return PVStructurePtr which may be null.
*/
epics::pvData::PVStructurePtr getDisplay() const;
/**
* Returns the control.
* @return PVStructurePtr which may be null.
*/
epics::pvData::PVStructurePtr getControl() const;
/**
* Returns the value field.
* @return The PVField for the values.
*/
epics::pvData::PVFieldPtr getValue() const;
/**
* Returns the value field of a specified type (for example, PVDouble).
* @tparam PVT the expected type of the value field which should be
* be PVScalar or a derived class.
* @return the value field or null if it is not of the expected type.
*/
template<typename PVT>
std::tr1::shared_ptr<PVT> getValue() const
{
return std::tr1::dynamic_pointer_cast<PVT>(pvValue);
}
private:
NTScalar(epics::pvData::PVStructurePtr const & pvStructure);
epics::pvData::PVStructurePtr pvNTScalar;
epics::pvData::PVFieldPtr pvValue;
friend class detail::NTScalarBuilder;
};
}}
#endif /* NTSCALAR_H */

350
src/pv/ntscalarArray.h Normal file
View File

@@ -0,0 +1,350 @@
/* ntscalarArray.h */
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#ifndef NTSCALARARRAY_H
#define NTSCALARARRAY_H
#ifdef epicsExportSharedSymbols
# define ntscalarArrayEpicsExportSharedSymbols
# undef epicsExportSharedSymbols
#endif
#include <pv/pvDisplay.h>
#include <pv/pvControl.h>
#ifdef ntscalarArrayEpicsExportSharedSymbols
# define epicsExportSharedSymbols
# undef ntscalarArrayEpicsExportSharedSymbols
#endif
#include <pv/ntfield.h>
#include <shareLib.h>
namespace epics { namespace nt {
class NTScalarArray;
typedef std::tr1::shared_ptr<NTScalarArray> NTScalarArrayPtr;
namespace detail {
/**
* @brief Interface for in-line creating of NTScalarArray.
*
* One instance can be used to create multiple instances.
* An instance of this object must not be used concurrently (an object has a state).
* @author mse
*/
class epicsShareClass NTScalarArrayBuilder :
public std::tr1::enable_shared_from_this<NTScalarArrayBuilder>
{
public:
POINTER_DEFINITIONS(NTScalarArrayBuilder);
/**
* Sets the value type of the NTScalarArray.
* @param elementType the value field element ScalarType.
* @return this instance of <b>NTScalarArrayBuilder</b>.
*/
shared_pointer value(epics::pvData::ScalarType elementType);
/**
* Sets the value type of the NTScalarArray.
* @param elementType the value field element ScalarType.
* @return this instance of <b>NTScalarArrayBuilder</b>.
* @deprecated use value instead.
*/
shared_pointer arrayValue(epics::pvData::ScalarType elementType);
/**
* Adds descriptor field to the NTScalarArray.
* @return this instance of <b>NTScalarArrayBuilder</b>.
*/
shared_pointer addDescriptor();
/**
* Adds alarm field to the NTScalarArray.
* @return this instance of <b>NTScalarArrayBuilder</b>.
*/
shared_pointer addAlarm();
/**
* Adds timeStamp field to the NTScalarArray.
* @return this instance of <b>NTScalarArrayBuilder</b>.
*/
shared_pointer addTimeStamp();
/**
* Adds display field to the NTScalarArray.
* @return this instance of <b>NTScalarArrayBuilder</b>.
*/
shared_pointer addDisplay();
/**
* Adds control field to the NTScalarArray.
* @return this instance of <b>NTScalarArrayBuilder</b>.
*/
shared_pointer addControl();
/**
* Creates a <b>Structure</b> that represents NTScalarArray.
* This resets this instance state and allows new instance to be created.
* @return a new instance of <b>Structure</b>.
*/
epics::pvData::StructureConstPtr createStructure();
/**
* Creates a <b>PVStructure</b> that represents NTScalarArray.
* This resets this instance state and allows new instance to be created.
* @return a new instance of <b>PVStructure</b>.
*/
epics::pvData::PVStructurePtr createPVStructure();
/**
* Creates a <b>NTScalarArray</b> instance.
* This resets this instance state and allows new instance to be created.
* @return a new instance of <b>NTScalarArray</b>.
*/
NTScalarArrayPtr create();
/**
* Adds extra <b>Field</b> to the type.
* @param name the name of the field.
* @param field the field to be added.
* @return this instance of <b>NTScalarArrayBuilder</b>.
*/
shared_pointer add(std::string const & name, epics::pvData::FieldConstPtr const & field);
private:
NTScalarArrayBuilder();
void reset();
bool valueTypeSet;
epics::pvData::ScalarType valueType;
bool descriptor;
bool alarm;
bool timeStamp;
bool display;
bool control;
// NOTE: this preserves order, however it does not handle duplicates
epics::pvData::StringArray extraFieldNames;
epics::pvData::FieldConstPtrArray extraFields;
friend class ::epics::nt::NTScalarArray;
};
}
typedef std::tr1::shared_ptr<detail::NTScalarArrayBuilder> NTScalarArrayBuilderPtr;
/**
* @brief Convenience Class for NTScalarArray
*
* @author mrk
*/
class epicsShareClass NTScalarArray
{
public:
POINTER_DEFINITIONS(NTScalarArray);
static const std::string URI;
/**
* Creates an NTScalarArray wrapping the specified PVStructure if the latter is compatible.
* <p>
* Checks the supplied PVStructure is compatible with NTScalarArray
* and if so returns an NTScalarArray which wraps it.
* This method will return null if the structure is is not compatible
* or is null.
*
* @param pvStructure the PVStructure to be wrapped
* @return NTScalarArray instance wrapping pvStructure on success, null otherwise
*/
static shared_pointer wrap(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Creates an NTScalarArray wrapping the specified PVStructure, regardless of the latter's compatibility.
* <p>
* No checks are made as to whether the specified PVStructure
* is compatible with NTScalarArray or is non-null.
*
* @param pvStructure the PVStructure to be wrapped
* @return NTScalarArray instance wrapping pvStructure
*/
static shared_pointer wrapUnsafe(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Returns whether the specified Structure reports to be a compatible NTScalarArray.
* <p>
* Checks if the specified Structure reports compatibility with this
* version of NTScalarArray through its type ID, including checking version numbers.
* The return value does not depend on whether the structure is actually
* compatible in terms of its introspection type.
*
* @param structure the Structure to test
* @return (false,true) if the specified Structure (is not, is) a compatible NTScalarArray
*/
static bool is_a(epics::pvData::StructureConstPtr const & structure);
/**
* Returns whether the specified PVStructure reports to be a compatible NTScalarArray.
* <p>
* Checks if the specified PVStructure reports compatibility with this
* version of NTScalarArray through its type ID, including checking version numbers.
* The return value does not depend on whether the structure is actually
* compatible in terms of its introspection type.
*
* @param pvStructure the PVStructure to test
* @return (false,true) if the specified PVStructure (is not, is) a compatible NTScalarArray
*/
static bool is_a(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Returns whether the specified Structure is compatible with NTScalarArray.
* <p>
* Checks if the specified Structure is compatible with this version
* of NTScalarArray through the introspection interface.
*
* @param structure the Structure to test.
* @return (false,true) if the specified Structure (is not, is) a compatible NTScalarArray
*/
static bool isCompatible(
epics::pvData::StructureConstPtr const &structure);
/**
* Returns whether the specified PVStructure is compatible with NTScalarArray.
* <p>
* Checks if the specified PVStructure is compatible with this version
* of NTScalarArray through the introspection interface.
*
* @param pvStructure the PVStructure to test
* @return (false,true) if the specified PVStructure (is not, is) a compatible NTScalarArray
*/
static bool isCompatible(
epics::pvData::PVStructurePtr const &pvStructure);
/**
* Returns whether the wrapped PVStructure is a valid NTScalarArray.
* <p>
* Unlike isCompatible(), isValid() may perform checks on the value
* data as well as the introspection data.
*
* @return (false,true) if the wrapped PVStructure (is not, is) a valid NTScalarArray.
*/
bool isValid();
/**
* Creates an NTScalarArray builder instance.
* @return builder instance.
*/
static NTScalarArrayBuilderPtr createBuilder();
/**
* Destructor.
*/
~NTScalarArray() {}
/**
* Attaches a PVTimeStamp to the wrapped PVStructure.
* Does nothing if no timeStamp field.
* @param pvTimeStamp the PVTimeStamp that will be attached.
* @return true if the operation was successfull (i.e. this instance has a timeStamp field), otherwise false.
*/
bool attachTimeStamp(epics::pvData::PVTimeStamp &pvTimeStamp) const;
/**
* Attaches a PVAlarm to the wrapped PVStructure.
* Does nothing if no alarm field.
* @param pvAlarm the PVAlarm that will be attached.
* @return true if the operation was successfull (i.e. this instance has an alarm field), otherwise false.
*/
bool attachAlarm(epics::pvData::PVAlarm &pvAlarm) const;
/**
* Attaches a PVDisplay to the wrapped PVStructure.
* Does nothing if no display field.
* @param pvDisplay the PVDisplay that will be attached.
* @return true if the operation was successfull (i.e. this instance has a display field), otherwise false.
*/
bool attachDisplay(epics::pvData::PVDisplay &pvDisplay) const;
/**
* Attaches an pvControl.
* @param pvControl The pvControl that will be attached.
* Does nothing if no control field.
* @return true if the operation was successfull (i.e. this instance has a control field), otherwise false.
*/
bool attachControl(epics::pvData::PVControl &pvControl) const;
/**
* Returns the PVStructure wrapped by this instance.
* @return the PVStructure wrapped by this instance.
*/
epics::pvData::PVStructurePtr getPVStructure() const;
/**
* Returns the descriptor field.
* @return the descriptor field or null if no descriptor field.
*/
epics::pvData::PVStringPtr getDescriptor() const;
/**
* Returns the timeStamp field.
* @return the timStamp field or null if no timeStamp field.
*/
epics::pvData::PVStructurePtr getTimeStamp() const;
/**
* Returns the alarm field.
* @return the alarm field or null if no alarm field.
*/
epics::pvData::PVStructurePtr getAlarm() const;
/**
* Returns the display.
* @return PVStructurePtr which may be null.
*/
epics::pvData::PVStructurePtr getDisplay() const;
/**
* Returns the control.
* @return PVStructurePtr which may be null.
*/
epics::pvData::PVStructurePtr getControl() const;
/**
* Returns the value field.
* @return The PVField for the values.
*/
epics::pvData::PVFieldPtr getValue() const;
/**
* Returns the value field of a specified type (e.g. PVDoubleArray).
* @tparam PVT the expected type of the value field which should be
* be PVScalarArray or a derived class.
* @return the value field or null if it is not of the expected type.
*/
template<typename PVT>
std::tr1::shared_ptr<PVT> getValue() const
{
return std::tr1::dynamic_pointer_cast<PVT>(pvValue);
}
private:
NTScalarArray(epics::pvData::PVStructurePtr const & pvStructure);
epics::pvData::PVStructurePtr pvNTScalarArray;
epics::pvData::PVFieldPtr pvValue;
friend class detail::NTScalarArrayBuilder;
};
}}
#endif /* NTSCALARARRAY_H */

View File

@@ -0,0 +1,423 @@
/* ntscalarMultiChannel.h */
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#ifndef NTSCALARMULTICHANNEL_H
#define NTSCALARMULTICHANNEL_H
#include <vector>
#include <string>
#ifdef epicsExportSharedSymbols
# define ntscalarMultiChannelEpicsExportSharedSymbols
# undef epicsExportSharedSymbols
#endif
#include <pv/pvDisplay.h>
#include <pv/pvControl.h>
#ifdef ntscalarMultiChannelEpicsExportSharedSymbols
# define epicsExportSharedSymbols
# undef ntscalarMultiChannelEpicsExportSharedSymbols
#endif
#include <pv/ntfield.h>
#include <shareLib.h>
namespace epics { namespace nt {
class NTScalarMultiChannel;
typedef std::tr1::shared_ptr<NTScalarMultiChannel> NTScalarMultiChannelPtr;
namespace detail {
/**
* @brief Interface for in-line creating of NTScalarMultiChannel.
*
* One instance can be used to create multiple instances.
* An instance of this object must not be used concurrently (an object has a state).
* @author dgh
* @author mse
*/
class epicsShareClass NTScalarMultiChannelBuilder :
public std::tr1::enable_shared_from_this<NTScalarMultiChannelBuilder>
{
public:
POINTER_DEFINITIONS(NTScalarMultiChannelBuilder);
/**
* Sets the scalar type for the value field.
* If this is not called then pvDouble is the default.
* @param scalarType the value field element ScalarType.
* @return this instance of <b>NTScalarMultiChannelBuilder</b>.
*/
shared_pointer value(epics::pvData::ScalarType scalarType);
/**
* Adds descriptor field to the NTScalarMultiChannel.
* @return this instance of <b>NTScalarMultiChannelBuilder</b>.
*/
shared_pointer addDescriptor();
/**
* Adds alarm field to the NTScalarMultiChannel.
* @return this instance of <b>NTScalarMultiChannelBuilder</b>.
*/
shared_pointer addAlarm();
/**
* Adds timeStamp field to the NTScalarMultiChannel.
* @return this instance of <b>NTScalarMultiChannelBuilder</b>.
*/
shared_pointer addTimeStamp();
/**
* Adds severity array to the NTScalarMultiChannel.
* @return this instance of <b>NTScalarMultiChannelBuilder</b>.
*/
shared_pointer addSeverity();
/**
* Adds status array to the NTScalarMultiChannel.
* @return this instance of <b>NTScalarMultiChannelBuilder</b>.
*/
shared_pointer addStatus();
/**
* Adds message array to the NTScalarMultiChannel.
* @return this instance of <b>NTScalarMultiChannelBuilder</b>.
*/
shared_pointer addMessage();
/**
* Adds secondsPastEpoch array to the NTScalarMultiChannel.
* @return this instance of <b>NTScalarMultiChannelBuilder</b>.
*/
shared_pointer addSecondsPastEpoch();
/**
* Adds nanoseconds array to the NTScalarMultiChannel.
* @return this instance of <b>NTScalarMultiChannelBuilder</b>.
*/
shared_pointer addNanoseconds();
/**
* Adds userTag array to the NTScalarMultiChannel.
* @return this instance of <b>NTScalarMultiChannelBuilder</b>.
*/
shared_pointer addUserTag();
/**
* Adds isConnected array to the NTScalarMultiChannel.
* @return this instance of <b>NTScalarMultiChannelBuilder</b>.
*/
shared_pointer addIsConnected();
/**
* Creates a <b>Structure</b> that represents NTScalarMultiChannel.
* This resets this instance state and allows new instance to be created.
* @return a new instance of a <b>Structure</b>.
*/
epics::pvData::StructureConstPtr createStructure();
/**
* Creates a <b>PVStructure</b> that represents NTScalarMultiChannel.
* This resets this instance state and allows new instance to be created.
* @return a new instance of a <b>PVStructure</b>
*/
epics::pvData::PVStructurePtr createPVStructure();
/**
* Creates a <b>NTScalarMultiChannel</b> instance.
* This resets this instance state and allows new instance to be created.
* @return a new instance of a <b>NTScalarMultiChannel</b>
*/
NTScalarMultiChannelPtr create();
/**
* Adds extra <b>Field</b> to the type.
* @param name the name of the field.
* @param field the field to be added.
* @return this instance of a <b>NTScalarMultiChannelBuilder</b>
*/
shared_pointer add(std::string const & name, epics::pvData::FieldConstPtr const & field);
private:
NTScalarMultiChannelBuilder();
void reset();
epics::pvData::ScalarType valueType;
bool descriptor;
bool alarm;
bool timeStamp;
bool severity;
bool status;
bool message;
bool secondsPastEpoch;
bool nanoseconds;
bool userTag;
bool isConnected;
// NOTE: this preserves order, however it does not handle duplicates
epics::pvData::StringArray extraFieldNames;
epics::pvData::FieldConstPtrArray extraFields;
friend class ::epics::nt::NTScalarMultiChannel;
};
}
typedef std::tr1::shared_ptr<detail::NTScalarMultiChannelBuilder> NTScalarMultiChannelBuilderPtr;
/**
* @brief Convenience Class for NTScalarMultiChannel
* @author dgh
* @author mrk
*
*/
class epicsShareClass NTScalarMultiChannel
{
public:
POINTER_DEFINITIONS(NTScalarMultiChannel);
static const std::string URI;
/**
* Creates an NTScalarMultiChannel wrapping the specified PVStructure if the latter is compatible.
* <p>
* Checks the supplied PVStructure is compatible with NTScalarMultiChannel
* and if so returns an NTScalarMultiChannel which wraps it.
* This method will return null if the structure is is not compatible
* or is null.
*
* @param pvStructure the PVStructure to be wrapped
* @return NTScalarMultiChannel instance wrapping pvStructure on success, null otherwise
*/
static shared_pointer wrap(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Creates an NTScalarMultiChannel wrapping the specified PVStructure, regardless of the latter's compatibility.
* <p>
* No checks are made as to whether the specified PVStructure
* is compatible with NTScalarMultiChannel or is non-null.
*
* @param pvStructure the PVStructure to be wrapped
* @return NTScalarMultiChannel instance wrapping pvStructure
*/
static shared_pointer wrapUnsafe(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Returns whether the specified Structure reports to be a compatible NTScalarMultiChannel.
* <p>
* Checks if the specified Structure reports compatibility with this
* version of NTScalarMultiChannel through its type ID, including checking version numbers.
* The return value does not depend on whether the structure is actually
* compatible in terms of its introspection type.
*
* @param structure the Structure to test
* @return (false,true) if the specified Structure (is not, is) a compatible NTScalarMultiChannel
*/
static bool is_a(epics::pvData::StructureConstPtr const & structure);
/**
* Returns whether the specified PVStructure reports to be a compatible NTScalarMultiChannel.
* <p>
* Checks if the specified PVStructure reports compatibility with this
* version of NTScalarMultiChannel through its type ID, including checking version numbers.
* The return value does not depend on whether the structure is actually
* compatible in terms of its introspection type.
*
* @param pvStructure the PVStructure to test
* @return (false,true) if the specified PVStructure (is not, is) a compatible NTScalarMultiChannel
*/
static bool is_a(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Returns whether the specified Structure is compatible with NTScalarMultiChannel.
* <p>
* Checks if the specified Structure is compatible with this version
* of NTScalarMultiChannel through the introspection interface.
*
* @param structure the Structure to test
* @return (false,true) if the specified Structure (is not, is) a compatible NTScalarMultiChannel
*/
static bool isCompatible(
epics::pvData::StructureConstPtr const &structure);
/**
* Returns whether the wrapped PVStructure is a valid NTScalarMultiChannel.
* <p>
* Unlike isCompatible(), isValid() may perform checks on the value
* data as well as the introspection data.
*
* @return (false,true) if wrapped PVStructure (is not, is) a valid NTScalarMultiChannel
*/
static bool isCompatible(
epics::pvData::PVStructurePtr const &pvStructure);
/**
* Returns whether the specified PVStructure is a valid NTScalarMultiChannel.
* <p>
* Unlike isCompatible(), isValid() may perform checks on the value
* data as well as the introspection data.
*
* @return (false,true) if wrapped PVStructure (is not, is) a valid NTScalarMultiChannel.
*/
bool isValid();
/**
* Creates an NTScalarMultiChannelBuilder instance
* @return builder instance.
*/
static NTScalarMultiChannelBuilderPtr createBuilder();
/**
* Destructor
*/
~NTScalarMultiChannel() {}
/**
* Attaches a PVTimeStamp to the wrapped PVStructure.
* Does nothing if no timeStamp field.
* @param pvTimeStamp the PVTimeStamp that will be attached.
* @return true if the operation was successfull (i.e. this instance has a timeStamp field), otherwise false.
*/
bool attachTimeStamp(epics::pvData::PVTimeStamp &pvTimeStamp) const;
/**
* Attaches a PVAlarm to the wrapped PVStructure.
* Does nothing if no alarm field.
* @param pvAlarm the PVAlarm that will be attached.
* @return true if the operation was successfull (i.e. this instance has an alarm field), otherwise false.
*/
bool attachAlarm(epics::pvData::PVAlarm &pvAlarm) const;
/**
* Returns the PVStructure wrapped by this instance.
* @return the PVStructure wrapped by this instance.
*/
epics::pvData::PVStructurePtr getPVStructure() const
{return pvNTScalarMultiChannel;}
/**
* Return the descriptor field.
* @return the descriptor field or null if no descriptor field.
*/
epics::pvData::PVStringPtr getDescriptor() const
{return pvDescriptor;}
/**
* Returns the timeStamp field.
* @return the timeStamp field or null if no such field.
*/
epics::pvData::PVStructurePtr getTimeStamp() const
{return pvTimeStamp;}
/**
* Returns the alarm field.
* @return the alarm field or null if no such field.
*/
epics::pvData::PVStructurePtr getAlarm() const
{return pvAlarm;}
/**
* Returns the field with the value of each channel.
* @return the value field.
*/
epics::pvData::PVScalarArrayPtr getValue() const
{return pvValue;}
/**
* Returns the value of each channel of a specified expected type
* (for example, PVDoubleArray).
* @tparam PVT the expected type of the value field which should be
* be PVScalarArray or a derived class.
* @return the value field or null if it is not of the expected type.
*/
template<typename PVT>
std::tr1::shared_ptr<PVT> getValue() const
{
return std::tr1::dynamic_pointer_cast<PVT>(pvValue);
}
/**
* Returns the field with the channelName of each channel.
* @return the channelName field
*/
epics::pvData::PVStringArrayPtr getChannelName() const
{ return pvChannelName;};
/**
* Returns the field with the connection state of each channel.
* @return the isConnected field or null if no such field
*/
epics::pvData::PVBooleanArrayPtr getIsConnected() const
{ return pvIsConnected;};
/**
* Returns the field with the severity of each channel.
* @return the severity field or null if no such field
*/
epics::pvData::PVIntArrayPtr getSeverity() const
{return pvSeverity;}
/**
* Returns the field with the status of each channel.
* @return the status field or null if no such field
*/
epics::pvData::PVIntArrayPtr getStatus() const
{return pvStatus;}
/**
* Returns the field with the message of each channel.
* @return message field or null if no such field.
*/
epics::pvData::PVStringArrayPtr getMessage() const
{return pvMessage;}
/**
* Returns the field with the secondsPastEpoch of each channel.
* @return the secondsPastEpoch field or null if no such field.
*/
epics::pvData::PVLongArrayPtr getSecondsPastEpoch() const
{return pvSecondsPastEpoch;}
/**
* Returns the field with the nanoseconds of each channel.
* @return nanoseconds field or null if no such field.
*/
epics::pvData::PVIntArrayPtr getNanoseconds() const
{return pvNanoseconds;}
/**
* Returns the field with the userTag of each channel.
* @return the userTag field or null if no such field.
*/
epics::pvData::PVIntArrayPtr getUserTag() const
{return pvUserTag;}
private:
NTScalarMultiChannel(epics::pvData::PVStructurePtr const & pvStructure);
epics::pvData::PVStructurePtr pvNTScalarMultiChannel;
epics::pvData::PVStructurePtr pvTimeStamp;
epics::pvData::PVStructurePtr pvAlarm;
epics::pvData::PVScalarArrayPtr pvValue;
epics::pvData::PVStringArrayPtr pvChannelName;
epics::pvData::PVBooleanArrayPtr pvIsConnected;
epics::pvData::PVIntArrayPtr pvSeverity;
epics::pvData::PVIntArrayPtr pvStatus;
epics::pvData::PVStringArrayPtr pvMessage;
epics::pvData::PVLongArrayPtr pvSecondsPastEpoch;
epics::pvData::PVIntArrayPtr pvNanoseconds;
epics::pvData::PVIntArrayPtr pvUserTag;
epics::pvData::PVStringPtr pvDescriptor;
friend class detail::NTScalarMultiChannelBuilder;
};
}}
#endif /* NTSCALARMULTICHANNEL_H */

326
src/pv/nttable.h Normal file
View File

@@ -0,0 +1,326 @@
/* nttable.h */
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#ifndef NTTABLE_H
#define NTTABLE_H
#include <vector>
#include <string>
#ifdef epicsExportSharedSymbols
# define nttableEpicsExportSharedSymbols
# undef epicsExportSharedSymbols
#endif
#include <pv/pvDisplay.h>
#include <pv/pvControl.h>
#ifdef nttableEpicsExportSharedSymbols
# define epicsExportSharedSymbols
# undef nttableEpicsExportSharedSymbols
#endif
#include <pv/ntfield.h>
#include <shareLib.h>
namespace epics { namespace nt {
class NTTable;
typedef std::tr1::shared_ptr<NTTable> NTTablePtr;
namespace detail {
/**
* @brief Interface for in-line creating of NTTable.
*
* One instance can be used to create multiple instances.
* An instance of this object must not be used concurrently (an object has a state).
* @author mse
*/
class epicsShareClass NTTableBuilder :
public std::tr1::enable_shared_from_this<NTTableBuilder>
{
public:
POINTER_DEFINITIONS(NTTableBuilder);
/**
* Adds a column of given <b>Scalar</b> type.
* @param name name of the column.
* @param elementType column type, a scalar array.
* @return this instance of <b>NTTableBuilder</b>.
*/
shared_pointer addColumn(std::string const & name, epics::pvData::ScalarType elementType);
/**
* Adds descriptor field to the NTTable.
* @return this instance of <b>NTTableBuilder</b>.
*/
shared_pointer addDescriptor();
/**
* Adds alarm field to the NTTable.
* @return this instance of <b>NTTableBuilder</b>.
*/
shared_pointer addAlarm();
/**
* Adds timeStamp field to the NTTable.
* @return this instance of <b>NTTableBuilder</b>.
*/
shared_pointer addTimeStamp();
/**
* Creates a <b>Structure</b> that represents NTTable.
* This resets this instance state and allows new instance to be created.
* @return a new instance of <b>Structure</b>.
*/
epics::pvData::StructureConstPtr createStructure();
/**
* Creates a <b>PVStructure</b> that represents NTTable.
* The returned PVStructure will have labels equal to the column names.
* This resets this instance state and allows new instance to be created.
* @return a new instance of <b>PVStructure</b>.
*/
epics::pvData::PVStructurePtr createPVStructure();
/**
* Creates a <b>NTTable</b> instance.
* The returned NTTable will wrap a PVStructure which will have
* labels equal to the column names.
* This resets this instance state and allows new instance to be created.
* @return a new instance of <b>NTTable</b>.
*/
NTTablePtr create();
/**
* Adds extra <b>Field</b> to the type.
* @param name the name of the field.
* @param field the field to be added.
* @return this instance of <b>NTTableBuilder</b>.
*/
shared_pointer add(std::string const & name, epics::pvData::FieldConstPtr const & field);
private:
NTTableBuilder();
void reset();
std::vector<std::string> columnNames;
std::vector<epics::pvData::ScalarType> types;
bool descriptor;
bool alarm;
bool timeStamp;
// NOTE: this preserves order, however it does not handle duplicates
epics::pvData::StringArray extraFieldNames;
epics::pvData::FieldConstPtrArray extraFields;
friend class ::epics::nt::NTTable;
};
}
typedef std::tr1::shared_ptr<detail::NTTableBuilder> NTTableBuilderPtr;
/**
* @brief Convenience Class for NTTable
*
* @author mrk
*/
class epicsShareClass NTTable
{
public:
POINTER_DEFINITIONS(NTTable);
static const std::string URI;
/**
* Creates an NTTable wrapping the specified PVStructure if the latter is compatible.
* <p>
* Checks the supplied PVStructure is compatible with NTTable
* and if so returns an NTTable which wraps it.
* This method will return null if the structure is is not compatible
* or is null.
*
* @param pvStructure the PVStructure to be wrapped
* @return NTTable instance wrapping pvStructure on success, null otherwise
*/
static shared_pointer wrap(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Creates an NTTable wrapping the specified PVStructure, regardless of the latter's compatibility.
* <p>
* No checks are made as to whether the specified PVStructure
* is compatible with NTTable or is non-null.
*
* @param pvStructure the PVStructure to be wrapped
* @return NTTable instance wrapping pvStructure
*/
static shared_pointer wrapUnsafe(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Returns whether the specified Structure reports to be a compatible NTTable.
* <p>
* Checks if the specified Structure reports compatibility with this
* version of NTTable through its type ID, including checking version numbers.
* The return value does not depend on whether the structure is actually
* compatible in terms of its introspection type.
*
* @param structure the Structure to test
* @return (false,true) if the specified Structure (is not, is) a compatible NTTable
*/
static bool is_a(epics::pvData::StructureConstPtr const & structure);
/**
* Returns whether the specified PVStructure reports to be a compatible NTTable.
* <p>
* Checks if the specified PVStructure reports compatibility with this
* version of NTTable through its type ID, including checking version numbers.
* The return value does not depend on whether the structure is actually
* compatible in terms of its introspection type.
*
* @param pvStructure the PVStructure to test
* @return (false,true) if the specified PVStructure (is not, is) a compatible NTTable
*/
static bool is_a(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Returns whether the specified Structure is compatible with NTTable.
* <p>
* Checks if the specified Structure is compatible with this version
* of NTTable through the introspection interface.
*
* @param structure the Structure to test
* @return (false,true) if the specified Structure (is not, is) a compatible NTTable
*/
static bool isCompatible(
epics::pvData::StructureConstPtr const &structure);
/**
* Returns whether the specified PVStructure is compatible with NTTable.
*
* Checks if the specified PVStructure is compatible with this version
* of NTTable through the introspection interface.
*
* @param pvStructure the PVStructure to test
* @return (false,true) if the specified PVStructure (is not, is) a compatible NTTable
*/
static bool isCompatible(
epics::pvData::PVStructurePtr const &pvStructure);
/**
* Returns whether the specified structure is a valid NTTable.
* <p>
* Unlike isCompatible(), isValid() may perform checks on the value
* data as well as the introspection data.
*
* @return (false,true) if wrapped PVStructure (is not, is) a valid NTTable
*/
bool isValid();
/**
* Creates an NTTable builder instance.
* @return builder instance.
*/
static NTTableBuilderPtr createBuilder();
/**
* Destructor.
*/
~NTTable() {}
/**
* Attaches a PVTimeStamp to the wrapped PVStructure.
* Does nothing if no timeStamp field.
* @param pvTimeStamp the PVTimeStamp that will be attached.
* @return true if the operation was successfull (i.e. this instance has a timeStamp field), otherwise false.
*/
bool attachTimeStamp(epics::pvData::PVTimeStamp &pvTimeStamp) const;
/**
* Attaches a PVAlarm to the wrapped PVStructure.
* Does nothing if no alarm field.
* @param pvAlarm the PVAlarm that will be attached.
* @return true if the operation was successfull (i.e. this instance has an alarm field), otherwise false.
*/
bool attachAlarm(epics::pvData::PVAlarm &pvAlarm) const;
/**
* Returns the PVStructure wrapped by this instance.
* @return the PVStructure wrapped by this instance.
*/
epics::pvData::PVStructurePtr getPVStructure() const;
/**
* Returns the descriptor field.
* @return the descriptor field or null if no descriptor field.
*/
epics::pvData::PVStringPtr getDescriptor() const;
/**
* Returns the timeStamp field.
* @return the timStamp field or null if no such field.
*/
epics::pvData::PVStructurePtr getTimeStamp() const;
/**
* Returns the alarm field.
* @return the alarm field or null if no such field.
*/
epics::pvData::PVStructurePtr getAlarm() const;
/**
* Returns the labels field.
* @return the labels field.
*/
epics::pvData::PVStringArrayPtr getLabels() const;
/**
* Returns the column names for the table.
* For each name, calling getColumn should return the column, which should not be null.
* @return the column names.
*/
epics::pvData::StringArray const & getColumnNames() const;
/**
* Returns the PVField for the column with the specified colum name.
* @param columnName the name of the column.
* @return the field for the column or null if column does not exist.
*/
epics::pvData::PVFieldPtr getColumn(std::string const & columnName) const;
/**
* Returns the column with the specified column name and of a specified
* expected type (for example, PVDoubleArray).
* @tparam PVT the expected type of the column which should be
* be PVScalarArray or a derived class.
* @param columnName the name of the column.
* @return the field for the column or null if column does not exist
* or is not of the specified type.
*/
template<typename PVT>
std::tr1::shared_ptr<PVT> getColumn(std::string const & columnName) const
{
epics::pvData::PVFieldPtr pvField = getColumn(columnName);
if (pvField.get())
return std::tr1::dynamic_pointer_cast<PVT>(pvField);
else
return std::tr1::shared_ptr<PVT>();
}
private:
NTTable(epics::pvData::PVStructurePtr const & pvStructure);
epics::pvData::PVStructurePtr pvNTTable;
epics::pvData::PVStructurePtr pvValue;
friend class detail::NTTableBuilder;
};
}}
#endif /* NTTABLE_H */

280
src/pv/ntunion.h Normal file
View File

@@ -0,0 +1,280 @@
/* ntunion.h */
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#ifndef NTUNION_H
#define NTUNION_H
#ifdef epicsExportSharedSymbols
# define ntunionEpicsExportSharedSymbols
# undef epicsExportSharedSymbols
#endif
#ifdef ntunionEpicsExportSharedSymbols
# define epicsExportSharedSymbols
# undef ntunionEpicsExportSharedSymbols
#endif
#include <pv/ntfield.h>
#include <shareLib.h>
namespace epics { namespace nt {
class NTUnion;
typedef std::tr1::shared_ptr<NTUnion> NTUnionPtr;
namespace detail {
/**
* @brief Interface for in-line creating of NTUnion.
*
* One instance can be used to create multiple instances.
* An instance of this object must not be used concurrently (an object has a state).
* @author dgh
*/
class epicsShareClass NTUnionBuilder :
public std::tr1::enable_shared_from_this<NTUnionBuilder>
{
public:
POINTER_DEFINITIONS(NTUnionBuilder);
/**
* Specifies the union for the value field.
* If this is not called then a variant union is the default.
* @param unionType the introspection object for the union value field
* @return this instance of NTUnionBuilder
*/
shared_pointer value(epics::pvData::UnionConstPtr unionType);
/**
* Adds descriptor field to the NTUnion.
* @return this instance of <b>NTUnionBuilder</b>.
*/
shared_pointer addDescriptor();
/**
* Adds alarm field to the NTUnion.
* @return this instance of <b>NTUnionBuilder</b>.
*/
shared_pointer addAlarm();
/**
* Adds timeStamp field to the NTUnion.
* @return this instance of <b>NTUnionBuilder</b>.
*/
shared_pointer addTimeStamp();
/**
* Creates a <b>Structure</b> that represents NTUnion.
* This resets this instance state and allows new instance to be created.
* @return a new instance of a <b>Structure</b>.
*/
epics::pvData::StructureConstPtr createStructure();
/**
* Creates a <b>PVStructure</b> that represents NTUnion.
* This resets this instance state and allows new instance to be created.
* @return a new instance of a <b>PVStructure</b>.
*/
epics::pvData::PVStructurePtr createPVStructure();
/**
* Creates a <b>NTUnion</b> instance.
* This resets this instance state and allows new instance to be created.
* @return a new instance of a <b>NTUnion</b>.
*/
NTUnionPtr create();
/**
* Adds extra <b>Field</b> to the type.
* @param name the name of the field.
* @param field the field to be added.
* @return this instance of <b>NTUnionBuilder</b>.
*/
shared_pointer add(std::string const & name, epics::pvData::FieldConstPtr const & field);
private:
NTUnionBuilder();
epics::pvData::UnionConstPtr valueType;
void reset();
bool descriptor;
bool alarm;
bool timeStamp;
// NOTE: this preserves order, however it does not handle duplicates
epics::pvData::StringArray extraFieldNames;
epics::pvData::FieldConstPtrArray extraFields;
friend class ::epics::nt::NTUnion;
};
}
typedef std::tr1::shared_ptr<detail::NTUnionBuilder> NTUnionBuilderPtr;
/**
* @brief Convenience Class for NTUnion
*
* @author dgh
*/
class epicsShareClass NTUnion
{
public:
POINTER_DEFINITIONS(NTUnion);
static const std::string URI;
/**
* Creates an NTUnion wrapping the specified PVStructure if the latter is compatible.
* <p>
* Checks the supplied PVStructure is compatible with NTUnion
* and if so returns an NTUnion which wraps it.
* This method will return null if the structure is is not compatible
* or is null.
*
* @param pvStructure the PVStructure to be wrapped
* @return NTUnion instance wrapping pvStructure on success, null otherwise
*/
static shared_pointer wrap(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Creates an NTUnion wrapping the specified PVStructure, regardless of the latter's compatibility.
* <p>
* No checks are made as to whether the specified PVStructure
* is compatible with NTUnion or is non-null.
* @param pvStructure the PVStructure to be wrapped
* @return NTUnion instance wrapping pvStructure
*/
static shared_pointer wrapUnsafe(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Returns whether the specified Structure reports to be a compatible NTUnion.
* <p>
* Checks if the specified Structure reports compatibility with this
* version of NTUnion through its type ID, including checking version numbers.
* The return value does not depend on whether the structure is actually
* compatible in terms of its introspection type.
*
* @param structure the Structure to test
* @return (false,true) if the specified Structure (is not, is) a compatible NTUnion
*/
static bool is_a(epics::pvData::StructureConstPtr const & structure);
/**
* Returns whether the specified PVStructure reports to be a compatible NTUnion.
*
* Checks if the specified PVStructure reports compatibility with this
* version of NTUnion through its type ID, including checking version numbers.
* The return value does not depend on whether the structure is actually
* compatible in terms of its introspection type.
*
* @param pvStructure the PVStructure to test
* @return (false,true) if the specified PVStructure (is not, is) a compatible NTUnion
*/
static bool is_a(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Returns whether the specified Structure is compatible with NTUnion.
* <p>
* Checks if the specified Structure is compatible with this version
* of NTUnion through the introspection interface.
* @param structure the Structure to test
* @return (false,true) if the specified Structure (is not, is) a compatible NTUnion
*/
static bool isCompatible(
epics::pvData::StructureConstPtr const &structure);
/**
* Returns whether the specified PVStructure is compatible with NTUnion.
* <p>
* Checks if the specified PVStructure is compatible with this version
* of NTUnion through the introspection interface
* @param pvStructure the PVStructure to test
* @return (false,true) if the specified PVStructure (is not, is) a compatible NTUnion
*/
static bool isCompatible(
epics::pvData::PVStructurePtr const &pvStructure);
/**
* Returns whether the wrapped PVStructure is a valid NTUnion.
* <p>
* Unlike isCompatible(), isValid() may perform checks on the value
* data as well as the introspection data.
*
* @return (false,true) if wrapped PVStructure (is not, is) a valid NTUnion
*/
bool isValid();
/**
* Creates an NTUnion builder instance.
* @return builder instance.
*/
static NTUnionBuilderPtr createBuilder();
/**
* Destructor.
*/
~NTUnion() {}
/**
* Attaches a PVTimeStamp to the wrapped PVStructure.
* Does nothing if no timeStamp field.
* @param pvTimeStamp the PVTimeStamp that will be attached.
* @return true if the operation was successfull (i.e. this instance has a timeStamp field), otherwise false.
*/
bool attachTimeStamp(epics::pvData::PVTimeStamp &pvTimeStamp) const;
/**
* Attaches a PVAlarm to the wrapped PVStructure.
* Does nothing if no alarm field.
* @param pvAlarm the PVAlarm that will be attached.
* @return true if the operation was successfull (i.e. this instance has an alarm field), otherwise false.
*/
bool attachAlarm(epics::pvData::PVAlarm &pvAlarm) const;
/**
* Returns the PVStructure wrapped by this instance.
* @return the PVStructure wrapped by this instance.
*/
epics::pvData::PVStructurePtr getPVStructure() const;
/**
* Returns the descriptor field.
* @return the descriptor field or null if no descriptor field.
*/
epics::pvData::PVStringPtr getDescriptor() const;
/**
* Returns the timeStamp field.
* @return the timStamp field or null if no timeStamp field.
*/
epics::pvData::PVStructurePtr getTimeStamp() const;
/**
* Returns the alarm field.
* @return the alarm field or null if no alarm field.
*/
epics::pvData::PVStructurePtr getAlarm() const;
/**
* Returns the value field.
* @return the value field.
*/
epics::pvData::PVUnionPtr getValue() const;
private:
NTUnion(epics::pvData::PVStructurePtr const & pvStructure);
epics::pvData::PVStructurePtr pvNTUnion;
epics::pvData::PVUnionPtr pvValue;
friend class detail::NTUnionBuilder;
};
}}
#endif /* NTUNION_H */

309
src/pv/nturi.h Normal file
View File

@@ -0,0 +1,309 @@
/* nturi.h */
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#ifndef NTURI_H
#define NTURI_H
#include <vector>
#include <string>
#ifdef epicsExportSharedSymbols
# define nturiEpicsExportSharedSymbols
# undef epicsExportSharedSymbols
#endif
#ifdef nturiEpicsExportSharedSymbols
# define epicsExportSharedSymbols
# undef nturiEpicsExportSharedSymbols
#endif
#include <pv/ntfield.h>
#include <shareLib.h>
namespace epics { namespace nt {
class NTURI;
typedef std::tr1::shared_ptr<NTURI> NTURIPtr;
namespace detail {
/**
* @brief Interface for in-line creating of NTURI.
*
* One instance can be used to create multiple instances.
* An instance of this object must not be used concurrently (an object has a state).
* @author dgh
*/
class epicsShareClass NTURIBuilder :
public std::tr1::enable_shared_from_this<NTURIBuilder>
{
public:
POINTER_DEFINITIONS(NTURIBuilder);
/**
* Adds authority field to the NTURI.
* @return this instance of <b>NTURIBuilder</b>.
*/
shared_pointer addAuthority();
/**
* Adds extra <b>Scalar</b> of ScalarType pvString
* to the query field of the type.
* @param name name of the field.
* @return this instance of <b>NTURIBuilder</b>.
*/
shared_pointer addQueryString(std::string const & name);
/**
* Adds extra <b>Scalar</b> of ScalarType pvDouble
* to the query field of the type.
* @param name name of the field.
* @return this instance of <b>NTURIBuilder</b>.
*/
shared_pointer addQueryDouble(std::string const & name);
/**
* Adds extra <b>Scalar</b> of ScalarType pvInt
* to the query field of the type.
* @param name name of the field.
* @return this instance of <b>NTURIBuilder</b>.
*/
shared_pointer addQueryInt(std::string const & name);
/**
* Creates a <b>Structure</b> that represents NTURI.
* This resets this instance state and allows new instance to be created.
* @return a new instance of <b>Structure</b>.
*/
epics::pvData::StructureConstPtr createStructure();
/**
* Creates a <b>PVStructure</b> that represents NTURI.
* The returned PVStructure will have labels equal to the column names.
* This resets this instance state and allows new instance to be created.
* @return a new instance of <b>PVStructure</b>.
*/
epics::pvData::PVStructurePtr createPVStructure();
/**
* Creates a <b>NTURI</b> instance.
* The returned NTURI will wrap a PVStructure which will have
* labels equal to the column names.
* This resets this instance state and allows new instance to be created.
* @return a new instance of <b>NTURI</b>.
*/
NTURIPtr create();
/**
* Adds extra <b>Field</b> to the type.
* @param name the name of the field.
* @param field the field to be added.
* @return this instance of <b>NTURIBuilder</b>.
*/
shared_pointer add(std::string const & name, epics::pvData::FieldConstPtr const & field);
private:
NTURIBuilder();
void reset();
std::vector<std::string> queryFieldNames;
std::vector<epics::pvData::ScalarType> queryTypes;
bool authority;
// NOTE: this preserves order, however it does not handle duplicates
epics::pvData::StringArray extraFieldNames;
epics::pvData::FieldConstPtrArray extraFields;
friend class ::epics::nt::NTURI;
};
}
typedef std::tr1::shared_ptr<detail::NTURIBuilder> NTURIBuilderPtr;
/**
* @brief Convenience Class for NTURI
*
* @author dgh
*/
class epicsShareClass NTURI
{
public:
POINTER_DEFINITIONS(NTURI);
static const std::string URI;
/**
* Creates an NTURI wrapping the specified PVStructure if the latter is compatible.
* <p>
* Checks the supplied PVStructure is compatible with NTURI
* and if so returns an NTURI which wraps it.
* This method will return null if the structure is is not compatible
* or is null.
*
* @param pvStructure the PVStructure to be wrapped
* @return NTURI instance wrapping pvStructure on success, null otherwise
*/
static shared_pointer wrap(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Creates an NTScalar wrapping the specified PVStructure, regardless of the latter's compatibility.
* <p>
* No checks are made as to whether the specified PVStructure
* is compatible with NTScalar or is non-null.
*
* @param pvStructure the PVStructure to be wrapped
* @return NTScalar instance wrapping pvStructure
*/
static shared_pointer wrapUnsafe(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Returns whether the specified Structure reports to be a compatible NTScalar.
* <p>
* Checks if the specified Structure reports compatibility with this
* version of NTScalar through its type ID, including checking version numbers.
* The return value does not depend on whether the structure is actually
* compatible in terms of its introspection type.
*
* @param structure the Structure to test
* @return (false,true) if (is not, is) a compatible NTScalar
*/
static bool is_a(epics::pvData::StructureConstPtr const & structure);
/**
* Returns whether the specified PVStructure reports to be a compatible NTURI.
* <p>
* Checks if the specified PVStructure reports compatibility with this
* version of NTURI through its type ID, including checking version numbers.
* The return value does not depend on whether the structure is actually
* compatible in terms of its introspection type.
*
* @param pvStructure the PVStructure to test.
* @return (false,true) if the specified PVStructure (is not, is) a compatible NTURI.
*/
static bool is_a(epics::pvData::PVStructurePtr const & pvStructure);
/**
* Returns whether the specified Structure is compatible with NTURI.
* <p>
* Checks if the specified Structure is compatible with this version
* of NTURI through the introspection interface.
*
* @param structure the Structure to test
* @return (false,true) if the specified Structure (is not, is) a compatible NTURI
*/
static bool isCompatible(
epics::pvData::StructureConstPtr const &structure);
/**
* Returns whether the specified PVStructure is compatible with NTURI.
* <p>
* Checks if the specified PVStructure is compatible with this version
* of NTURI through the introspection interface.
*
* @param pvStructure the PVStructure to test
* @return (false,true) if the specified PVStructure (is not, is) a compatible NTURI
*/
static bool isCompatible(
epics::pvData::PVStructurePtr const &pvStructure);
/**
* Returns whether the wrapped PVStructure is a valid NTURI.
* <p>
* Unlike isCompatible(), isValid() may perform checks on the value
* data as well as the introspection data.
*
* @return (false,true) if wrapped PVStructure (is not, is) a valid NTURI.
*/
bool isValid();
/**
* Creates an NTURI builder instance.
* @return builder instance.
*/
static NTURIBuilderPtr createBuilder();
/**
* Destructor.
*/
~NTURI() {}
/**
* Returns the PVStructure wrapped by this instance.
* @return the PVStructure wrapped by this instance.
*/
epics::pvData::PVStructurePtr getPVStructure() const;
/**
* Returns the scheme field.
* @return the scheme field.
*/
epics::pvData::PVStringPtr getScheme() const;
/**
* Returns the authority field.
* @return the authority field or null if no such field.
*/
epics::pvData::PVStringPtr getAuthority() const;
/**
* Returns the path field.
* @return the path field.
*/
epics::pvData::PVStringPtr getPath() const;
/**
* Returns the query field.
* @return the query field or null if no such field.
*/
epics::pvData::PVStructurePtr getQuery() const;
/**
* Returns the names of the query fields for the URI.
* For each name, calling getQueryField should return
* the query field, which should not be null.
* @return The query field names.
*/
epics::pvData::StringArray const & getQueryNames() const;
/**
* Returns the subfield of the query field with the specified name.
* @param name the name of the subfield.
* @return the the subfield of the query field or null if the field does not exist.
*/
epics::pvData::PVFieldPtr getQueryField(std::string const & name) const;
/**
* Returns the subfield of the query field (parameter) with the specified
* name and of a specified expected type (for example, PVString).
* @tparam PVT the expected type of the subfield which should be
* be PVString, PVInt pr PVDouble.
* @param name the subfield of the query field or null if the field does
* not exist or is not of the expected type.
* @return The PVT field.
*/
template<typename PVT>
std::tr1::shared_ptr<PVT> getQueryField(std::string const & name) const
{
epics::pvData::PVFieldPtr pvField = getQueryField(name);
if (pvField.get())
return std::tr1::dynamic_pointer_cast<PVT>(pvField);
else
return std::tr1::shared_ptr<PVT>();
}
private:
NTURI(epics::pvData::PVStructurePtr const & pvStructure);
epics::pvData::PVStructurePtr pvNTURI;
friend class detail::NTURIBuilder;
};
}}
#endif /* NTURI_H */

View File

@@ -1,8 +1,7 @@
/* ntutils.h */
/**
* Copyright - See the COPYRIGHT that is included with this distribution.
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#ifndef NTUTILS_H
#define NTUTILS_H
@@ -13,7 +12,8 @@
namespace epics { namespace nt {
/**
* Utility methods for NT types.
* @brief Utility methods for NT types.
*
* @author mse
*/
class epicsShareClass NTUtils {
@@ -22,9 +22,9 @@ public:
/**
* Checks whether NT types are compatible by checking their IDs,
* i.e. their names and major version must match.
* @param u1 the first uri.
* @param u2 the second uri.
* @return true of URIs are compatible, false otherwise.
* @param u1 the first URI.
* @param u2 the second URI.
* @return true if URIs are compatible, false otherwise.
*/
static bool is_a(const std::string &u1, const std::string &u2);

View File

@@ -1,5 +1,80 @@
TOP = ..
include $(TOP)/configure/CONFIG
DIRS += nt
include $(TOP)/configure/RULES_DIRS
TOP=..
include $(TOP)/configure/CONFIG
PROD_LIBS += nt pvData Com
TESTPROD_HOST += ntfieldTest
ntfieldTest_SRCS += ntfieldTest.cpp
TESTS += ntfieldTest
TESTPROD_HOST += ntscalarTest
ntscalarTest_SRCS += ntscalarTest.cpp
TESTS += ntscalarTest
TESTPROD_HOST += ntscalarArrayTest
ntscalarArrayTest_SRCS += ntscalarArrayTest.cpp
TESTS += ntscalarArrayTest
TESTPROD_HOST += ntnameValueTest
ntnameValueTest_SRCS += ntnameValueTest.cpp
TESTS += ntnameValueTest
TESTPROD_HOST += ntmultiChannelTest
ntmultiChannelTest_SRCS += ntmultiChannelTest.cpp
TESTS += ntmultiChannelTest
TESTPROD_HOST += ntscalarMultiChannelTest
ntscalarMultiChannelTest_SRCS += ntscalarMultiChannelTest.cpp
TESTS += ntscalarMultiChannelTest
TESTPROD_HOST += nttableTest
nttableTest_SRCS = nttableTest.cpp
TESTS += nttableTest
TESTPROD_HOST += ntndarrayTest
ntndarrayTest_SRCS = ntndarrayTest.cpp
TESTS += ntndarrayTest
TESTPROD_HOST += ntmatrixTest
ntmatrixTest_SRCS = ntmatrixTest.cpp
TESTS += ntmatrixTest
TESTPROD_HOST += ntenumTest
ntenumTest_SRCS = ntenumTest.cpp
TESTS += ntenumTest
TESTPROD_HOST += ntunionTest
ntunionTest_SRCS = ntunionTest.cpp
TESTS += ntunionTest
TESTPROD_HOST += ntaggregateTest
ntaggregateTest_SRCS = ntaggregateTest.cpp
TESTS += ntaggregateTest
TESTPROD_HOST += ntattributeTest
ntattributeTest_SRCS = ntattributeTest.cpp
TESTS += ntattributeTest
TESTPROD_HOST += ntndarrayAttributeTest
ntndarrayAttributeTest_SRCS = ntndarrayAttributeTest.cpp
TESTS += ntndarrayAttributeTest
TESTPROD_HOST += ntcontinuumTest
ntcontinuumTest = ntcontinuumTest.cpp
TESTS += ntcontinuumTest
TESTPROD_HOST += nthistogramTest
nthistogramTest_SRCS = nthistogramTest.cpp
TESTS += nthistogramTest
TESTPROD_HOST += ntutilsTest
ntutilsTest_SRCS = ntutilsTest.cpp
TESTS += ntutilsTest
TESTSCRIPTS_HOST += $(TESTS:%=%.t)
include $(TOP)/configure/RULES
#----------------------------------------
# ADD RULES AFTER THIS LINE

View File

@@ -1,44 +0,0 @@
TOP=../..
include $(TOP)/configure/CONFIG
PROD_LIBS += nt pvData Com
TESTPROD_HOST += ntfieldTest
ntfieldTest_SRCS += ntfieldTest.cpp
TESTS += ntfieldTest
TESTPROD_HOST += ntscalarTest
ntscalarTest_SRCS += ntscalarTest.cpp
TESTS += ntscalarTest
TESTPROD_HOST += ntscalarArrayTest
ntscalarArrayTest_SRCS += ntscalarArrayTest.cpp
TESTS += ntscalarArrayTest
TESTPROD_HOST += ntnameValueTest
ntnameValueTest_SRCS += ntnameValueTest.cpp
TESTS += ntnameValueTest
TESTPROD_HOST += ntmultiChannelTest
ntmultiChannelTest_SRCS += ntmultiChannelTest.cpp
TESTS += ntmultiChannelTest
TESTPROD_HOST += nttableTest
nttableTest_SRCS = nttableTest.cpp
TESTS += nttableTest
TESTPROD_HOST += ntndarrayTest
ntndarrayTest_SRCS = ntndarrayTest.cpp
TESTS += ntndarrayTest
TESTPROD_HOST += ntutilsTest
ntutilsTest_SRCS = ntutilsTest.cpp
TESTS += ntutilsTest
TESTSCRIPTS_HOST += $(TESTS:%=%.t)
include $(TOP)/configure/RULES
#----------------------------------------
# ADD RULES AFTER THIS LINE

177
test/ntaggregateTest.cpp Normal file
View File

@@ -0,0 +1,177 @@
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#include <epicsUnitTest.h>
#include <testMain.h>
#include <pv/nt.h>
using namespace epics::nt;
using namespace epics::pvData;
using std::tr1::dynamic_pointer_cast;
static FieldCreatePtr fieldCreate = getFieldCreate();
static StandardFieldPtr standardField = getStandardField();
static NTFieldPtr ntField = NTField::get();
void test_builder()
{
testDiag("test_builder");
NTAggregateBuilderPtr builder = NTAggregate::createBuilder();
testOk(builder.get() != 0, "Got builder");
StructureConstPtr structure = builder->
addDescriptor()->
addAlarm()->
addTimeStamp()->
add("valueAlarm",standardField->doubleAlarm()) ->
add("extra",fieldCreate->createScalarArray(pvString)) ->
createStructure();
testOk1(structure.get() != 0);
if (!structure)
return;
testOk1(NTAggregate::is_a(structure));
testOk1(structure->getID() == NTAggregate::URI);
testOk1(structure->getNumberFields() == 7);
testOk1(structure->getField("value").get() != 0);
testOk1(structure->getField("descriptor").get() != 0);
testOk1(structure->getField("alarm").get() != 0);
testOk1(structure->getField("timeStamp").get() != 0);
ScalarConstPtr valueField = structure->getField<Scalar>("value");
testOk(valueField.get() != 0, "value is scalar");
std::cout << *structure << std::endl;
}
void test_ntaggregate()
{
testDiag("test_ntaggregate");
NTAggregateBuilderPtr builder = NTAggregate::createBuilder();
testOk(builder.get() != 0, "Got builder");
NTAggregatePtr ntAggregate = builder->
addDescriptor()->
addAlarm()->
addTimeStamp()->
add("valueAlarm",standardField->intAlarm()) ->
create();
testOk1(ntAggregate.get() != 0);
testOk1(NTAggregate::is_a(ntAggregate->getPVStructure()));
testOk1(NTAggregate::isCompatible(ntAggregate->getPVStructure()));
testOk1(ntAggregate->getPVStructure().get() != 0);
testOk1(ntAggregate->getValue().get() != 0);
testOk1(ntAggregate->getDescriptor().get() != 0);
testOk1(ntAggregate->getAlarm().get() != 0);
testOk1(ntAggregate->getTimeStamp().get() != 0);
//
// example how to set a value
//
ntAggregate->getValue()->put(1.0);
//
// example how to get a value
//
double value = ntAggregate->getValue()->get();
testOk1(value == 1.0);
//
// timeStamp ops
//
PVTimeStamp pvTimeStamp;
if (ntAggregate->attachTimeStamp(pvTimeStamp))
{
testPass("timeStamp attach");
// example how to set current time
TimeStamp ts;
ts.getCurrent();
pvTimeStamp.set(ts);
// example how to get EPICS time
TimeStamp ts2;
pvTimeStamp.get(ts2);
testOk1(ts2.getEpicsSecondsPastEpoch() != 0);
}
else
testFail("timeStamp attach fail");
//
// alarm ops
//
PVAlarm pvAlarm;
if (ntAggregate->attachAlarm(pvAlarm))
{
testPass("alarm attach");
// example how to set an alarm
Alarm alarm;
alarm.setStatus(deviceStatus);
alarm.setSeverity(minorAlarm);
alarm.setMessage("simulation alarm");
pvAlarm.set(alarm);
}
else
testFail("alarm attach fail");
//
// set descriptor
//
ntAggregate->getDescriptor()->put("This is a test NTAggregate");
// dump ntAggregate
std::cout << *ntAggregate->getPVStructure() << std::endl;
}
void test_wrap()
{
testDiag("test_wrap");
NTAggregatePtr nullPtr = NTAggregate::wrap(PVStructurePtr());
testOk(nullPtr.get() == 0, "nullptr wrap");
nullPtr = NTAggregate::wrap(
getPVDataCreate()->createPVStructure(
NTField::get()->createTimeStamp()
)
);
testOk(nullPtr.get() == 0, "wrong type wrap");
NTAggregateBuilderPtr builder = NTAggregate::createBuilder();
testOk(builder.get() != 0, "Got builder");
PVStructurePtr pvStructure = builder->
createPVStructure();
testOk1(pvStructure.get() != 0);
if (!pvStructure)
return;
testOk1(NTAggregate::isCompatible(pvStructure)==true);
NTAggregatePtr ptr = NTAggregate::wrap(pvStructure);
testOk(ptr.get() != 0, "wrap OK");
ptr = NTAggregate::wrapUnsafe(pvStructure);
testOk(ptr.get() != 0, "wrapUnsafe OK");
}
MAIN(testNTAggregate) {
testPlan(30);
test_builder();
test_ntaggregate();
test_wrap();
return testDone();
}

177
test/ntattributeTest.cpp Normal file
View File

@@ -0,0 +1,177 @@
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#include <epicsUnitTest.h>
#include <testMain.h>
#include <pv/nt.h>
using namespace epics::nt;
using namespace epics::pvData;
using std::tr1::dynamic_pointer_cast;
static FieldCreatePtr fieldCreate = getFieldCreate();
static StandardFieldPtr standardField = getStandardField();
static NTFieldPtr ntField = NTField::get();
void test_builder()
{
testDiag("test_builder");
NTAttributeBuilderPtr builder = NTAttribute::createBuilder();
testOk(builder.get() != 0, "Got builder");
StructureConstPtr structure = builder->
addTags()->
addDescriptor()->
addAlarm()->
addTimeStamp()->
add("extra",fieldCreate->createScalar(pvString)) ->
createStructure();
testOk1(structure.get() != 0);
if (!structure)
return;
testOk1(NTAttribute::is_a(structure));
testOk1(structure->getID() == NTAttribute::URI);
testOk1(structure->getNumberFields() == 7);
testOk1(structure->getField("name").get() != 0);
testOk1(structure->getField("value").get() != 0);
testOk1(structure->getField("tags").get() != 0);
testOk1(structure->getField("descriptor").get() != 0);
testOk1(structure->getField("alarm").get() != 0);
testOk1(structure->getField("timeStamp").get() != 0);
ScalarConstPtr nameField = structure->getField<Scalar>("name");
testOk(nameField.get() != 0 && nameField->getScalarType() == pvString,
"name is string");
UnionConstPtr valueField = structure->getField<Union>("value");
testOk(valueField.get() != 0, "value is enum");
ScalarArrayConstPtr tagsField = structure->getField<ScalarArray>("tags");
testOk(tagsField.get() != 0 && tagsField->getElementType() == pvString,
"tags is string[]");
std::cout << *structure << std::endl;
}
void test_ntattribute()
{
testDiag("test_ntattribute");
NTAttributeBuilderPtr builder = NTAttribute::createBuilder();
testOk(builder.get() != 0, "Got builder");
NTAttributePtr ntAttribute = builder->
addTags()->
addDescriptor()->
addAlarm()->
addTimeStamp()->
create();
testOk1(ntAttribute.get() != 0);
testOk1(NTAttribute::is_a(ntAttribute->getPVStructure()));
testOk1(NTAttribute::isCompatible(ntAttribute->getPVStructure()));
testOk1(ntAttribute->getPVStructure().get() != 0);
testOk1(ntAttribute->getName().get() != 0);
testOk1(ntAttribute->getValue().get() != 0);
testOk1(ntAttribute->getTags().get() != 0);
testOk1(ntAttribute->getDescriptor().get() != 0);
testOk1(ntAttribute->getAlarm().get() != 0);
testOk1(ntAttribute->getTimeStamp().get() != 0);
//
// timeStamp ops
//
PVTimeStamp pvTimeStamp;
if (ntAttribute->attachTimeStamp(pvTimeStamp))
{
testPass("timeStamp attach");
// example how to set current time
TimeStamp ts;
ts.getCurrent();
pvTimeStamp.set(ts);
// example how to get EPICS time
TimeStamp ts2;
pvTimeStamp.get(ts2);
testOk1(ts2.getEpicsSecondsPastEpoch() != 0);
}
else
testFail("timeStamp attach fail");
//
// alarm ops
//
PVAlarm pvAlarm;
if (ntAttribute->attachAlarm(pvAlarm))
{
testPass("alarm attach");
// example how to set an alarm
Alarm alarm;
alarm.setStatus(deviceStatus);
alarm.setSeverity(minorAlarm);
alarm.setMessage("simulation alarm");
pvAlarm.set(alarm);
}
else
testFail("alarm attach fail");
//
// set descriptor
//
ntAttribute->getDescriptor()->put("This is a test NTAttribute");
// dump ntAttribute
std::cout << *ntAttribute->getPVStructure() << std::endl;
}
void test_wrap()
{
testDiag("test_wrap");
NTAttributePtr nullPtr = NTAttribute::wrap(PVStructurePtr());
testOk(nullPtr.get() == 0, "nullptr wrap");
nullPtr = NTAttribute::wrap(
getPVDataCreate()->createPVStructure(
NTField::get()->createTimeStamp()
)
);
testOk(nullPtr.get() == 0, "wrong type wrap");
NTAttributeBuilderPtr builder = NTAttribute::createBuilder();
testOk(builder.get() != 0, "Got builder");
PVStructurePtr pvStructure = builder->
createPVStructure();
testOk1(pvStructure.get() != 0);
if (!pvStructure)
return;
testOk1(NTAttribute::isCompatible(pvStructure)==true);
NTAttributePtr ptr = NTAttribute::wrap(pvStructure);
testOk(ptr.get() != 0, "wrap OK");
ptr = NTAttribute::wrapUnsafe(pvStructure);
testOk(ptr.get() != 0, "wrapUnsafe OK");
}
MAIN(testNTAttribute) {
testPlan(35);
test_builder();
test_ntattribute();
test_wrap();
return testDone();
}

278
test/ntcontinuumTest.cpp Normal file
View File

@@ -0,0 +1,278 @@
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#include <epicsUnitTest.h>
#include <testMain.h>
#include <pv/nt.h>
using namespace epics::nt;
using namespace epics::pvData;
using std::tr1::dynamic_pointer_cast;
static FieldCreatePtr fieldCreate = getFieldCreate();
void test_builder()
{
testDiag("test_builder");
NTContinuumBuilderPtr builder = NTContinuum::createBuilder();
testOk(builder.get() != 0, "Got builder");
StructureConstPtr structure = builder->
addDescriptor()->
addAlarm()->
addTimeStamp()->
add("extra1",fieldCreate->createScalar(pvString)) ->
add("extra2",fieldCreate->createScalarArray(pvString)) ->
createStructure();
testOk1(structure.get() != 0);
if (!structure)
return;
testOk1(NTContinuum::is_a(structure));
testOk1(structure->getID() == NTContinuum::URI);
testOk1(structure->getNumberFields() == 8);
testOk1(structure->getField("base").get() != 0);
testOk1(structure->getField("value").get() != 0);
testOk1(structure->getField("units").get() != 0);
testOk1(structure->getField("descriptor").get() != 0);
testOk1(structure->getField("alarm").get() != 0);
testOk1(structure->getField("timeStamp").get() != 0);
testOk(dynamic_pointer_cast<const ScalarArray>(structure->getField("base")).get() != 0 &&
dynamic_pointer_cast<const ScalarArray>(structure->getField("base"))->getElementType() == pvDouble, "base array element type");
testOk(dynamic_pointer_cast<const ScalarArray>(structure->getField("value")).get() != 0 &&
dynamic_pointer_cast<const ScalarArray>(structure->getField("value"))->getElementType() == pvDouble, "value array element type");
testOk(dynamic_pointer_cast<const ScalarArray>(structure->getField("units")).get() != 0 &&
dynamic_pointer_cast<const ScalarArray>(structure->getField("units"))->getElementType() == pvString, "units array element type");
std::cout << *structure << std::endl;
}
void test_ntcontinuum()
{
testDiag("test_ntcontinuum");
NTContinuumBuilderPtr builder = NTContinuum::createBuilder();
testOk(builder.get() != 0, "Got builder");
NTContinuumPtr ntContinuum = builder->
addDescriptor()->
addAlarm()->
addTimeStamp()->
add("extra1",fieldCreate->createScalar(pvString)) ->
add("extra2",fieldCreate->createScalarArray(pvString)) ->
create();
testOk1(ntContinuum.get() != 0);
testOk1(NTContinuum::is_a(ntContinuum->getPVStructure()));
testOk1(NTContinuum::isCompatible(ntContinuum->getPVStructure()));
testOk1(ntContinuum->getPVStructure().get() != 0);
testOk1(ntContinuum->getDescriptor().get() != 0);
testOk1(ntContinuum->getAlarm().get() != 0);
testOk1(ntContinuum->getTimeStamp().get() != 0);
testOk1(ntContinuum->getBase().get() != 0);
testOk1(ntContinuum->getValue().get() != 0);
//
// example how to set base
//
PVDoubleArray::svector newBase;
newBase.push_back(1.0);
newBase.push_back(2.0);
PVDoubleArrayPtr pvBaseField = ntContinuum->getBase();
pvBaseField->replace(freeze(newBase));
//
// example how to get bases
//
PVDoubleArray::const_svector base(pvBaseField->view());
testOk1(base.size() == 2);
testOk1(base[0] == 1.0);
testOk1(base[1] == 2.0);
//
// example how to set values
//
PVDoubleArray::svector newValue;
newValue.push_back(1.0);
newValue.push_back(2.0);
newValue.push_back(10.0);
newValue.push_back(20.0);
newValue.push_back(100.0);
newValue.push_back(200.0);
PVDoubleArrayPtr pvValueField = ntContinuum->getValue();
pvValueField->replace(freeze(newValue));
//
// example how to get values
//
PVDoubleArray::const_svector value(pvValueField->view());
testOk1(value.size() == 6);
testOk1(value[0] == 1.0);
testOk1(value[1] == 2.0);
testOk1(value[2] == 10.0);
testOk1(value[3] == 20.0);
testOk1(value[4] == 100.0);
testOk1(value[5] == 200.0);
//
// example how to set units
//
PVStringArray::svector newUnits;
newUnits.push_back("s");
newUnits.push_back("ms");
newUnits.push_back("us");
newUnits.push_back("s");
PVStringArrayPtr pvUnitsField = ntContinuum->getUnits();
pvUnitsField->replace(freeze(newUnits));
//
// example how to get units
//
PVStringArray::const_svector units(pvUnitsField->view());
testOk1(units.size() == 4);
testOk1(units[0] == "s");
testOk1(units[1] == "ms");
testOk1(units[2] == "us");
testOk1(units[3] == "s");
//
// test isValid
//
testOk1(ntContinuum->isValid());
//
// timeStamp ops
//
PVTimeStamp pvTimeStamp;
if (ntContinuum->attachTimeStamp(pvTimeStamp))
{
testPass("timeStamp attach");
// example how to set current time
TimeStamp ts;
ts.getCurrent();
pvTimeStamp.set(ts);
// example how to get EPICS time
TimeStamp ts2;
pvTimeStamp.get(ts2);
testOk1(ts2.getEpicsSecondsPastEpoch() != 0);
}
else
testFail("timeStamp attach fail");
//
// alarm ops
//
PVAlarm pvAlarm;
if (ntContinuum->attachAlarm(pvAlarm))
{
testPass("alarm attach");
// example how to set an alarm
Alarm alarm;
alarm.setStatus(deviceStatus);
alarm.setSeverity(minorAlarm);
alarm.setMessage("simulation alarm");
pvAlarm.set(alarm);
}
else
testFail("alarm attach fail");
//
// set descriptor
//
ntContinuum->getDescriptor()->put("This is a test NTContinuum");
// dump NTContinuum
std::cout << *ntContinuum->getPVStructure() << std::endl;
}
void test_wrap()
{
testDiag("test_wrap");
NTContinuumPtr nullPtr = NTContinuum::wrap(PVStructurePtr());
testOk(nullPtr.get() == 0, "nullptr wrap");
nullPtr = NTContinuum::wrap(
getPVDataCreate()->createPVStructure(
NTField::get()->createTimeStamp()
)
);
testOk(nullPtr.get() == 0, "wrong type wrap");
NTContinuumBuilderPtr builder = NTContinuum::createBuilder();
testOk(builder.get() != 0, "Got builder");
PVStructurePtr pvStructure = builder->
createPVStructure();
testOk1(pvStructure.get() != 0);
if (!pvStructure)
return;
testOk1(NTContinuum::isCompatible(pvStructure)==true);
NTContinuumPtr ptr = NTContinuum::wrap(pvStructure);
testOk(ptr.get() != 0, "wrap OK");
ptr = NTContinuum::wrapUnsafe(pvStructure);
testOk(ptr.get() != 0, "wrapUnsafe OK");
}
void test_extra()
{
testDiag("test_extra");
NTContinuumBuilderPtr builder = NTContinuum::createBuilder();
testOk(builder.get() != 0, "Got builder");
StructureConstPtr structure = builder->
addTimeStamp()->
add("function", getFieldCreate()->createScalar(pvString))->
createStructure();
testOk1(structure.get() != 0);
if (!structure)
return;
testOk1(NTContinuum::is_a(structure));
testOk1(structure->getID() == NTContinuum::URI);
testOk1(structure->getNumberFields() == 5);
testOk1(structure->getField("base").get() != 0);
testOk1(structure->getField("value").get() != 0);
testOk1(structure->getField("units").get() != 0);
testOk1(structure->getField("timeStamp").get() != 0);
testOk1(structure->getField("function").get() != 0);
testOk(dynamic_pointer_cast<const Scalar>(structure->getField("function")).get() != 0 &&
dynamic_pointer_cast<const Scalar>(structure->getField("function"))->getScalarType() == pvString, "function type");
std::cout << *structure << std::endl;
}
MAIN(testNTContinuum) {
testPlan(61);
test_builder();
test_ntcontinuum();
test_wrap();
test_extra();
return testDone();
}

189
test/ntenumTest.cpp Normal file
View File

@@ -0,0 +1,189 @@
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#include <epicsUnitTest.h>
#include <testMain.h>
#include <pv/nt.h>
using namespace epics::nt;
using namespace epics::pvData;
using std::tr1::dynamic_pointer_cast;
static FieldCreatePtr fieldCreate = getFieldCreate();
static StandardFieldPtr standardField = getStandardField();
static NTFieldPtr ntField = NTField::get();
void test_builder()
{
testDiag("test_builder");
NTEnumBuilderPtr builder = NTEnum::createBuilder();
testOk(builder.get() != 0, "Got builder");
StructureConstPtr structure = builder->
addDescriptor()->
addAlarm()->
addTimeStamp()->
add("valueAlarm",standardField->doubleAlarm()) ->
add("extra",fieldCreate->createScalarArray(pvString)) ->
createStructure();
testOk1(structure.get() != 0);
if (!structure)
return;
testOk1(NTEnum::is_a(structure));
testOk1(structure->getID() == NTEnum::URI);
testOk1(structure->getNumberFields() == 6);
testOk1(structure->getField("value").get() != 0);
testOk1(structure->getField("descriptor").get() != 0);
testOk1(structure->getField("alarm").get() != 0);
testOk1(structure->getField("timeStamp").get() != 0);
FieldConstPtr valueField = structure->getField("value");
testOk(valueField.get() != 0 &&
ntField->isEnumerated(valueField), "value is enum");
std::cout << *structure << std::endl;
}
void test_ntenum()
{
testDiag("test_ntenum");
NTEnumBuilderPtr builder = NTEnum::createBuilder();
testOk(builder.get() != 0, "Got builder");
NTEnumPtr ntEnum = builder->
addDescriptor()->
addAlarm()->
addTimeStamp()->
add("valueAlarm",standardField->intAlarm()) ->
create();
testOk1(ntEnum.get() != 0);
testOk1(NTEnum::is_a(ntEnum->getPVStructure()));
testOk1(NTEnum::isCompatible(ntEnum->getPVStructure()));
testOk1(ntEnum->getPVStructure().get() != 0);
testOk1(ntEnum->getValue().get() != 0);
testOk1(ntEnum->getDescriptor().get() != 0);
testOk1(ntEnum->getAlarm().get() != 0);
testOk1(ntEnum->getTimeStamp().get() != 0);
//
// example how to set a value
//
PVStructurePtr pvValue = ntEnum->getValue();
//PVStringArray pvChoices = pvValue->getSubField<PVStringArray>("choices");
PVStringArray::svector choices(2);
choices[0] = "Off";
choices[1] = "On";
pvValue->getSubField<PVStringArray>("choices")->replace(freeze(choices));
pvValue->getSubField<PVInt>("index")->put(1);
//
// example how to get a value
//
int32 value = ntEnum->getValue()->getSubField<PVInt>("index")->get();
testOk1(value == 1);
PVStringArrayPtr pvChoices = ntEnum->getValue()->getSubField<PVStringArray>("choices");
std::string choice0 = pvChoices->view()[0];
std::string choice1 = pvChoices->view()[1];
testOk1(choice0 == "Off");
testOk1(choice1 == "On");
//
// timeStamp ops
//
PVTimeStamp pvTimeStamp;
if (ntEnum->attachTimeStamp(pvTimeStamp))
{
testPass("timeStamp attach");
// example how to set current time
TimeStamp ts;
ts.getCurrent();
pvTimeStamp.set(ts);
// example how to get EPICS time
TimeStamp ts2;
pvTimeStamp.get(ts2);
testOk1(ts2.getEpicsSecondsPastEpoch() != 0);
}
else
testFail("timeStamp attach fail");
//
// alarm ops
//
PVAlarm pvAlarm;
if (ntEnum->attachAlarm(pvAlarm))
{
testPass("alarm attach");
// example how to set an alarm
Alarm alarm;
alarm.setStatus(deviceStatus);
alarm.setSeverity(minorAlarm);
alarm.setMessage("simulation alarm");
pvAlarm.set(alarm);
}
else
testFail("alarm attach fail");
//
// set descriptor
//
ntEnum->getDescriptor()->put("This is a test NTEnum");
// dump ntEnum
std::cout << *ntEnum->getPVStructure() << std::endl;
}
void test_wrap()
{
testDiag("test_wrap");
NTEnumPtr nullPtr = NTEnum::wrap(PVStructurePtr());
testOk(nullPtr.get() == 0, "nullptr wrap");
nullPtr = NTEnum::wrap(
getPVDataCreate()->createPVStructure(
NTField::get()->createTimeStamp()
)
);
testOk(nullPtr.get() == 0, "wrong type wrap");
NTEnumBuilderPtr builder = NTEnum::createBuilder();
testOk(builder.get() != 0, "Got builder");
PVStructurePtr pvStructure = builder->
createPVStructure();
testOk1(pvStructure.get() != 0);
if (!pvStructure)
return;
testOk1(NTEnum::isCompatible(pvStructure)==true);
NTEnumPtr ptr = NTEnum::wrap(pvStructure);
testOk(ptr.get() != 0, "wrap OK");
ptr = NTEnum::wrapUnsafe(pvStructure);
testOk(ptr.get() != 0, "wrapUnsafe OK");
}
MAIN(testNTEnum) {
testPlan(32);
test_builder();
test_ntenum();
test_wrap();
return testDone();
}

View File

@@ -1,7 +1,6 @@
/**
* Copyright - See the COPYRIGHT that is included with this distribution.
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
/*
* ntfieldTest.cpp

263
test/nthistogramTest.cpp Normal file
View File

@@ -0,0 +1,263 @@
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#include <epicsUnitTest.h>
#include <testMain.h>
#include <pv/nt.h>
using namespace epics::nt;
using namespace epics::pvData;
using std::tr1::dynamic_pointer_cast;
static FieldCreatePtr fieldCreate = getFieldCreate();
void test_builder()
{
testDiag("test_builder");
NTHistogramBuilderPtr builder = NTHistogram::createBuilder();
testOk(builder.get() != 0, "Got builder");
StructureConstPtr structure = builder->
value(pvLong)->
addDescriptor()->
addAlarm()->
addTimeStamp()->
add("extra1",fieldCreate->createScalar(pvString)) ->
add("extra2",fieldCreate->createScalarArray(pvString)) ->
createStructure();
testOk1(structure.get() != 0);
if (!structure)
return;
testOk1(NTHistogram::is_a(structure));
testOk1(structure->getID() == NTHistogram::URI);
testOk1(structure->getNumberFields() == 7);
testOk1(structure->getField("ranges").get() != 0);
testOk1(structure->getField("value").get() != 0);
testOk1(structure->getField("descriptor").get() != 0);
testOk1(structure->getField("alarm").get() != 0);
testOk1(structure->getField("timeStamp").get() != 0);
testOk(dynamic_pointer_cast<const ScalarArray>(structure->getField("ranges")).get() != 0 &&
dynamic_pointer_cast<const ScalarArray>(structure->getField("ranges"))->getElementType() == pvDouble, "ranges array element type");
testOk(dynamic_pointer_cast<const ScalarArray>(structure->getField("value")).get() != 0 &&
dynamic_pointer_cast<const ScalarArray>(structure->getField("value"))->getElementType() == pvLong, "value array element type");
std::cout << *structure << std::endl;
// no value set
try
{
structure = builder->
addDescriptor()->
addAlarm()->
addTimeStamp()->
add("extra1",fieldCreate->createScalar(pvString)) ->
add("extra2",fieldCreate->createScalarArray(pvString)) ->
createStructure();
testFail("no value type set");
} catch (std::runtime_error &) {
testPass("no value type set");
}
}
void test_nthistogram()
{
testDiag("test_nthistogram");
NTHistogramBuilderPtr builder = NTHistogram::createBuilder();
testOk(builder.get() != 0, "Got builder");
NTHistogramPtr ntHistogram = builder->
value(pvInt)->
addDescriptor()->
addAlarm()->
addTimeStamp()->
add("extra1",fieldCreate->createScalar(pvString)) ->
add("extra2",fieldCreate->createScalarArray(pvString)) ->
create();
testOk1(ntHistogram.get() != 0);
testOk1(NTHistogram::is_a(ntHistogram->getPVStructure()));
testOk1(NTHistogram::isCompatible(ntHistogram->getPVStructure()));
testOk1(ntHistogram->getPVStructure().get() != 0);
testOk1(ntHistogram->getDescriptor().get() != 0);
testOk1(ntHistogram->getAlarm().get() != 0);
testOk1(ntHistogram->getTimeStamp().get() != 0);
testOk1(ntHistogram->getRanges().get() != 0);
testOk1(ntHistogram->getValue().get() != 0);
testOk1(ntHistogram->getValue<PVIntArray>().get() != 0);
//
// example how to set ranges
//
PVDoubleArray::svector newRanges;
newRanges.push_back(-100.0);
newRanges.push_back(0.0);
newRanges.push_back(100.0);
PVDoubleArrayPtr pvRangesField = ntHistogram->getRanges();
pvRangesField->replace(freeze(newRanges));
//
// example how to get ranges
//
PVDoubleArray::const_svector ranges(pvRangesField->view());
testOk1(ranges.size() == 3);
testOk1(ranges[0] == -100.0);
testOk1(ranges[1] == 0.0);
testOk1(ranges[2] == 100.0);
//
// example how to set value
//
PVIntArray::svector newValue;
newValue.push_back(1);
newValue.push_back(2);
PVIntArrayPtr pvValueField = ntHistogram->getValue<PVIntArray>();
pvValueField->replace(freeze(newValue));
//
// example how to get values for each bin
//
PVIntArray::const_svector value(pvValueField->view());
testOk1(value.size() == 2);
testOk1(value[0] == 1);
testOk1(value[1] == 2);
//
// test isValid
//
testOk1(ntHistogram->isValid());
//
// timeStamp ops
//
PVTimeStamp pvTimeStamp;
if (ntHistogram->attachTimeStamp(pvTimeStamp))
{
testPass("timeStamp attach");
// example how to set current time
TimeStamp ts;
ts.getCurrent();
pvTimeStamp.set(ts);
// example how to get EPICS time
TimeStamp ts2;
pvTimeStamp.get(ts2);
testOk1(ts2.getEpicsSecondsPastEpoch() != 0);
}
else
testFail("timeStamp attach fail");
//
// alarm ops
//
PVAlarm pvAlarm;
if (ntHistogram->attachAlarm(pvAlarm))
{
testPass("alarm attach");
// example how to set an alarm
Alarm alarm;
alarm.setStatus(deviceStatus);
alarm.setSeverity(minorAlarm);
alarm.setMessage("simulation alarm");
pvAlarm.set(alarm);
}
else
testFail("alarm attach fail");
//
// set descriptor
//
ntHistogram->getDescriptor()->put("This is a test NTHistogram");
// dump NTHistogram
std::cout << *ntHistogram->getPVStructure() << std::endl;
}
void test_wrap()
{
testDiag("test_wrap");
NTHistogramPtr nullPtr = NTHistogram::wrap(PVStructurePtr());
testOk(nullPtr.get() == 0, "nullptr wrap");
nullPtr = NTHistogram::wrap(
getPVDataCreate()->createPVStructure(
NTField::get()->createTimeStamp()
)
);
testOk(nullPtr.get() == 0, "wrong type wrap");
NTHistogramBuilderPtr builder = NTHistogram::createBuilder();
testOk(builder.get() != 0, "Got builder");
PVStructurePtr pvStructure = builder->
value(pvInt)->
createPVStructure();
testOk1(pvStructure.get() != 0);
if (!pvStructure)
return;
testOk1(NTHistogram::isCompatible(pvStructure)==true);
NTHistogramPtr ptr = NTHistogram::wrap(pvStructure);
testOk(ptr.get() != 0, "wrap OK");
ptr = NTHistogram::wrapUnsafe(pvStructure);
testOk(ptr.get() != 0, "wrapUnsafe OK");
}
void test_extra()
{
testDiag("test_extra");
NTHistogramBuilderPtr builder = NTHistogram::createBuilder();
testOk(builder.get() != 0, "Got builder");
StructureConstPtr structure = builder->
value(pvInt)->
addTimeStamp()->
add("function", getFieldCreate()->createScalar(pvString))->
createStructure();
testOk1(structure.get() != 0);
if (!structure)
return;
testOk1(NTHistogram::is_a(structure));
testOk1(structure->getID() == NTHistogram::URI);
testOk1(structure->getNumberFields() == 4);
testOk1(structure->getField("ranges").get() != 0);
testOk1(structure->getField("value").get() != 0);
testOk1(structure->getField("timeStamp").get() != 0);
testOk1(structure->getField("function").get() != 0);
testOk(dynamic_pointer_cast<const Scalar>(structure->getField("function")).get() != 0 &&
dynamic_pointer_cast<const Scalar>(structure->getField("function"))->getScalarType() == pvString, "function type");
std::cout << *structure << std::endl;
}
MAIN(testNTHistogram) {
testPlan(52);
test_builder();
test_nthistogram();
test_wrap();
test_extra();
return testDone();
}

212
test/ntmatrixTest.cpp Normal file
View File

@@ -0,0 +1,212 @@
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#include <epicsUnitTest.h>
#include <testMain.h>
#include <pv/nt.h>
using namespace epics::nt;
using namespace epics::pvData;
using std::tr1::dynamic_pointer_cast;
static FieldCreatePtr fieldCreate = getFieldCreate();
void test_builder()
{
testDiag("test_builder");
NTMatrixBuilderPtr builder = NTMatrix::createBuilder();
testOk(builder.get() != 0, "Got builder");
StructureConstPtr structure = builder->
//arrayValue(pvDouble)->
addDim()->
addDescriptor()->
addAlarm()->
addTimeStamp()->
addDisplay()->
add("extra1",fieldCreate->createScalar(pvString)) ->
add("extra2",fieldCreate->createScalarArray(pvString)) ->
createStructure();
testOk1(structure.get() != 0);
if (!structure)
return;
testOk1(NTMatrix::is_a(structure));
testOk1(structure->getID() == NTMatrix::URI);
testOk1(structure->getNumberFields() == 8);
testOk1(structure->getField("value").get() != 0);
testOk1(structure->getField("dim").get() != 0);
testOk1(structure->getField("descriptor").get() != 0);
testOk1(structure->getField("alarm").get() != 0);
testOk1(structure->getField("timeStamp").get() != 0);
testOk1(structure->getField("display").get() != 0);
testOk(dynamic_pointer_cast<const ScalarArray>(structure->getField("value")).get() != 0 &&
dynamic_pointer_cast<const ScalarArray>(structure->getField("value"))->getElementType() == pvDouble, "value type");
std::cout << *structure << std::endl;
}
void test_ntmatrix()
{
testDiag("test_ntmatrix");
NTMatrixBuilderPtr builder = NTMatrix::createBuilder();
testOk(builder.get() != 0, "Got builder");
NTMatrixPtr ntMatrix = builder->
//arrayValue(pvInt)->
addDim()->
addDescriptor()->
addAlarm()->
addTimeStamp()->
addDisplay()->
create();
testOk1(ntMatrix.get() != 0);
testOk1(NTMatrix::is_a(ntMatrix->getPVStructure()));
testOk1(NTMatrix::isCompatible(ntMatrix->getPVStructure()));
testOk1(ntMatrix->getPVStructure().get() != 0);
testOk1(ntMatrix->getValue().get() != 0);
testOk1(ntMatrix->getDim().get() != 0);
testOk1(ntMatrix->getDescriptor().get() != 0);
testOk1(ntMatrix->getAlarm().get() != 0);
testOk1(ntMatrix->getTimeStamp().get() != 0);
testOk1(ntMatrix->getDisplay().get() != 0);
//
// example how to set values
//
PVDoubleArray::svector newValues;
newValues.push_back(1.0);
newValues.push_back(2.0);
newValues.push_back(8.0);
PVDoubleArrayPtr pvValueField = ntMatrix->getValue();
pvValueField->replace(freeze(newValues));
//
// example how to get values
//
PVDoubleArray::const_svector values(pvValueField->view());
testOk1(values.size() == 3);
testOk1(values[0] == 1.0);
testOk1(values[1] == 2.0);
testOk1(values[2] == 8.0);
//
// timeStamp ops
//
PVTimeStamp pvTimeStamp;
if (ntMatrix->attachTimeStamp(pvTimeStamp))
{
testPass("timeStamp attach");
// example how to set current time
TimeStamp ts;
ts.getCurrent();
pvTimeStamp.set(ts);
// example how to get EPICS time
TimeStamp ts2;
pvTimeStamp.get(ts2);
testOk1(ts2.getEpicsSecondsPastEpoch() != 0);
}
else
testFail("timeStamp attach fail");
//
// alarm ops
//
PVAlarm pvAlarm;
if (ntMatrix->attachAlarm(pvAlarm))
{
testPass("alarm attach");
// example how to set an alarm
Alarm alarm;
alarm.setStatus(deviceStatus);
alarm.setSeverity(minorAlarm);
alarm.setMessage("simulation alarm");
pvAlarm.set(alarm);
}
else
testFail("alarm attach fail");
//
// display ops
//
PVDisplay pvDisplay;
if (ntMatrix->attachDisplay(pvDisplay))
{
testPass("display attach");
// example how to set an display
Display display;
display.setLow(-15);
display.setHigh(15);
display.setDescription("This is a test scalar array");
display.setFormat("%d");
display.setUnits("A");
pvDisplay.set(display);
}
else
testFail("display attach fail");
//
// set descriptor
//
ntMatrix->getDescriptor()->put("This is a test NTMatrix");
// dump ntMatrix
std::cout << *ntMatrix->getPVStructure() << std::endl;
}
void test_wrap()
{
testDiag("test_wrap");
NTMatrixPtr nullPtr = NTMatrix::wrap(PVStructurePtr());
testOk(nullPtr.get() == 0, "nullptr wrap");
nullPtr = NTMatrix::wrap(
getPVDataCreate()->createPVStructure(
NTField::get()->createTimeStamp()
)
);
testOk(nullPtr.get() == 0, "wrong type wrap");
NTMatrixBuilderPtr builder = NTMatrix::createBuilder();
testOk(builder.get() != 0, "Got builder");
PVStructurePtr pvStructure = builder->
createPVStructure();
testOk1(pvStructure.get() != 0);
if (!pvStructure)
return;
testOk1(NTMatrix::isCompatible(pvStructure)==true);
NTMatrixPtr ptr = NTMatrix::wrap(pvStructure);
testOk(ptr.get() != 0, "wrap OK");
ptr = NTMatrix::wrapUnsafe(pvStructure);
testOk(ptr.get() != 0, "wrapUnsafe OK");
}
MAIN(testNTMatrix) {
testPlan(38);
test_builder();
test_ntmatrix();
test_wrap();
return testDone();
}

View File

@@ -1,7 +1,6 @@
/**
* Copyright - See the COPYRIGHT that is included with this distribution.
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
/*
* ntmutiChannelTest.cpp
@@ -54,6 +53,9 @@ static void test()
create();
testOk1(multiChannel.get() != 0);
testOk1(NTMultiChannel::is_a(multiChannel->getPVStructure()));
testOk1(NTMultiChannel::isCompatible(multiChannel->getPVStructure()));
PVStructurePtr pvStructure = multiChannel->getPVStructure();
testOk1(pvStructure.get()!=NULL);
testOk1(NTMultiChannel::is_a(pvStructure->getStructure()));
@@ -77,6 +79,7 @@ static void test()
addAlarm()->
addTimeStamp()->
addSeverity() ->
addIsConnected() ->
create();
testOk1(multiChannel.get() != 0);
pvStructure = multiChannel->getPVStructure();
@@ -118,6 +121,7 @@ static void test()
addSecondsPastEpoch() ->
addNanoseconds() ->
addUserTag() ->
addIsConnected() ->
create();
testOk1(multiChannel.get() != 0);
pvStructure = multiChannel->getPVStructure();
@@ -184,7 +188,7 @@ void test_wrap()
MAIN(testCreateRequest)
{
testPlan(25);
testPlan(27);
test();
test_wrap();
return testDone();

View File

@@ -1,7 +1,6 @@
/**
* Copyright - See the COPYRIGHT that is included with this distribution.
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#include <epicsUnitTest.h>
@@ -81,6 +80,9 @@ void test_ntnameValue()
create();
testOk1(ntNameValue.get() != 0);
testOk1(NTNameValue::is_a(ntNameValue->getPVStructure()));
testOk1(NTNameValue::isCompatible(ntNameValue->getPVStructure()));
testOk1(ntNameValue->getPVStructure().get() != 0);
testOk1(ntNameValue->getDescriptor().get() != 0);
testOk1(ntNameValue->getAlarm().get() != 0);
@@ -245,7 +247,7 @@ void test_extra()
MAIN(testNTNameValue) {
testPlan(48);
testPlan(50);
test_builder();
test_ntnameValue();
test_wrap();

View File

@@ -0,0 +1,179 @@
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#include <epicsUnitTest.h>
#include <testMain.h>
#include <pv/nt.h>
using namespace epics::nt;
using namespace epics::pvData;
using std::tr1::dynamic_pointer_cast;
static FieldCreatePtr fieldCreate = getFieldCreate();
static StandardFieldPtr standardField = getStandardField();
static NTFieldPtr ntField = NTField::get();
void test_builder()
{
testDiag("test_builder");
NTNDArrayAttributeBuilderPtr builder = NTNDArrayAttribute::createBuilder();
testOk(builder.get() != 0, "Got builder");
StructureConstPtr structure = builder->
addTags()->
addAlarm()->
addTimeStamp()->
add("extra",fieldCreate->createScalar(pvString)) ->
createStructure();
testOk1(structure.get() != 0);
if (!structure)
return;
testOk1(NTNDArrayAttribute::is_a(structure));
testOk1(structure->getID() == NTNDArrayAttribute::URI);
testOk1(structure->getNumberFields() == 9);
testOk1(structure->getField("name").get() != 0);
testOk1(structure->getField("value").get() != 0);
testOk1(structure->getField("tags").get() != 0);
testOk1(structure->getField("descriptor").get() != 0);
testOk1(structure->getField("alarm").get() != 0);
testOk1(structure->getField("timeStamp").get() != 0);
testOk1(structure->getField("sourceType").get() != 0);
testOk1(structure->getField("source").get() != 0);
ScalarConstPtr nameField = structure->getField<Scalar>("name");
testOk(nameField.get() != 0 && nameField->getScalarType() == pvString,
"name is string");
UnionConstPtr valueField = structure->getField<Union>("value");
testOk(valueField.get() != 0, "value is enum");
ScalarArrayConstPtr tagsField = structure->getField<ScalarArray>("tags");
testOk(tagsField.get() != 0 && tagsField->getElementType() == pvString,
"tags is string[]");
std::cout << *structure << std::endl;
}
void test_ntndarrayAttribute()
{
testDiag("test_ntndarrayAttribute");
NTNDArrayAttributeBuilderPtr builder = NTNDArrayAttribute::createBuilder();
testOk(builder.get() != 0, "Got builder");
NTNDArrayAttributePtr ntNDArrayAttribute = builder->
addTags()->
addAlarm()->
addTimeStamp()->
create();
testOk1(ntNDArrayAttribute.get() != 0);
testOk1(NTNDArrayAttribute::is_a(ntNDArrayAttribute->getPVStructure()));
testOk1(NTNDArrayAttribute::isCompatible(ntNDArrayAttribute->getPVStructure()));
testOk1(ntNDArrayAttribute->getPVStructure().get() != 0);
testOk1(ntNDArrayAttribute->getName().get() != 0);
testOk1(ntNDArrayAttribute->getValue().get() != 0);
testOk1(ntNDArrayAttribute->getTags().get() != 0);
testOk1(ntNDArrayAttribute->getDescriptor().get() != 0);
testOk1(ntNDArrayAttribute->getAlarm().get() != 0);
testOk1(ntNDArrayAttribute->getTimeStamp().get() != 0);
testOk1(ntNDArrayAttribute->getSourceType().get() != 0);
testOk1(ntNDArrayAttribute->getSource().get() != 0);
//
// timeStamp ops
//
PVTimeStamp pvTimeStamp;
if (ntNDArrayAttribute->attachTimeStamp(pvTimeStamp))
{
testPass("timeStamp attach");
// example how to set current time
TimeStamp ts;
ts.getCurrent();
pvTimeStamp.set(ts);
// example how to get EPICS time
TimeStamp ts2;
pvTimeStamp.get(ts2);
testOk1(ts2.getEpicsSecondsPastEpoch() != 0);
}
else
testFail("timeStamp attach fail");
//
// alarm ops
//
PVAlarm pvAlarm;
if (ntNDArrayAttribute->attachAlarm(pvAlarm))
{
testPass("alarm attach");
// example how to set an alarm
Alarm alarm;
alarm.setStatus(deviceStatus);
alarm.setSeverity(minorAlarm);
alarm.setMessage("simulation alarm");
pvAlarm.set(alarm);
}
else
testFail("alarm attach fail");
//
// set descriptor
//
ntNDArrayAttribute->getDescriptor()->put("This is a test NTNDArrayAttribute");
// dump ntNDArrayAttribute
std::cout << *ntNDArrayAttribute->getPVStructure() << std::endl;
}
void test_wrap()
{
testDiag("test_wrap");
NTNDArrayAttributePtr nullPtr = NTNDArrayAttribute::wrap(PVStructurePtr());
testOk(nullPtr.get() == 0, "nullptr wrap");
nullPtr = NTNDArrayAttribute::wrap(
getPVDataCreate()->createPVStructure(
NTField::get()->createTimeStamp()
)
);
testOk(nullPtr.get() == 0, "wrong type wrap");
NTNDArrayAttributeBuilderPtr builder = NTNDArrayAttribute::createBuilder();
testOk(builder.get() != 0, "Got builder");
PVStructurePtr pvStructure = builder->
createPVStructure();
testOk1(pvStructure.get() != 0);
if (!pvStructure)
return;
testOk1(NTNDArrayAttribute::isCompatible(pvStructure)==true);
NTNDArrayAttributePtr ptr = NTNDArrayAttribute::wrap(pvStructure);
testOk(ptr.get() != 0, "wrap OK");
ptr = NTNDArrayAttribute::wrapUnsafe(pvStructure);
testOk(ptr.get() != 0, "wrapUnsafe OK");
}
MAIN(testNTNDArrayAttribute) {
testPlan(39);
test_builder();
test_ntndarrayAttribute();
test_wrap();
return testDone();
}

View File

@@ -1,7 +1,6 @@
/**
* Copyright - See the COPYRIGHT that is included with this distribution.
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#include <epicsUnitTest.h>
@@ -75,7 +74,7 @@ void test_all()
add("extra1",fieldCreate->createScalar(pvString)) ->
add("extra2",fieldCreate->createScalarArray(pvString)) ->
createPVStructure();
std::cout << *pvStructure << std::endl;
testOk1(NTNDArray::is_a(pvStructure)==true);
testOk1(NTNDArray::isCompatible(pvStructure)==true);
}
@@ -113,7 +112,7 @@ void test_wrap()
}
MAIN(testNTNDArray) {
testPlan(59);
testPlan(60);
test_builder(true);
test_builder(false);
test_builder(false); // called twice to test caching

View File

@@ -1,7 +1,6 @@
/**
* Copyright - See the COPYRIGHT that is included with this distribution.
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#include <epicsUnitTest.h>
@@ -23,7 +22,7 @@ void test_builder()
testOk(builder.get() != 0, "Got builder");
StructureConstPtr structure = builder->
arrayValue(pvDouble)->
value(pvDouble)->
addDescriptor()->
addAlarm()->
addTimeStamp()->
@@ -75,7 +74,7 @@ void test_ntscalarArray()
testOk(builder.get() != 0, "Got builder");
NTScalarArrayPtr ntScalarArray = builder->
arrayValue(pvInt)->
value(pvInt)->
addDescriptor()->
addAlarm()->
addTimeStamp()->
@@ -84,6 +83,9 @@ void test_ntscalarArray()
create();
testOk1(ntScalarArray.get() != 0);
testOk1(NTScalarArray::is_a(ntScalarArray->getPVStructure()));
testOk1(NTScalarArray::isCompatible(ntScalarArray->getPVStructure()));
testOk1(ntScalarArray->getPVStructure().get() != 0);
testOk1(ntScalarArray->getValue().get() != 0);
testOk1(ntScalarArray->getDescriptor().get() != 0);
@@ -220,7 +222,7 @@ void test_wrap()
testOk(builder.get() != 0, "Got builder");
PVStructurePtr pvStructure = builder->
arrayValue(pvDouble)->
value(pvDouble)->
createPVStructure();
testOk1(pvStructure.get() != 0);
if (!pvStructure)
@@ -235,7 +237,7 @@ void test_wrap()
}
MAIN(testNTScalarArray) {
testPlan(38);
testPlan(40);
test_builder();
test_ntscalarArray();
test_wrap();

View File

@@ -0,0 +1,183 @@
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
/*
* ntscalarMultiChannelTest.cpp
*
* Created on: 2015.08
* Authors: Marty Kraimer, Dave Hickin
*/
#include <cstddef>
#include <cstdlib>
#include <cstddef>
#include <string>
#include <list>
#include <iostream>
#include <epicsUnitTest.h>
#include <testMain.h>
#include <pv/nt.h>
#include <pv/sharedVector.h>
#include <pv/ntscalarMultiChannel.h>
using namespace epics::pvData;
using namespace epics::nt;
using std::string;
using std::cout;
using std::endl;
using std::vector;
static bool debug = false;
static FieldCreatePtr fieldCreate = getFieldCreate();
static PVDataCreatePtr pvDataCreate = getPVDataCreate();
static NTFieldPtr ntField = NTField::get();
static PVNTFieldPtr pvntField = PVNTField::get();
static void test()
{
NTScalarMultiChannelBuilderPtr builder = NTScalarMultiChannel::createBuilder();
testOk(builder.get() != 0, "Got builder");
NTScalarMultiChannelPtr multiChannel = builder->
addDescriptor()->
addAlarm()->
addTimeStamp()->
addSeverity() ->
add("extra1",fieldCreate->createScalar(pvString)) ->
add("extra2",fieldCreate->createScalarArray(pvString)) ->
create();
testOk1(multiChannel.get() != 0);
testOk1(NTScalarMultiChannel::is_a(multiChannel->getPVStructure()));
testOk1(NTScalarMultiChannel::isCompatible(multiChannel->getPVStructure()));
PVStructurePtr pvStructure = multiChannel->getPVStructure();
testOk1(pvStructure.get()!=NULL);
testOk1(NTScalarMultiChannel::is_a(pvStructure->getStructure()));
size_t nchan = 3;
shared_vector<string> names(nchan);
names[0] = "channel 0";
names[1] = "channel 1";
names[2] = "channel 2";
shared_vector<const string> channelNames(freeze(names));
PVStringArrayPtr pvChannelName = multiChannel->getChannelName();
pvChannelName->replace(channelNames);
if(debug) {cout << *pvStructure << endl;}
multiChannel = builder->
value(pvDouble) ->
addDescriptor()->
addAlarm()->
addTimeStamp()->
addSeverity() ->
addIsConnected() ->
create();
testOk1(multiChannel.get() != 0);
pvStructure = multiChannel->getPVStructure();
if(debug) {cout << *pvStructure << endl;}
pvChannelName = multiChannel->getChannelName();
pvChannelName->replace(channelNames);
PVDoubleArrayPtr pvValue = multiChannel->getValue<PVDoubleArray>();
PVDoubleArray::svector doubles(nchan);
doubles.resize(nchan);
doubles[0] = 3.14159;
doubles[1] = 2.71828;
doubles[2] = 137.036;
pvValue->replace(freeze(doubles));
shared_vector<int32> severities(nchan);
severities[0] = 0;
severities[1] = 1;
severities[2] = 2;
PVIntArrayPtr pvSeverity = multiChannel->getSeverity();
pvSeverity->replace(freeze(severities));
if(debug) {cout << *pvStructure << endl;}
PVBooleanArrayPtr pvIsConnected = multiChannel->getIsConnected();
shared_vector<const epics::pvData::boolean> isConnected = pvIsConnected->view();
multiChannel = builder->
value(pvDouble) ->
addDescriptor()->
addAlarm()->
addTimeStamp()->
addSeverity() ->
addStatus() ->
addMessage() ->
addSecondsPastEpoch() ->
addNanoseconds() ->
addUserTag() ->
addIsConnected() ->
create();
testOk1(multiChannel.get() != 0);
pvStructure = multiChannel->getPVStructure();
if(debug) {cout << *pvStructure << endl;}
testOk1(NTScalarMultiChannel::isCompatible(pvStructure)==true);
PVStructurePtr pvTimeStamp = multiChannel->getTimeStamp();
testOk1(pvTimeStamp.get() !=0);
PVStructurePtr pvAlarm = multiChannel->getAlarm();
testOk1(pvAlarm.get() !=0);
pvValue = multiChannel->getValue<PVDoubleArray>();
testOk1(pvValue.get() !=0);
pvChannelName = multiChannel->getChannelName();
testOk1(pvChannelName.get() !=0);
pvIsConnected = multiChannel->getIsConnected();
testOk1(pvIsConnected.get() !=0);
pvSeverity = multiChannel->getSeverity();
testOk1(pvSeverity.get() !=0);
PVIntArrayPtr pvStatus = multiChannel->getStatus();
testOk1(pvStatus.get() !=0);
PVStringArrayPtr pvMessage = multiChannel->getMessage();
testOk1(pvMessage.get() !=0);
PVLongArrayPtr pvSecondsPastEpoch = multiChannel->getSecondsPastEpoch();
testOk1(pvSecondsPastEpoch.get() !=0);
PVIntArrayPtr pvNanoseconds = multiChannel->getNanoseconds();
testOk1(pvNanoseconds.get() !=0);
PVIntArrayPtr pvUserTag = multiChannel->getUserTag();
testOk1(pvUserTag.get() !=0);
PVStringPtr pvDescriptor = multiChannel->getDescriptor();
testOk1(pvDescriptor.get() !=0);
}
void test_wrap()
{
testDiag("test_wrap");
NTScalarMultiChannelPtr nullPtr = NTScalarMultiChannel::wrap(PVStructurePtr());
testOk(nullPtr.get() == 0, "nullptr wrap");
nullPtr = NTScalarMultiChannel::wrap(
getPVDataCreate()->createPVStructure(
NTField::get()->createTimeStamp()
)
);
testOk(nullPtr.get() == 0, "wrong type wrap");
NTScalarMultiChannelBuilderPtr builder = NTScalarMultiChannel::createBuilder();
testOk(builder.get() != 0, "Got builder");
PVStructurePtr pvStructure = builder->
createPVStructure();
testOk1(pvStructure.get() != 0);
if (!pvStructure)
return;
NTScalarMultiChannelPtr ptr = NTScalarMultiChannel::wrap(pvStructure);
testOk(ptr.get() != 0, "wrap OK");
builder = NTScalarMultiChannel::createBuilder();
ptr = NTScalarMultiChannel::wrapUnsafe(pvStructure);
testOk(ptr.get() != 0, "wrapUnsafe OK");
}
MAIN(testCreateRequest)
{
testPlan(27);
test();
test_wrap();
return testDone();
}

View File

@@ -1,7 +1,6 @@
/**
* Copyright - See the COPYRIGHT that is included with this distribution.
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#include <epicsUnitTest.h>
@@ -86,6 +85,9 @@ void test_ntscalar()
create();
testOk1(ntScalar.get() != 0);
testOk1(NTScalar::is_a(ntScalar->getPVStructure()));
testOk1(NTScalar::isCompatible(ntScalar->getPVStructure()));
testOk1(ntScalar->getPVStructure().get() != 0);
testOk1(ntScalar->getValue().get() != 0);
testOk1(ntScalar->getDescriptor().get() != 0);
@@ -226,7 +228,7 @@ void test_wrap()
}
MAIN(testNTScalar) {
testPlan(35);
testPlan(37);
test_builder();
test_ntscalar();
test_wrap();

View File

@@ -1,7 +1,6 @@
/**
* Copyright - See the COPYRIGHT that is included with this distribution.
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#include <epicsUnitTest.h>
@@ -22,9 +21,9 @@ void test_builder()
testOk(builder.get() != 0, "Got builder");
StructureConstPtr structure = builder->
add("column0", pvDouble)->
add("column1", pvString)->
add("column2", pvInt)->
addColumn("column0", pvDouble)->
addColumn("column1", pvString)->
addColumn("column2", pvInt)->
addDescriptor()->
addAlarm()->
addTimeStamp()->
@@ -37,12 +36,14 @@ void test_builder()
testOk1(NTTable::is_a(structure));
testOk1(structure->getID() == NTTable::URI);
testOk1(structure->getNumberFields() == 5);
testOk1(structure->getNumberFields() == 7);
testOk1(structure->getField("labels").get() != 0);
testOk1(structure->getField("value").get() != 0);
testOk1(structure->getField("descriptor").get() != 0);
testOk1(structure->getField("alarm").get() != 0);
testOk1(structure->getField("timeStamp").get() != 0);
testOk1(structure->getField("extra1").get() != 0);
testOk1(structure->getField("extra2").get() != 0);
StructureConstPtr s = dynamic_pointer_cast<const Structure>(structure->getField("value"));
#define TEST_COLUMN(name, type) \
@@ -62,8 +63,8 @@ void test_builder()
try
{
structure = builder->
add("column0", pvDouble)->
add("column0", pvString)->
addColumn("column0", pvDouble)->
addColumn("column0", pvString)->
createStructure();
testFail("duplicate column name");
} catch (std::runtime_error &) {
@@ -79,9 +80,9 @@ void test_labels()
testOk(builder.get() != 0, "Got builder");
PVStructurePtr pvStructure = builder->
add("column0", pvDouble)->
add("column1", pvString)->
add("column2", pvInt)->
addColumn("column0", pvDouble)->
addColumn("column1", pvString)->
addColumn("column2", pvInt)->
createPVStructure();
testOk1(pvStructure.get() != 0);
if (!pvStructure)
@@ -108,15 +109,18 @@ void test_nttable()
testOk(builder.get() != 0, "Got builder");
NTTablePtr ntTable = builder->
add("column0", pvDouble)->
add("column1", pvString)->
add("column2", pvInt)->
addColumn("column0", pvDouble)->
addColumn("column1", pvString)->
addColumn("column2", pvInt)->
addDescriptor()->
addAlarm()->
addTimeStamp()->
create();
testOk1(ntTable.get() != 0);
testOk1(NTTable::is_a(ntTable->getPVStructure()));
testOk1(NTTable::isCompatible(ntTable->getPVStructure()));
testOk1(ntTable->getPVStructure().get() != 0);
testOk1(ntTable->getDescriptor().get() != 0);
testOk1(ntTable->getAlarm().get() != 0);
@@ -218,9 +222,9 @@ void test_wrap()
testOk(builder.get() != 0, "Got builder");
PVStructurePtr pvStructure = builder->
add("column0", pvDouble)->
add("column1", pvString)->
add("column2", pvInt)->
addColumn("column0", pvDouble)->
addColumn("column1", pvString)->
addColumn("column2", pvInt)->
createPVStructure();
testOk1(pvStructure.get() != 0);
if (!pvStructure)
@@ -234,7 +238,7 @@ void test_wrap()
}
MAIN(testNTTable) {
testPlan(46);
testPlan(50);
test_builder();
test_labels();
test_nttable();

200
test/ntunionTest.cpp Normal file
View File

@@ -0,0 +1,200 @@
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#include <epicsUnitTest.h>
#include <testMain.h>
#include <pv/nt.h>
using namespace epics::nt;
using namespace epics::pvData;
using std::tr1::dynamic_pointer_cast;
static FieldCreatePtr fieldCreate = getFieldCreate();
static StandardFieldPtr standardField = getStandardField();
static NTFieldPtr ntField = NTField::get();
void test_builder()
{
testDiag("test_builder");
NTUnionBuilderPtr builder = NTUnion::createBuilder();
testOk(builder.get() != 0, "Got builder");
StructureConstPtr structure = builder->
addDescriptor()->
addAlarm()->
addTimeStamp()->
add("valueAlarm",standardField->doubleAlarm()) ->
add("extra",fieldCreate->createScalarArray(pvString)) ->
createStructure();
testOk1(structure.get() != 0);
if (!structure)
return;
testOk1(NTUnion::is_a(structure));
testOk1(structure->getID() == NTUnion::URI);
testOk1(structure->getNumberFields() == 6);
testOk1(structure->getField("value").get() != 0);
testOk1(structure->getField("descriptor").get() != 0);
testOk1(structure->getField("alarm").get() != 0);
testOk1(structure->getField("timeStamp").get() != 0);
UnionConstPtr valueField = structure->getField<Union>("value");
testOk(valueField.get() != 0, "value is enum");
std::cout << *structure << std::endl;
}
void test_ntunion()
{
testDiag("test_ntunion");
NTUnionBuilderPtr builder = NTUnion::createBuilder();
testOk(builder.get() != 0, "Got builder");
NTUnionPtr ntUnion = builder->
addDescriptor()->
addAlarm()->
addTimeStamp()->
create();
testOk1(ntUnion.get() != 0);
testOk1(NTUnion::is_a(ntUnion->getPVStructure()));
testOk1(NTUnion::isCompatible(ntUnion->getPVStructure()));
testOk1(ntUnion->getPVStructure().get() != 0);
testOk1(ntUnion->getValue().get() != 0);
testOk1(ntUnion->getDescriptor().get() != 0);
testOk1(ntUnion->getAlarm().get() != 0);
testOk1(ntUnion->getTimeStamp().get() != 0);
// TODO
// 1. Variant union example.
// 2. set the union value.
//
// timeStamp ops
//
PVTimeStamp pvTimeStamp;
if (ntUnion->attachTimeStamp(pvTimeStamp))
{
testPass("timeStamp attach");
// example how to set current time
TimeStamp ts;
ts.getCurrent();
pvTimeStamp.set(ts);
// example how to get EPICS time
TimeStamp ts2;
pvTimeStamp.get(ts2);
testOk1(ts2.getEpicsSecondsPastEpoch() != 0);
}
else
testFail("timeStamp attach fail");
//
// alarm ops
//
PVAlarm pvAlarm;
if (ntUnion->attachAlarm(pvAlarm))
{
testPass("alarm attach");
// example how to set an alarm
Alarm alarm;
alarm.setStatus(deviceStatus);
alarm.setSeverity(minorAlarm);
alarm.setMessage("simulation alarm");
pvAlarm.set(alarm);
}
else
testFail("alarm attach fail");
//
// set descriptor
//
ntUnion->getDescriptor()->put("This is a test NTUnion");
// dump ntUnion
std::cout << *ntUnion->getPVStructure() << std::endl;
}
void test_wrap()
{
testDiag("test_wrap");
NTUnionPtr nullPtr = NTUnion::wrap(PVStructurePtr());
testOk(nullPtr.get() == 0, "nullptr wrap");
nullPtr = NTUnion::wrap(
getPVDataCreate()->createPVStructure(
NTField::get()->createTimeStamp()
)
);
testOk(nullPtr.get() == 0, "wrong type wrap");
NTUnionBuilderPtr builder = NTUnion::createBuilder();
testOk(builder.get() != 0, "Got builder");
PVStructurePtr pvStructure = builder->
createPVStructure();
testOk1(pvStructure.get() != 0);
if (!pvStructure)
return;
testOk1(NTUnion::isCompatible(pvStructure)==true);
NTUnionPtr ptr = NTUnion::wrap(pvStructure);
testOk(ptr.get() != 0, "wrap OK");
ptr = NTUnion::wrapUnsafe(pvStructure);
testOk(ptr.get() != 0, "wrapUnsafe OK");
}
void test_variant_union()
{
StructureConstPtr structure = NTUnion::createBuilder()->
addDescriptor()->
addAlarm()->
addTimeStamp()->
createStructure();
testOk1(structure->getField<Union>("value")->isVariant());
}
void test_regular_union()
{
UnionConstPtr u = getFieldCreate()->createFieldBuilder()->
add("x", pvDouble)->
add("i", pvInt)->
createUnion();
StructureConstPtr structure = NTUnion::createBuilder()->
value(u)->
addDescriptor()->
addAlarm()->
addTimeStamp()->
createStructure();
testOk1(!structure->getField<Union>("value")->isVariant());
testOk1(structure->getField<Union>("value") == u);
}
MAIN(testNTUnion) {
testPlan(32);
test_builder();
test_ntunion();
test_wrap();
test_variant_union();
test_regular_union();
return testDone();
}

View File

@@ -1,7 +1,6 @@
/**
* Copyright - See the COPYRIGHT that is included with this distribution.
* EPICS pvDataCPP is distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
/*
* Copyright information and license terms for this software can be
* found in the file LICENSE that is included with the distribution
*/
#include <epicsUnitTest.h>
@@ -24,11 +23,13 @@ void test_is_a()
testOk1(!NTUtils::is_a("epics:nt/NTTable:1.0", "epics:nt/NTTable:2.0"));
testOk1(!NTUtils::is_a("epics:nt/NTTable:2.0", "epics:nt/NTTable:1.0"));
testOk1(!NTUtils::is_a("epics:nt/NTTable:1.3", "epics:nt/NTTable:2.3"));
testOk1(!NTUtils::is_a("epics:nt/NTTable:1.0", "epics:nt/NTTable:11.0"));
testOk1(!NTUtils::is_a("epics:nt/NTTable:11.0", "epics:nt/NTTable:1.0"));
testOk1(!NTUtils::is_a("epics:nt/NTTable:1.0", "epics:nt/NTMatrix:1.0"));
}
MAIN(testNTUtils) {
testPlan(8);
testPlan(10);
test_is_a();
return testDone();
}