init notmative types repo, which is moved from alphaCPP repo

This commit is contained in:
Guobao Shen
2012-07-16 10:01:32 -04:00
commit 7facd19fb1
25 changed files with 3678 additions and 0 deletions

18
.hgignore Normal file
View File

@ -0,0 +1,18 @@
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

1721
Doxyfile Normal file

File diff suppressed because it is too large Load Diff

12
Makefile Normal file
View File

@ -0,0 +1,12 @@
#Makefile at top of application tree
TOP = .
include $(TOP)/configure/CONFIG
DIRS += configure
DIRS += src
src_DEPEND_DIRS = configure
DIRS += test
test_DEPEND_DIRS = src
include $(TOP)/configure/RULES_TOP

30
configure/CONFIG Normal file
View File

@ -0,0 +1,30 @@
# CONFIG
# You might want to change this to some shared set of rules, e.g.
# RULES=/path/to/epics/support/modules/rules/x-y
RULES=$(EPICS_BASE)
include $(TOP)/configure/RELEASE
-include $(TOP)/configure/RELEASE.$(EPICS_HOST_ARCH)
-include $(TOP)/configure/RELEASE.$(EPICS_HOST_ARCH).Common
ifdef T_A
-include $(TOP)/configure/RELEASE.Common.$(T_A)
-include $(TOP)/configure/RELEASE.$(EPICS_HOST_ARCH).$(T_A)
endif
CONFIG=$(RULES)/configure
include $(CONFIG)/CONFIG
# Override for definition in base
INSTALL_LOCATION = $(TOP)
include $(TOP)/configure/CONFIG_SITE
-include $(TOP)/configure/CONFIG_SITE.$(EPICS_HOST_ARCH)
-include $(TOP)/configure/CONFIG_SITE.$(EPICS_HOST_ARCH).Common
ifdef T_A
-include $(TOP)/configure/CONFIG_SITE.Common.$(T_A)
-include $(TOP)/configure/CONFIG_SITE.$(EPICS_HOST_ARCH).$(T_A)
-include $(TOP)/configure/O.$(T_A)/CONFIG_APP_INCLUDE
endif

34
configure/CONFIG_SITE Normal file
View File

@ -0,0 +1,34 @@
# CONFIG_SITE
# Make any application-specific changes to the EPICS build
# configuration variables in this file.
#
# Host/target specific settings can be specified in files named
# CONFIG_SITE.$(EPICS_HOST_ARCH).Common
# CONFIG_SITE.Common.$(T_A)
# CONFIG_SITE.$(EPICS_HOST_ARCH).$(T_A)
# Set this when you only want to compile this application
# for a subset of the cross-compiled target architectures
# that Base is built for.
#CROSS_COMPILER_TARGET_ARCHS = vxWorks-68040
# Set this when your IOC and the host use different paths
# to access the application. This will be needed to boot
# from a Microsoft FTP server or with some NFS mounts.
# You must rebuild in the iocBoot directory for this to
# take effect.
#IOCS_APPL_TOP = <path to application top as seen by IOC>
# If you don't want to install into $(TOP) then
# define INSTALL_LOCATION here
#INSTALL_LOCATION=<fullpathname>
ifeq ($(EPICS_TEST_COVERAGE),1)
USR_CPPFLAGS += --coverage
USR_LDFLAGS += --coverage
endif
INSTALL_INCLUDE = $(INSTALL_LOCATION)/include/pv
USR_INCLUDES += -I $(INSTALL_LOCATION)/include

17
configure/Makefile Normal file
View File

@ -0,0 +1,17 @@
TOP=..
include $(TOP)/configure/CONFIG
# CHECK_RELEASE controls the consistency checking of the support
# applications defined in the $(TOP)/configure/RELEASE* files.
# Normally CHECK_RELEASE should be set to YES.
# Set CHECK_RELEASE to NO to disable checking completely.
# Set CHECK_RELEASE to WARN to perform consistency checking,
# but continue the build even if conflicts are found.
CHECK_RELEASE = YES
TARGETS = $(CONFIG_TARGETS)
CONFIGS += $(subst ../,,$(wildcard $(CONFIG_INSTALLS)))
include $(TOP)/configure/RULES

31
configure/RELEASE Normal file
View File

@ -0,0 +1,31 @@
#RELEASE Location of external products
#
# 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.
#
# 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.
#
# Host/target specific settings can be specified in files named
# RELEASE.$(EPICS_HOST_ARCH).Common
# RELEASE.Common.$(T_A)
# RELEASE.$(EPICS_HOST_ARCH).$(T_A)
TEMPLATE_TOP=$(EPICS_BASE)/templates/makeBaseApp/top
#If using the sequencer, point SNCSEQ at its top directory:
#SNCSEQ=$(EPICS_BASE)/../modules/soft/seq
# EPICS_BASE usually appears last so other apps can override stuff:
#EPICS_BASE=/opt/epics/base
#Capfast users may need the following definitions
#CAPFAST_TEMPLATES=
#SCH2EDIF_PATH=
-include $(TOP)/configure/RELEASE.local

6
configure/RULES Normal file
View File

@ -0,0 +1,6 @@
# RULES
include $(CONFIG)/RULES
# Library should be rebuilt because LIBOBJS may have changed.
$(LIBNAME): ../Makefile

2
configure/RULES.ioc Normal file
View File

@ -0,0 +1,2 @@
#RULES.ioc
include $(CONFIG)/RULES.ioc

2
configure/RULES_DIRS Normal file
View File

@ -0,0 +1,2 @@
#RULES_DIRS
include $(CONFIG)/RULES_DIRS

3
configure/RULES_TOP Normal file
View File

@ -0,0 +1,3 @@
#RULES_TOP
include $(CONFIG)/RULES_TOP

289
documentation/ntCPP.html Normal file
View File

