2) implemented Lock. See effective C++ item 14.
This is as easy to use as Java synchronize.
3) wrapper on top of std::string. All usage of string in pvData is one of:
String - Just a std::string
StringBuilder - Used where StringBuilder is used in Java
StringConst - Just a "std::string const". This is used wherever String is used in Java
StringConstArray - Just like a String[] in Java.
4) The reference counting (incReferenceCount and decReferenceCount) are now private. It is completely handled by the implenentaion.
NO code that uses pvData needs even know about reference counting.
64 lines
1.8 KiB
C++
64 lines
1.8 KiB
C++
/* pvDataMain.cpp */
|
|
/* Author: Marty Kraimer Date: 17MAR2000 */
|
|
|
|
#include <stddef.h>
|
|
#include <stdlib.h>
|
|
#include <stddef.h>
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
|
|
#include "pvData.h"
|
|
|
|
using namespace epics::pvData;
|
|
|
|
static FieldCreate * pfieldCreate = 0;
|
|
static PVDataCreate *pvDataCreate = 0;
|
|
static String buffer("");
|
|
|
|
void testDouble() {
|
|
printf("\ntestDouble\n");
|
|
StringConst valueName("value");
|
|
ScalarConstPtr pscalar = pfieldCreate->createScalar(valueName,pvDouble);
|
|
PVScalar *pvScalar = pvDataCreate->createPVScalar(0,pscalar);
|
|
PVDouble *pvValue = (PVDouble *)pvScalar;
|
|
double value = 2;
|
|
pvValue->put(value);
|
|
double getValue = pvValue->get();
|
|
printf("put %lf get %lf\n",value,getValue);
|
|
if(value!=getValue) {
|
|
fprintf(stderr,"ERROR getValue put %f get %f\n",value,getValue);
|
|
}
|
|
FieldConstPtr field = pvValue->getField();
|
|
buffer.clear();
|
|
field->toString(&buffer);
|
|
printf("%s\n",buffer.c_str());
|
|
epicsBoolean isImmutable = pvValue->isImmutable();
|
|
PVStructure *pvParent = pvValue->getParent();
|
|
printf("immutable %s parent %p\n",
|
|
((isImmutable==epicsFalse) ? "false" : "true"),
|
|
pvParent);
|
|
int offset = pvValue->getFieldOffset();
|
|
int nextOffset = pvValue->getNextFieldOffset();
|
|
int numberFields = pvValue->getNumberFields();
|
|
printf("offset %d nextOffset %d numberFields %d\n",
|
|
offset,nextOffset,numberFields);
|
|
ScalarConstPtr scalar = dynamic_cast<ScalarConstPtr>(field);
|
|
if(scalar!=field) {
|
|
fprintf(stderr,"ERROR field!=scalar field %p scalar %p\n",field,scalar);
|
|
}
|
|
buffer.clear();
|
|
buffer += "value ";
|
|
pvValue->toString(&buffer);
|
|
printf("%s\n",buffer.c_str());
|
|
delete pvValue;
|
|
}
|
|
|
|
int main(int argc,char *argv[])
|
|
{
|
|
pfieldCreate = getFieldCreate();
|
|
pvDataCreate = getPVDataCreate();
|
|
testDouble();
|
|
return(0);
|
|
}
|
|
|