@ -0,0 +1,289 @@
<?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 }
body { margin-right: 10% }
/*]]>*/</style>
</head>
<body>
<h1 style="text-align: center">EPICS pvDataCPP<br />
2012.01.11</h1>
<p>TODO</p>
<ul>
<li>Move next section to pvDataCPP documentation.</li>
</ul>
<hr />
<h2 style="text-align: center">Normative Types</h2>
<hr />
<p>This section describes the C++ implemmentation of normative types.</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 NTField * get();
~NTField() {}
bool isEnumerated(FieldConstPtr field);
bool isTimeStamp(FieldConstPtr field);
bool isAlarm(FieldConstPtr field);
bool isDisplay(FieldConstPtr field);
bool isAlarmLimit(FieldConstPtr field);
bool isControl(FieldConstPtr field);
StructureConstPtr createEnumerated(String fieldName);
StructureConstPtr createTimeStamp();
StructureConstPtr createAlarm();
StructureConstPtr createDisplay();
StructureConstPtr createAlarmLimit();
StructureConstPtr createControl();
StructureArrayConstPtr createEnumeratedArray(String fieldName);
StructureArrayConstPtr createTimeStampArray(String fieldName);
StructureArrayConstPtr createAlarmArray(String fieldName);
};</pre>
<p>where</p>
<dl>
<dt>isEnumerated</dt>
<dd>Is this field an enumerated structure, i. e. a structure that has a int
field named index and a string array field named choices.</dd>
<dt>isTimeStamp</dt>
<dd>Is this field a timeStamp structure.</dd>
<dt>isAlarm</dt>
<dd>Is this field an alarm structure..</dd>
<dt>isDisplay</dt>
<dd>Is the field a display structure.</dd>
<dt>isAlarmLimit</dt>
<dd>Is the field an alarm limit structure.</dd>
<dt>isControl</dt>
<dd>Is the field a control structure.</dd>
<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 pvStructure);
static PVStructure::shared_pointer create(
bool hasFunction,bool hasTimeStamp, bool hasAlarm);
NTNameValue(PVStructure::shared_pointer const &amp; pvStructure);
~NTNameValue();
PVString* getFunction();
void attachTimeStamp(PVTimeStamp &amp;pvTimeStamp);
void attachAlarm(PVAlarm &amp;pvAlarm);
PVStructurePtr getPVStructure();
PVStructurePtr getTimeStamp();
PVStructurePtr getAlarm();
PVStringArray *getNames();
PVStringArray *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 constructor. The pvStructure <b>must</b> be a NTNameValue
structure.</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 pvStructure);
static PVStructure::shared_pointer create(
bool hasFunction,bool hasTimeStamp, bool hasAlarm,
int numberValues,
FieldConstPtrArray valueFields);
NTTable(PVStructure::shared_pointer const &amp; pvStructure);
~NTTable();
PVString *getFunction();
void attachTimeStamp(PVTimeStamp &amp;pvTimeStamp);
void attachAlarm(PVAlarm &amp;pvAlarm);
PVStructurePtr getPVStructure();
PVStructurePtr getTimeStamp();
PVStructurePtr getAlarm();
PVStringArray *getLabel();
int 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 constructor. The pvStructure <b>must</b> be a NTTable
structure.</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>
<hr />
<h2 style="text-align: center">License Agreement</h2>
<hr />
<pre>Copyright (c) 2008 Martin R. Kraimer
Copyright (c) 2007 Control System Laboratory,
(COSYLAB) Ljubljana Slovenia
Copyright (c) 2010 Brookhaven National Laboratory
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.
________________________________________________________________________
This software is in part copyrighted by Brookhaven National Laboratory(BNL)
In no event shall BNL 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
BNL has been advised of the possibility of such damage.
BNL specifically disclaims 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 BNL has no obligation to provide maintenance, support,
updates, enhancements, or modifications.
________________________________________________________________________
This software is in part copyrighted by the BERLINER SPEICHERRING
GESELLSCHAFT FUER SYNCHROTRONSTRAHLUNG M.B.H. (BESSY), BERLIN, GERMANY.
In no event shall BESSY 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
BESSY has been advised of the possibility of such damage.
BESSY specifically disclaims 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 BESSY has no obligation to provide maintenance, support,
updates, enhancements, or modifications.
________________________________________________________________________
This software is in part copyrighted by the Deutsches Elektronen-Synchroton,
Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY.
In no event shall DESY 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
DESY has been advised of the possibility of such damage.
DESY specifically disclaims 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 DESY has no obligation to provide maintenance, support,
updates, enhancements, or modifications.
________________________________________________________________________</pre>
</body>
</html>

22
src/Makefile Normal file
View File

@ -0,0 +1,22 @@
TOP = ..
include $(TOP)/configure/CONFIG
SRC = $(TOP)/src/
SRC_DIRS += $(SRC)/nt
INC += nt.h
INC += ntfield.h
INC += ntnameValue.h
INC += nttable.h
LIBSRCS += ntfield.cpp
LIBSRCS += ntnameValue.cpp
LIBSRCS += nttable.cpp
LIBRARY=nt
nt_LIBS += pvData Com
include $(TOP)/configure/RULES

15
src/nt/nt.h Normal file
View File

@ -0,0 +1,15 @@
/* 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 <pv/ntfield.h>
#include <pv/ntnameValue.h>
#include <pv/nttable.h>
#endif /* NT_H */

339
src/nt/ntfield.cpp Normal file
View File

@ -0,0 +1,339 @@
/* ntArgument.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.
*/
#include <pv/lock.h>
#include <pv/ntfield.h>
namespace epics { namespace pvData {
NTField *NTField::get()
{
static Mutex mutex;
static NTField *ntstructureField = 0;
Lock xx(mutex);
if(ntstructureField==0) ntstructureField = new NTField();
return ntstructureField;
}
NTField::NTField()
: fieldCreate(getFieldCreate()),
standardField(getStandardField())
{
}
bool NTField::isEnumerated(FieldConstPtr field)
{
if(field->getType()!=structure) return false;
const Structure *st = static_cast<const Structure *>(field.get());
FieldConstPtrArray fields = st->getFields();
int n = st->getNumberFields();
if(n!=2) return false;
FieldConstPtr f = fields[0];
if(f->getFieldName().compare("index")!=0) return false;
if(f->getType()!=scalar) return false;
const Scalar* s = static_cast<const Scalar*>(f.get());
if(s->getScalarType()!=pvInt) return false;
f = fields[1];
if(f->getFieldName().compare("choices")!=0) return false;
if(f->getType()!=scalarArray) return false;
const ScalarArray* sa = static_cast<const ScalarArray*>(f.get());
if(sa->getElementType()!=pvString) return false;
return true;
}
bool NTField::isTimeStamp(FieldConstPtr field)
{
if(field->getType()!=structure) return false;
const Structure *st = static_cast<const Structure *>(field.get());
if(field->getFieldName().compare("timeStamp")!=0) return false;
FieldConstPtrArray fields = st->getFields();
int n = st->getNumberFields();
if(n!=3) return false;
FieldConstPtr f = fields[0];
if(f->getFieldName().compare("secondsPastEpoch")!=0) return false;
if(f->getType()!=scalar) return false;
const Scalar* s = static_cast<const Scalar*>(f.get());
if(s->getScalarType()!=pvLong) return false;
f = fields[1];
if(f->getFieldName().compare("nanoSeconds")!=0) return false;
if(f->getType()!=scalar) return false;
s = static_cast<const Scalar*>(f.get());
if(s->getScalarType()!=pvInt) return false;
f = fields[2];
if(f->getFieldName().compare("userTag")!=0) return false;
if(f->getType()!=scalar) return false;
s = static_cast<const Scalar*>(f.get());
if(s->getScalarType()!=pvInt) return false;
return true;
}
bool NTField::isAlarm(FieldConstPtr field)
{
if(field->getType()!=structure) return false;
const Structure *st = static_cast<const Structure *>(field.get());
if(field->getFieldName().compare("alarm")!=0) return false;
FieldConstPtrArray fields = st->getFields();
int n = st->getNumberFields();
if(n!=3) return false;
FieldConstPtr f = fields[0];
if(f->getFieldName().compare("severity")!=0) return false;
if(f->getType()!=scalar) return false;
const Scalar* s = static_cast<const Scalar*>(f.get());
if(s->getScalarType()!=pvInt) return false;
f = fields[1];
if(f->getFieldName().compare("status")!=0) return false;
if(f->getType()!=scalar) return false;
s = static_cast<const Scalar*>(f.get());
if(s->getScalarType()!=pvInt) return false;
f = fields[2];
if(f->getFieldName().compare("message")!=0) return false;
if(f->getType()!=scalar) return false;
s = static_cast<const Scalar*>(f.get());
if(s->getScalarType()!=pvString) return false;
return true;
}
bool NTField::isDisplay(FieldConstPtr field)
{
if(field->getType()!=structure) return false;
const Structure *st = static_cast<const Structure *>(field.get());
if(field->getFieldName().compare("display")!=0) return false;
FieldConstPtrArray fields = st->getFields();
int n = st->getNumberFields();
if(n!=4) return false;
// look at limit first
FieldConstPtr f = fields[3];
if(f->getFieldName().compare("limit")!=0) return false;
if(f->getType()!=structure) return false;
const Structure* s = static_cast<const Structure*>(f.get());
FieldConstPtrArray subfields = s->getFields();
n = s->getNumberFields();
if(n!=2) return false;
f = subfields[0];
if(f->getFieldName().compare("low")!=0) return false;
if(f->getType()!=scalar) return false;
const Scalar* sc = static_cast<const Scalar*>(f.get());
if(sc->getScalarType()!=pvDouble) return false;
f = subfields[1];
if(f->getFieldName().compare("high")!=0) return false;
if(f->getType()!=scalar) return false;
sc = static_cast<const Scalar*>(f.get());
if(sc->getScalarType()!=pvDouble) return false;
f = fields[0];
if(f->getFieldName().compare("description")!=0) return false;
if(f->getType()!=scalar) return false;
sc = static_cast<const Scalar*>(f.get());
if(sc->getScalarType()!=pvString) return false;
f = fields[1];
if(f->getFieldName().compare("format")!=0) return false;
if(f->getType()!=scalar) return false;
sc = static_cast<const Scalar*>(f.get());
if(sc->getScalarType()!=pvString) return false;
f = fields[2];
if(f->getFieldName().compare("units")!=0) return false;
if(f->getType()!=scalar) return false;
sc = static_cast<const Scalar*>(f.get());
if(sc->getScalarType()!=pvString) return false;
return true;
}
bool NTField::isAlarmLimit(FieldConstPtr field)
{
if(field->getType()!=structure) return false;
const Structure *st = static_cast<const Structure *>(field.get());
if(field->getFieldName().compare("alarmLimit")!=0) return false;
FieldConstPtrArray fields = st->getFields();
int n = st->getNumberFields();
if(n!=4) return false;
FieldConstPtr f = fields[0];
if(f->getFieldName().compare("highAlarm")!=0) return false;
if(f->getType()!=scalar) return false;
const Scalar *sc = static_cast<const Scalar *>(f.get());
if(sc->getScalarType()!=pvDouble) return false;
f = fields[1];
if(f->getFieldName().compare("highWarning")!=0) return false;
if(f->getType()!=scalar) return false;
sc = static_cast<const Scalar *>(f.get());
if(sc->getScalarType()!=pvDouble) return false;
f = fields[2];
if(f->getFieldName().compare("lowWarning")!=0) return false;
if(f->getType()!=scalar) return false;
sc = static_cast<const Scalar *>(f.get());
if(sc->getScalarType()!=pvDouble) return false;
f = fields[3];
if(f->getFieldName().compare("lowAlarm")!=0) return false;
if(f->getType()!=scalar) return false;
sc = static_cast<const Scalar *>(f.get());
if(sc->getScalarType()!=pvDouble) return false;
return true;
}
bool NTField::isControl(FieldConstPtr field)
{
if(field->getType()!=structure) return false;
const Structure *st = static_cast<const Structure *>(field.get());
if(field->getFieldName().compare("control")!=0) return false;
FieldConstPtrArray fields = st->getFields();
int n = st->getNumberFields();
if(n!=2) return false;
FieldConstPtr f = fields[1];
if(f->getFieldName().compare("minStep")!=0) return false;
if(f->getType()!=scalar) return false;
const Scalar* sc = static_cast<const Scalar*>(f.get());
if(sc->getScalarType()!=pvDouble) return false;
f = fields[0];
if(f->getFieldName().compare("limit")!=0) return false;
if(f->getType()!=structure) return false;
const Structure* s = static_cast<const Structure*>(f.get());
fields = s->getFields();
n = s->getNumberFields();
if(n!=2) return false;
f = fields[0];
if(f->getFieldName().compare("low")!=0) return false;
if(f->getType()!=scalar) return false;
sc = static_cast<const Scalar*>(f.get());
if(sc->getScalarType()!=pvDouble) return false;
f = fields[1];
if(f->getFieldName().compare("high")!=0) return false;
if(f->getType()!=scalar) return false;
sc = static_cast<const Scalar*>(f.get());
if(sc->getScalarType()!=pvDouble) return false;
return true;
}
StructureConstPtr NTField::createEnumerated(String fieldName)
{
return standardField->enumerated(fieldName);
}
StructureConstPtr NTField::createTimeStamp()
{
return standardField->timeStamp();
}
StructureConstPtr NTField::createAlarm()
{
return standardField->alarm();
}
StructureConstPtr NTField::createDisplay()
{
return standardField->display();
}
StructureConstPtr NTField::createAlarmLimit()
{
int numFields = 4;
FieldConstPtrArray fields = new FieldConstPtr[numFields];
fields[0] = fieldCreate->createScalar(String("highAlarm"),pvDouble);
fields[1] = fieldCreate->createScalar(String("highWarning"),pvDouble);
fields[2] = fieldCreate->createScalar(String("lowWarning"),pvDouble);
fields[3] = fieldCreate->createScalar(String("lowAlarm"),pvDouble);
return fieldCreate->createStructure(String("alarmLimit"),numFields,fields);
}
StructureConstPtr NTField::createControl()
{
return standardField->control();
}
StructureArrayConstPtr NTField::createEnumeratedArray(String fieldName)
{
StructureConstPtr st = createEnumerated(fieldName);
return fieldCreate->createStructureArray(fieldName,st);
}
StructureArrayConstPtr NTField::createTimeStampArray(String fieldName)
{
StructureConstPtr st = createTimeStamp();
return fieldCreate->createStructureArray(fieldName,st);
}
StructureArrayConstPtr NTField::createAlarmArray(String fieldName)
{
StructureConstPtr st = createAlarm();
return fieldCreate->createStructureArray(fieldName,st);
}
PVNTField *PVNTField::get()
{
static Mutex mutex;
static PVNTField *pvntstructureField = 0;
Lock xx(mutex);
if(pvntstructureField==0) pvntstructureField = new PVNTField();
return pvntstructureField;
}
PVNTField::PVNTField()
: pvDataCreate(getPVDataCreate()),
standardPVField(getStandardPVField()),
ntstructureField(NTField::get())
{
}
PVStructurePtr PVNTField::createEnumerated(
PVStructurePtr parent,
String fieldName,
StringArray choices,
int numberChoices)
{
return standardPVField->enumerated(parent,fieldName,choices,numberChoices);
}
PVStructurePtr PVNTField::createTimeStamp(PVStructurePtr parent)
{
return standardPVField->timeStamp(parent);
}
PVStructurePtr PVNTField::createAlarm(PVStructurePtr parent)
{
return standardPVField->alarm(parent);
}
PVStructurePtr PVNTField::createDisplay(PVStructurePtr parent)
{
return standardPVField->display(parent);
}
PVStructurePtr PVNTField::createAlarmLimit(PVStructurePtr parent)
{
StructureConstPtr structure = NTField::get()->createAlarmLimit();
return pvDataCreate->createPVStructure(parent,structure);
}
PVStructurePtr PVNTField::createControl(PVStructurePtr parent)
{
return standardPVField->control(parent);
}
PVStructureArray *PVNTField::createEnumeratedArray(
PVStructurePtr parent,String fieldName)
{
StructureArrayConstPtr sa = ntstructureField->createEnumeratedArray(fieldName);
return pvDataCreate->createPVStructureArray(parent,sa);
}
PVStructureArray *PVNTField::createTimeStampArray(
PVStructurePtr parent,String fieldName)
{
StructureArrayConstPtr sa = ntstructureField->createTimeStampArray(fieldName);
return pvDataCreate->createPVStructureArray(parent,sa);
}
PVStructureArray *PVNTField::createAlarmArray(
PVStructurePtr parent,String fieldName)
{
StructureArrayConstPtr sa = ntstructureField->createAlarmArray(fieldName);
return pvDataCreate->createPVStructureArray(parent,sa);
}
}}

221
src/nt/ntfield.h Normal file
View File

@ -0,0 +1,221 @@
/* 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.
*/
#ifndef NTFIELD_H
#define NTFIELD_H
#include <cstdarg>
#include <pv/standardField.h>
#include <pv/standardPVField.h>
#include <pv/alarm.h>
#include <pv/pvAlarm.h>
#include <pv/timeStamp.h>
#include <pv/pvTimeStamp.h>
namespace epics { namespace pvData {
/**
* Convenience Class for introspection fields of a Normative Type
* @author mrk
*
*/
class NTField: NoDefaultMethods {
public:
/**
* get the single implementation of this class.
* @return the implementation
*/
static NTField * get();
/**
* destructor
*/
~NTField() {}
/**
* Is field an enumerated structure.
* @param field The field to test.
* @return (false,true) if field (is not,is) an enumerated structure.
*/
bool isEnumerated(FieldConstPtr field);
/**
* Is field a timeStamp structure.
* @param field The field to test.
* @return (false,true) if field (is not,is) a timeStamp structure.
*/
bool isTimeStamp(FieldConstPtr field);
/**
* Is field an alarm structure.
* @param field The field to test.
* @return (false,true) if field (is not,is) an alarm structure.
*/
bool isAlarm(FieldConstPtr field);
/**
* Is field a display structure.
* @param field The field to test.
* @return (false,true) if field (is not,is) a display structure.
*/
bool isDisplay(FieldConstPtr field);
/**
* Is field an alarmLimit structure.
* @param field The field to test.
* @return (false,true) if field (is not,is) an alarmLimit structure.
*/
bool isAlarmLimit(FieldConstPtr field);
/**
* Is field a control structure.
* @param field The field to test.
* @return (false,true) if field (is not,is) a control structure.
*/
bool isControl(FieldConstPtr field);
/**
* Create an enumerated structure.
* @param fieldName The fieldName for the structure.
* @return an enumerated structure.
*/
StructureConstPtr createEnumerated(String fieldName);
/**
* Create a timeStamp structure.
* @return a timeStamp structure.
*/
StructureConstPtr createTimeStamp();
/**
* Create an alarm structure.
* @return an alarm structure.
*/
StructureConstPtr createAlarm();
/**
* Create a display structure.
* @return a displayalarm structure.
*/
StructureConstPtr createDisplay();
/**
* Create an alarmLimit structure.
* @return an alarmLimit structure.
*/
StructureConstPtr createAlarmLimit();
/**
* Create a control structure.
* @return a control structure.
*/
StructureConstPtr createControl();
/**
* Create an array of enumerated structures.
* @param fieldName The fieldName for the array.
* @return an array of enumerated structures.
*/
StructureArrayConstPtr createEnumeratedArray(String fieldName);
/**
* Create an array of timeStamp structures.
* @param fieldName The fieldName for the array.
* @return an array of timeStamp structures.
*/
StructureArrayConstPtr createTimeStampArray(String fieldName);
/**
* Create an array of alarm structures.
* @param fieldName The fieldName for the array.
* @return an array of alarm structures.
*/
StructureArrayConstPtr createAlarmArray(String fieldName);
private:
NTField();
FieldCreate *fieldCreate;
StandardField *standardField;
};
/**
* Convenience Class for data fields of a Normative Type
* @author mrk
*
*/
class PVNTField: NoDefaultMethods {
public:
/**
* get the single implementation of this class.
* @return the implementation
*/
static PVNTField * get();
/**
* destructor
*/
~PVNTField() {}
/**
* Create an enumerated PVStructure.
* @param parent The parent structure.
* @param fieldName The fieldName for the structure.
* @param choices The array of choices.
* @param numberChoices The number of choices.
* @return an enumerated PVStructure..
*/
PVStructurePtr createEnumerated(
PVStructurePtr parent,
String fieldName,
StringArray choices,
int numberChoices);
/**
* Create a timeStamp PVStructure.
* @param parent The parent structure.
* @return a timeStamp PVStructure..
*/
PVStructurePtr createTimeStamp(PVStructurePtr parent);
/**
* Create an alarm PVStructure.
* @param parent The parent structure.
* @return an alarm PVStructure..
*/
PVStructurePtr createAlarm(PVStructurePtr parent);
/**
* Create a display PVStructure.
* @param parent The parent structure.
* @return a display PVStructure..
*/
PVStructurePtr createDisplay(PVStructurePtr parent);
/**
* Create an alarmLimit PVStructure.
* @param parent The parent structure.
* @return an alarmLimit PVStructure..
*/
PVStructurePtr createAlarmLimit(PVStructurePtr parent);
/**
* Create a control PVStructure.
* @param parent The parent structure.
* @return a control PVStructure..
*/
PVStructurePtr createControl(PVStructurePtr parent);
/**
* Create an enumerated PVStructureArray.
* @param parent The parent structure.
* @param fieldName The fieldName for the structure.
* @return an enumerated PVStructureArray..
*/
PVStructureArray * createEnumeratedArray(
PVStructurePtr parent,String fieldName);
/**
* Create a timeStamp PVStructureArray.
* @param parent The parent structure.
* @param fieldName The fieldName for the structure.
* @return a timeStamp PVStructureArray
*/
PVStructureArray * createTimeStampArray(
PVStructurePtr parent,String fieldName);
/**
* Create an alarm PVStructureArray.
* @param parent The parent structure.
* @param fieldName The fieldName for the structure.
* @return an alarm PVStructureArray..
*/
PVStructureArray * createAlarmArray(
PVStructurePtr parent,String fieldName);
private:
PVNTField();
PVDataCreate *pvDataCreate;
StandardPVField *standardPVField;
NTField *ntstructureField;
};
}}
#endif /* NTFIELD_H */

129
src/nt/ntnameValue.cpp Normal file
View File

@ -0,0 +1,129 @@
/* 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.
*/
#include <pv/ntnameValue.h>
namespace epics { namespace pvData {
using std::tr1::static_pointer_cast;
bool NTNameValue::isNTNameValue(PVStructurePtr pvStructure)
{
String name = pvStructure->getField()->getFieldName();
if(name.compare("NTNameValue")!=0) return false;
PVFieldPtr pvField = pvStructure->getSubField("names");
if(pvField==0) return false;
FieldConstPtr field = pvField->getField();
if(field->getType()!=scalarArray) return false;
ScalarArrayConstPtr pscalarArray = static_pointer_cast<const ScalarArray>(field);
if(pscalarArray->getElementType()!=pvString) return false;
pvField = pvStructure->getSubField("values");
if(pvField==0) return false;
field = pvField->getField();
if(field->getType()!=scalarArray) return false;
pscalarArray = static_pointer_cast<const ScalarArray>(field);
if(pscalarArray->getElementType()!=pvString) return false;
return true;
}
PVStructure::shared_pointer NTNameValue::create(
bool hasFunction,bool hasTimeStamp, bool hasAlarm)
{
StandardField *standardField = getStandardField();
int nfields = 2;
if(hasFunction) nfields++;
if(hasTimeStamp) nfields++;
if(hasAlarm) nfields++;
FieldCreate *fieldCreate = getFieldCreate();
PVDataCreate *pvDataCreate = getPVDataCreate();
FieldConstPtrArray fields = new FieldConstPtr[nfields];
fields[0] = fieldCreate->createScalarArray("names",pvString);
fields[1] = fieldCreate->createScalarArray("values",pvString);
int ind = 2;
if(hasFunction) {
fields[ind++] = fieldCreate->createScalar(String("function"),pvString);
}
if(hasTimeStamp) {
fields[ind++] = standardField->timeStamp();
}
if(hasAlarm) {
fields[ind++] = standardField->alarm();
}
return PVStructure::shared_pointer(
pvDataCreate->createPVStructure(0,"NTNameValue",ind,fields));
}
NTNameValue::NTNameValue(PVStructure::shared_pointer const & pvStructure)
: pvNTNameValue(pvStructure),
pvFunction(0),
pvTimeStamp(0),
pvAlarm(0),
pvNames(0),
pvValues(0)
{
NTField *ntfield = NTField::get();
String name = pvStructure->getField()->getFieldName();
if(name.compare("NTNameValue")!=0) {
throw std::invalid_argument(
"pvArgument does not have name NTNameValue");
}
PVArray * pvArray = pvStructure->getScalarArrayField("names",pvString);
if(pvArray==0) {
throw std::invalid_argument(
"pvArgument does not have a string array field names");
}
pvNames = static_cast<PVStringArray *>(pvArray);
pvArray = pvStructure->getScalarArrayField("values",pvString);
if(pvArray==0) {
throw std::invalid_argument(
"pvArgument does not have a string array field values");
}
pvValues = static_cast<PVStringArray *>(pvArray);
PVFieldPtr pvField = pvStructure->getSubField("function");
if(pvField!=0) {
pvFunction = pvStructure->getStringField("function");
}
pvField = pvStructure->getSubField("timeStamp");
if(pvField!=0 && ntfield->isTimeStamp(pvField->getField())) {
pvTimeStamp = static_cast<PVStructure *>(pvField);
}
pvField = pvStructure->getSubField("alarm");
if(pvField!=0 && ntfield->isAlarm(pvField->getField())) {
pvAlarm = static_cast<PVStructure *>(pvField);
}
}
NTNameValue::~NTNameValue()
{
}
PVString * NTNameValue::getFunction()
{
return pvFunction;
}
void NTNameValue::attachTimeStamp(PVTimeStamp &pvTimeStamp)
{
if(this->pvTimeStamp==0) return;
pvTimeStamp.attach(this->pvTimeStamp);
}
void NTNameValue::attachAlarm(PVAlarm &pvAlarm)
{
if(this->pvAlarm==0) return;
pvAlarm.attach(this->pvAlarm);
}
PVStringArray * NTNameValue::getNames() {
return pvNames;
}
PVStringArray * NTNameValue::getValues() {
return pvValues;
}
}}

101
src/nt/ntnameValue.h Normal file
View File

@ -0,0 +1,101 @@
/* 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
#include <pv/ntfield.h>
namespace epics { namespace pvData {
/**
* Convenience Class for NTNameValue
* @author mrk
*
*/
class NTNameValue
{
public:
POINTER_DEFINITIONS(NTNameValue);
/**
* Is the pvStructure an NTNameValue.
* @param pvStructure The pvStructure to test.
* @return (false,true) if (is not, is) an NTNameValue.
*/
static bool isNTNameValue(PVStructurePtr pvStructure);
/**
* Create an NTNameValue pvStructure.
* @param hasFunction Create a PVString field named function.
* @param hasTimeStamp Create a timeStamp structure field.
* @param hasAlarm Create an alarm structure field.
* @return a NTNameValue pvStructure.
*/
static PVStructure::shared_pointer create(
bool hasFunction,bool hasTimeStamp, bool hasAlarm);
/**
* Constructor
* @param pvStructure The pvStructure to which to attach.
* @return A NTNameValue that is attached to the pvStructure
*/
NTNameValue(PVStructure::shared_pointer const & pvStructure);
/**
* Destructor
*/
~NTNameValue();
/**
* Get the function field.
* @return The pvString or null if no function field.
*/
PVString* getFunction();
/**
* Attach a pvTimeStamp.
* @param pvTimeStamp The pvTimeStamp that will be attached.
* Does nothing if no timeStamp
*/
void attachTimeStamp(PVTimeStamp &pvTimeStamp);
/**
* Attach an pvAlarm.
* @param pvAlarm The pvAlarm that will be attached.
* Does nothing if no alarm
*/
void attachAlarm(PVAlarm &pvAlarm);
/**
* Get the pvStructure.
* @return PVStructurePtr.
*/
PVStructurePtr getPVStructure(){return pvNTNameValue.get();}
/**
* Get the timeStamp.
* @return PVStructurePtr which may be null.
*/
PVStructurePtr getTimeStamp(){return pvTimeStamp;}
/**
* Get the alarm.
* @return PVStructurePtr which may be null.
*/
PVStructurePtr getAlarm() {return pvAlarm;}
/**
* Get the string array on names.
* @return The array of names.
*/
PVStringArray *getNames();
/**
* Get the string array on values.
* @return The array of values.
*/
PVStringArray *getValues();
private:
PVStructure::shared_pointer pvNTNameValue;
PVString * pvFunction;
PVStructurePtr pvTimeStamp;
PVStructurePtr pvAlarm;
PVStringArray *pvNames;
PVStringArray *pvValues;
};
}}
#endif /* NTNAMEVALUE_H */

162
src/nt/nttable.cpp Normal file
View File

@ -0,0 +1,162 @@
/* 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.
*/
#include <pv/nttable.h>
namespace epics { namespace pvData {
bool NTTable::isNTTable(PVStructurePtr pvStructure)
{
NTField *ntfield = NTField::get();
//StandardField *standardField = getStandardField();
String name = pvStructure->getField()->getFieldName();
if(name.compare("NTTable")!=0) return false;
PVStringArray *pvLabel = static_cast<PVStringArray *>
(pvStructure->getScalarArrayField("label",pvString));
if(pvLabel==0) return false;
int nfields = pvLabel->getLength();
int nextra = 1; // label is 1 field
PVFieldPtr pvField = pvStructure->getSubField("function");
if(pvField!=0 && pvStructure->getStringField("function")) nextra++;
pvField = pvStructure->getSubField("timeStamp");
if(pvField!=0 && ntfield->isTimeStamp(pvField->getField())) {
nextra++;
}
pvField = pvStructure->getSubField("alarm");
if(pvField!=0 && ntfield->isAlarm(pvField->getField())) {
nextra++;
}
if(nfields!=(pvStructure->getStructure()->getNumberFields()-nextra)) return false;
FieldConstPtrArray fields = pvStructure->getStructure()->getFields();
int n = nfields - nextra;
for(int i=0; i<n; i++) {
FieldConstPtr field = fields[i+nextra];
Type type = field->getType();
if(type!=scalarArray && type!=structureArray) return false;
}
return true;
}
PVStructure::shared_pointer NTTable::create(
bool hasFunction,bool hasTimeStamp, bool hasAlarm,
int numberValues,
FieldConstPtrArray valueFields)
{
StandardField *standardField = getStandardField();
int nfields = 1;
if(hasFunction) nfields++;
if(hasTimeStamp) nfields++;
if(hasAlarm) nfields++;
nfields += numberValues;
FieldCreate *fieldCreate = getFieldCreate();
PVDataCreate *pvDataCreate = getPVDataCreate();
FieldConstPtrArray fields = new FieldConstPtr[nfields];
int ind = 0;
if(hasFunction) {
fields[ind++] = fieldCreate->createScalar(String("function"),pvString);
}
if(hasTimeStamp) {
fields[ind++] = standardField->timeStamp();
}
if(hasAlarm) {
fields[ind++] = standardField->alarm();
}
fields[ind++] = standardField->scalarArray("label",pvString);
for(int i=0; i<numberValues ; i++) fields[ind++] = valueFields[i];
PVStructure::shared_pointer pvStructure = PVStructure::shared_pointer(
pvDataCreate->createPVStructure(0,"NTTable",nfields,fields));
String label[numberValues];
for(int i=0; i<numberValues; i++) {
FieldConstPtr field = fields[nfields - numberValues +i];
label[i] = field->getFieldName();
}
PVStringArray *pvLabel = static_cast<PVStringArray *>
(pvStructure->getScalarArrayField("label",pvString));
pvLabel->put(0,numberValues,label,0);
return pvStructure;
}
NTTable::NTTable(PVStructure::shared_pointer const & pvStructure)
: pvNTTable(pvStructure),
pvFunction(0),
pvTimeStamp(0),
pvAlarm(0),
pvLabel(0),
offsetFields(1)
{
NTField *ntfield = NTField::get();
String name = pvStructure->getField()->getFieldName();
if(name.compare("NTTable")!=0) {
throw std::invalid_argument(
"pvArgument does not have name NTTable");
}
PVScalarArray * pvScalarArray
= pvStructure->getScalarArrayField("label",pvString);
if(pvScalarArray==0) {
throw std::invalid_argument(
"pvArgument did not have a structureArray field value");
}
pvLabel = static_cast<PVStringArray *>(pvScalarArray);
PVFieldPtr pvField = pvStructure->getSubField("function");
if(pvField!=0) {
pvFunction = pvStructure->getStringField("function");
offsetFields++;
}
pvField = pvStructure->getSubField("timeStamp");
if(pvField!=0 && ntfield->isTimeStamp(pvField->getField())) {
pvTimeStamp = static_cast<PVStructure *>(pvField);
offsetFields++;
}
pvField = pvStructure->getSubField("alarm");
if(pvField!=0 && ntfield->isAlarm(pvField->getField())) {
pvAlarm = static_cast<PVStructure *>(pvField);
offsetFields++;
}
}
NTTable::~NTTable()
{
}
PVString * NTTable::getFunction()
{
return pvFunction;
}
void NTTable::attachTimeStamp(PVTimeStamp &pvTimeStamp)
{
if(this->pvTimeStamp==0) return;
pvTimeStamp.attach(this->pvTimeStamp);
}
void NTTable::attachAlarm(PVAlarm &pvAlarm)
{
if(this->pvAlarm==0) return;
pvAlarm.attach(this->pvAlarm);
}
PVStringArray * NTTable::getLabel()
{
return pvLabel;
}
int NTTable::getNumberValues()
{
return pvLabel->getLength();
}
FieldConstPtr NTTable::getField(int index)
{
return pvNTTable->getStructure()->getFields()[index+offsetFields];
}
PVFieldPtr NTTable::getPVField(int index)
{
return pvNTTable->getPVFields()[index+offsetFields];
}
}}

117
src/nt/nttable.h Normal file
View File

@ -0,0 +1,117 @@
/* 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 <pv/ntfield.h>
namespace epics { namespace pvData {
/**
* Convenience Class for NTTable
* @author mrk
*
*/
class NTTable
{
public:
POINTER_DEFINITIONS(NTTable);
/**
* Is the pvStructure an NTTable.
* @param pvStructure The pvStructure to test.
* @return (false,true) if (is not, is) an NTNameValuePair.
*/
static bool isNTTable(PVStructurePtr pvStructure);
/**
* Create an NTTable pvStructure.
* @param hasFunction Create a PVString field named function.
* @param hasTimeStamp Create a timeStamp structure field.
* @param hasAlarm Create an alarm structure field.
* @param numberValues The number of fields that follow the label field.
* @param valueFields The fields that follow the label field.
* @return an NTTable pvStructure.
*/
static PVStructure::shared_pointer create(
bool hasFunction,bool hasTimeStamp, bool hasAlarm,
int numberValues,
FieldConstPtrArray valueFields);
/**
* Constructor
* @param pvStructure The pvStructure to which to attach.
* @return A NTTable that is attached to the pvStructure
*/
NTTable(PVStructure::shared_pointer const & pvStructure);
/**
* Destructor
*/
~NTTable();
/**
* Get the function field.
* @return The pvString or null if no function field.
*/
PVString *getFunction();
/**
* Attach a pvTimeStamp.
* @param pvTimeStamp The pvTimeStamp that will be attached.
* Does nothing if no timeStamp
*/
void attachTimeStamp(PVTimeStamp &pvTimeStamp);
/**
* Attach an pvAlarm.
* @param pvAlarm The pvAlarm that will be attached.
* Does nothing if no alarm
*/
void attachAlarm(PVAlarm &pvAlarm);
/**
* Get the pvStructure.
* @return PVStructurePtr.
*/
PVStructurePtr getPVStructure(){return pvNTTable.get();}
/**
* Get the timeStamp.
* @return PVStructurePtr which may be null.
*/
PVStructurePtr getTimeStamp(){return pvTimeStamp;}
/**
* Get the alarm.
* @return PVStructurePtr which may be null.
*/
PVStructurePtr getAlarm() {return pvAlarm;}
/**
* Get the label field.
* @return The pvStringArray for the label.
*/
PVStringArray *getLabel();
/**
* Get the the number of fields that follow the label field.
* @return The number of fields.
*/
int getNumberValues();
/**
* Get the Field for a field that follows the label field.
* @param index The index of the field desired.
* @return The FieldConstPtr for the field.
*/
FieldConstPtr getField(int index);
/**
* Get the PVField for a field that follows the label field.
* @param index The index of the field desired.
* @return The PVFieldPtr for the field.
*/
PVFieldPtr getPVField(int index);
private:
PVStructure::shared_pointer pvNTTable;
PVString *pvFunction;
PVStructurePtr pvTimeStamp;
PVStructurePtr pvAlarm;
PVStringArray *pvLabel;
int offsetFields;
};
}}
#endif /* NTTABLE_H */

5
test/Makefile Normal file
View File

@ -0,0 +1,5 @@
TOP = ..
include $(TOP)/configure/CONFIG
DIRS += nt
include $(TOP)/configure/RULES_DIRS

20
test/nt/Makefile Normal file
View File

@ -0,0 +1,20 @@
TOP=../..
include $(TOP)/configure/CONFIG
PROD_HOST += ntfieldTest
ntfieldTest_SRCS += ntfieldTest.cpp
ntfieldTest_LIBS += nt pvData Com
PROD_HOST += ntnameValueTest
ntnameValueTest_SRCS += ntnameValueTest.cpp
ntnameValueTest_LIBS += nt pvData Com
PROD_HOST += nttableTest
nttableTest_SRCS += nttableTest.cpp
nttableTest_LIBS += nt pvData Com
include $(TOP)/configure/RULES
#----------------------------------------
# ADD RULES AFTER THIS LINE

176
test/nt/ntfieldTest.cpp Normal file
View File

@ -0,0 +1,176 @@
/**
* 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.
*/
/*
* ntfieldTest.cpp
*
* Created on: 2011.11
* Author: Marty Kraimer
*/
#include <cstddef>
#include <cstdlib>
#include <cstddef>
#include <string>
#include <cstring>
#include <cstdio>
#include <ctime>
#include <list>
#include <epicsAssert.h>
#include <pv/nt.h>
#include <epicsExit.h>
#include <pv/CDRMonitor.h>
using namespace epics::pvData;
static FieldCreate * fieldCreate = 0;
static PVDataCreate * pvDataCreate = 0;
static StandardField *standardField = 0;
static StandardPVField *standardPVField = 0;
static NTField *ntField = 0;
static PVNTField *pvntField = 0;
static String builder("");
static void testNTField(FILE * fd)
{
StructureConstPtr structureConstPtr = ntField->createEnumerated("value");
builder.clear();
structureConstPtr->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
assert(ntField->isEnumerated(structureConstPtr));
structureConstPtr = ntField->createTimeStamp();
builder.clear();
structureConstPtr->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
assert(ntField->isTimeStamp(structureConstPtr));
structureConstPtr = ntField->createAlarm();
builder.clear();
structureConstPtr->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
assert(ntField->isAlarm(structureConstPtr));
structureConstPtr = ntField->createDisplay();
builder.clear();
structureConstPtr->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
assert(ntField->isDisplay(structureConstPtr));
structureConstPtr = ntField->createAlarmLimit();
builder.clear();
structureConstPtr->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
assert(ntField->isAlarmLimit(structureConstPtr));
structureConstPtr = ntField->createControl();
builder.clear();
structureConstPtr->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
assert(ntField->isControl(structureConstPtr));
StructureArrayConstPtr structureArrayConstPtr
= ntField->createEnumeratedArray("value");
builder.clear();
structureArrayConstPtr->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
structureArrayConstPtr = ntField->createTimeStampArray("value");
builder.clear();
structureArrayConstPtr->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
structureArrayConstPtr = ntField->createAlarmArray("value");
builder.clear();
structureArrayConstPtr->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
}
static void testPVNTField(FILE * fd)
{
String choices[] = {"one","two","three"};
PVStructure::shared_pointer pvStructure = PVStructure::shared_pointer(
pvntField->createEnumerated(0,"enumerated",choices, 3));
builder.clear();
pvStructure->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
assert(ntField->isEnumerated(pvStructure->getStructure()));
pvStructure = PVStructure::shared_pointer(pvntField->createTimeStamp(0));
builder.clear();
pvStructure->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
assert(ntField->isTimeStamp(pvStructure->getStructure()));
pvStructure = PVStructure::shared_pointer(pvntField->createAlarm(0));
builder.clear();
pvStructure->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
assert(ntField->isAlarm(pvStructure->getStructure()));
pvStructure = PVStructure::shared_pointer(pvntField->createDisplay(0));
builder.clear();
pvStructure->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
assert(ntField->isDisplay(pvStructure->getStructure()));
pvStructure = PVStructure::shared_pointer(pvntField->createAlarmLimit(0));
builder.clear();
pvStructure->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
assert(ntField->isAlarmLimit(pvStructure->getStructure()));
PVStructureArray::shared_pointer pvStructureArray = PVStructureArray::shared_pointer(
pvntField->createEnumeratedArray(0,"enumArray"));
builder.clear();
pvStructureArray->toString(&builder);
fprintf(fd,"\n%s\n",builder.c_str());
builder.clear();
pvStructureArray->getStructureArray()->getStructure()->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
pvStructureArray = PVStructureArray::shared_pointer(
pvntField->createTimeStampArray(0,"timeStampArray"));
builder.clear();
pvStructureArray->toString(&builder);
fprintf(fd,"\n%s\n",builder.c_str());
builder.clear();
pvStructureArray->getStructureArray()->getStructure()->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
pvStructureArray = PVStructureArray::shared_pointer(
pvntField->createAlarmArray(0,"alarmArray"));
builder.clear();
pvStructureArray->toString(&builder);
fprintf(fd,"\n%s\n",builder.c_str());
builder.clear();
pvStructureArray->getStructureArray()->getStructure()->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
}
int main(int argc,char *argv[])
{
char *fileName = 0;
if(argc>1) fileName = argv[1];
FILE * fd = stdout;
if(fileName!=0 && fileName[0]!=0) {
fd = fopen(fileName,"w+");
}
fieldCreate = getFieldCreate();
pvDataCreate = getPVDataCreate();
standardField = getStandardField();
standardPVField = getStandardPVField();
ntField = NTField::get();
pvntField = PVNTField::get();
testNTField(fd);
testPVNTField(fd);
epicsExitCallAtExits();
CDRMonitor::get().show(fd,true);
return(0);
}

View File

@ -0,0 +1,92 @@
/**
* 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.
*/
/*
* ntnameValueTest.cpp
*
* Created on: 2011.11
* Author: Marty Kraimer
*/
#include <cstddef>
#include <cstdlib>
#include <cstddef>
#include <string>
#include <cstring>
#include <cstdio>
#include <ctime>
#include <list>
#include <epicsAssert.h>
#include <pv/nt.h>
#include <epicsExit.h>
#include <pv/CDRMonitor.h>
using namespace epics::pvData;
static PVDataCreate * pvDataCreate = 0;
static NTField *ntField = 0;
static PVNTField *pvntField = 0;
static String builder("");
static void test(FILE * fd)
{
PVStructure::shared_pointer pvStructure = NTNameValue::create(true,true,true);
builder.clear();
pvStructure->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
builder.clear();
pvStructure->getStructure()->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
NTNameValue ntNameValue(pvStructure);
PVStringArray *names = ntNameValue.getNames();
PVStringArray *values = ntNameValue.getValues();
int n = 2;
String name[] = {String("name 0"),String("name 1")};
String value[] = {String("value 0"),String("value 1")};
names->put(0,n,name,0);
values->put(0,n,value,0);
PVString *function = ntNameValue.getFunction();
function->put("test");
PVAlarm pvAlarm;
ntNameValue.attachAlarm(pvAlarm);
Alarm alarm;
alarm.setMessage("test alarm");
alarm.setSeverity(majorAlarm);
alarm.setStatus(clientStatus);
pvAlarm.set(alarm);
PVTimeStamp pvTimeStamp;
ntNameValue.attachTimeStamp(pvTimeStamp);
TimeStamp timeStamp(1000,1000,10);
pvTimeStamp.set(timeStamp);
builder.clear();
pvStructure->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
assert(NTNameValue::isNTNameValue(pvStructure.get()));
NTNameValue::shared_pointer pntNameValue
= NTNameValue::shared_pointer(new NTNameValue(pvStructure));
}
int main(int argc,char *argv[])
{
char *fileName = 0;
if(argc>1) fileName = argv[1];
FILE * fd = stdout;
if(fileName!=0 && fileName[0]!=0) {
fd = fopen(fileName,"w+");
}
pvDataCreate = getPVDataCreate();
ntField = NTField::get();
pvntField = PVNTField::get();
test(fd);
epicsExitCallAtExits();
CDRMonitor::get().show(fd,true);
return(0);
}

114
test/nt/nttableTest.cpp Normal file
View File

@ -0,0 +1,114 @@
/**
* 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.
*/
/*
* nttableTest.cpp
*
* Created on: 2011.11
* Author: Marty Kraimer
*/
#include <cstddef>
#include <cstdlib>
#include <cstddef>
#include <string>
#include <cstring>
#include <cstdio>
#include <ctime>
#include <list>
#include <epicsAssert.h>
#include <pv/nt.h>
#include <epicsExit.h>
#include <pv/CDRMonitor.h>
using namespace epics::pvData;
static FieldCreate * fieldCreate = 0;
static PVDataCreate * pvDataCreate = 0;
static NTField *ntField = 0;
static PVNTField *pvntField = 0;
static String builder("");
static void test(FILE * fd)
{
int n = 2;
FieldConstPtr fields[2];
fields[0] = fieldCreate->createScalarArray("position",pvDouble);
fields[1] = ntField->createAlarmArray("alarms");
PVStructure::shared_pointer pvStructure = NTTable::create(
true,true,true,n,fields);
builder.clear();
pvStructure->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
builder.clear();
pvStructure->getStructure()->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
NTTable ntTable(pvStructure);
PVDoubleArray *pvPositions
= static_cast<PVDoubleArray *>(ntTable.getPVField(0));
double positions[2];
positions[0] = 1.0;
positions[1] = 2.0;
pvPositions->put(0,n,positions,0);
PVStructureArray *pvAlarms
= static_cast<PVStructureArray *>(ntTable.getPVField(1));
PVAlarm pvAlarm;
Alarm alarm;
PVStructurePtr palarms[n];
for(int i=0; i<n; i++) {
palarms[i] = pvntField->createAlarm(0);
pvAlarm.attach(palarms[i]);
alarm.setMessage("test");
alarm.setSeverity(majorAlarm);
alarm.setStatus(clientStatus);
pvAlarm.set(alarm);
}
pvAlarms->put(0,n,palarms,0);
String labels[n];
labels[0] = pvPositions->getField()->getFieldName();
labels[1] = pvAlarms->getField()->getFieldName();
PVStringArray *label = ntTable.getLabel();
label->put(0,n,labels,0);
PVString *function = ntTable.getFunction();
function->put("test");
ntTable.attachAlarm(pvAlarm);
alarm.setMessage("test alarm");
alarm.setSeverity(majorAlarm);
alarm.setStatus(clientStatus);
pvAlarm.set(alarm);
PVTimeStamp pvTimeStamp;
ntTable.attachTimeStamp(pvTimeStamp);
TimeStamp timeStamp(1000,1000,10);
pvTimeStamp.set(timeStamp);
builder.clear();
pvStructure->toString(&builder);
fprintf(fd,"%s\n",builder.c_str());
assert(NTTable::isNTTable(pvStructure.get()));
}
int main(int argc,char *argv[])
{
char *fileName = 0;
if(argc>1) fileName = argv[1];
FILE * fd = stdout;
if(fileName!=0 && fileName[0]!=0) {
fd = fopen(fileName,"w+");
}
fieldCreate = getFieldCreate();
pvDataCreate = getPVDataCreate();
ntField = NTField::get();
pvntField = PVNTField::get();
test(fd);
epicsExitCallAtExits();
CDRMonitor::get().show(fd,true);
return(0);
}