get rid of all static global objects

This commit is contained in:
Marty Kraimer
2012-10-03 08:59:23 -04:00
parent ced439f4c4
commit 5ba0209f39
23 changed files with 202 additions and 140 deletions

View File

@@ -22,14 +22,12 @@ using std::size_t;
namespace epics { namespace pvData {
static PVDataCreatePtr pvDataCreate;
static String trueString("true");
static String falseString("false");
static String logicError("Logic error. Should never get here.");
static String illegalScalarType("Illegal ScalarType");
static ConvertPtr convert;
static void newLineImpl(StringBuilder buffer, int indentLevel)
{
*buffer += "\n";
for(int i=0; i<indentLevel; i++) *buffer += " ";
}
template<typename T>
T toScalar(PVScalarPtr const &pv)
@@ -82,7 +80,7 @@ T toScalar(PVScalarPtr const &pv)
case pvString:
throw std::logic_error(String("string can not be converted to byte"));
}
throw std::logic_error(logicError);
throw std::logic_error("Logic error. Should never get here.");
}
int8 Convert::toByte(PVScalarPtr const & pv)
@@ -278,7 +276,7 @@ void fromScalar(PVScalarPtr const &pv,T from)
return;
}
}
throw std::logic_error(logicError);
throw std::logic_error("Logic error. Should never get here.");
}
void Convert::fromByte(PVScalarPtr const &pv,int8 from)
@@ -412,7 +410,14 @@ static std::vector<String> split(String commaSeparatedList) {
return valueList;
}
Convert::Convert(){}
Convert::Convert()
: pvDataCreate(getPVDataCreate()),
trueString("true"),
falseString("false"),
illegalScalarType("Illegal ScalarType")
{}
Convert::~Convert(){}
@@ -1151,7 +1156,7 @@ String Convert::toString(PVScalarPtr const & pv)
return value->get();
}
}
throw std::logic_error(logicError);
throw std::logic_error("Logic error. Should never get here.");
}
size_t Convert::toByteArray(PVScalarArrayPtr const &pv, size_t offset, size_t length,
@@ -1336,8 +1341,7 @@ size_t Convert::fromDoubleArray(PVScalarArrayPtr &pv, size_t offset, size_t leng
void Convert::newLine(StringBuilder buffer, int indentLevel)
{
*buffer += "\n";
for(int i=0; i<indentLevel; i++) *buffer += " ";
newLineImpl(buffer,indentLevel);
}
static bool scalarEquals(PVScalar *a,PVScalar *b)
@@ -2388,7 +2392,7 @@ size_t convertToStringArray(PVScalarArray *pv,
if (pvdata->get(offset + i, 1, data) == 1) {
BooleanArray dataArray = data.data;
bool value = dataArray[data.offset];
to[toOffset + i] = value ? trueString : falseString;
to[toOffset + i] = value ? "true" : "false";
} else {
to[toOffset + i] = "bad pv";
}
@@ -2710,7 +2714,7 @@ void convertStructure(StringBuilder buffer,PVStructure const *data,int indentLev
if (fieldsData.size() != 0) {
int length = data->getStructure()->getNumberFields();
for(int i=0; i<length; i++) {
convert->newLine(buffer, indentLevel+1);
newLineImpl(buffer, indentLevel+1);
PVFieldPtr fieldField = fieldsData[i];
fieldField->toString(buffer,indentLevel + 1);
}
@@ -2976,7 +2980,7 @@ void convertStructureArray(StringBuilder buffer,
StructureArrayData data = StructureArrayData();
pvdata->get(0, length, data);
for (size_t i = 0; i < length; i++) {
convert->newLine(buffer, indentLevel + 1);
newLineImpl(buffer, indentLevel + 1);
PVStructurePtr pvStructure = data.data[i];
if (pvStructure.get() == 0) {
*buffer += "null";
@@ -3314,12 +3318,12 @@ size_t copyNumericArray(PVScalarArray *from, size_t offset, PVScalarArray *to, s
ConvertPtr Convert::getConvert()
{
static ConvertPtr convert;
static Mutex mutex;
Lock xx(mutex);
if(convert.get()==0) {
convert = ConvertPtr(new Convert());
pvDataCreate = getPVDataCreate();
}
return convert;
}

View File

@@ -74,7 +74,10 @@ void Scalar::toString(StringBuilder buffer,int indentLevel) const{
*buffer += getID();
}
static const String idScalarLUT[] = {
String Scalar::getID() const
{
static const String idScalarLUT[] = {
"boolean", // pvBoolean
"byte", // pvByte
"short", // pvShort
@@ -87,31 +90,33 @@ static const String idScalarLUT[] = {
"float", // pvFloat
"double", // pvDouble
"string" // pvString
};
String Scalar::getID() const
{
};
return idScalarLUT[scalarType];
}
static const int8 typeCodeLUT[] = {
0x00, // pvBoolean
0x20, // pvByte
0x21, // pvShort
0x22, // pvInt
0x23, // pvLong
0x28, // pvUByte
0x29, // pvUShort
0x2A, // pvUInt
0x2B, // pvULong
0x42, // pvFloat
0x43, // pvDouble
0x60 // pvString
};
const int8 Scalar::getTypeCodeLUT() const
{
static const int8 typeCodeLUT[] = {
0x00, // pvBoolean
0x20, // pvByte
0x21, // pvShort
0x22, // pvInt
0x23, // pvLong
0x28, // pvUByte
0x29, // pvUShort
0x2A, // pvUInt
0x2B, // pvULong
0x42, // pvFloat
0x43, // pvDouble
0x60 // pvString
};
return typeCodeLUT[scalarType];
}
void Scalar::serialize(ByteBuffer *buffer, SerializableControl *control) const {
control->ensureBuffer(1);
buffer->putByte(typeCodeLUT[scalarType]);
buffer->putByte(getTypeCodeLUT());
}
void Scalar::deserialize(ByteBuffer *buffer, DeserializableControl *control) {
@@ -153,7 +158,28 @@ ScalarArray::ScalarArray(ScalarType elementType)
ScalarArray::~ScalarArray() {}
static const String idScalarArrayLUT[] = {
const int8 ScalarArray::getTypeCodeLUT() const
{
static const int8 typeCodeLUT[] = {
0x00, // pvBoolean
0x20, // pvByte
0x21, // pvShort
0x22, // pvInt
0x23, // pvLong
0x28, // pvUByte
0x29, // pvUShort
0x2A, // pvUInt
0x2B, // pvULong
0x42, // pvFloat
0x43, // pvDouble
0x60 // pvString
};
return typeCodeLUT[elementType];
}
const String ScalarArray::getIDScalarArrayLUT() const
{
static const String idScalarArrayLUT[] = {
"boolean[]", // pvBoolean
"byte[]", // pvByte
"short[]", // pvShort
@@ -166,11 +192,13 @@ static const String idScalarArrayLUT[] = {
"float[]", // pvFloat
"double[]", // pvDouble
"string[]" // pvString
};
};
return idScalarArrayLUT[elementType];
}
String ScalarArray::getID() const
{
return idScalarArrayLUT[elementType];
return getIDScalarArrayLUT();
}
void ScalarArray::toString(StringBuilder buffer,int indentLevel) const{
@@ -179,7 +207,7 @@ void ScalarArray::toString(StringBuilder buffer,int indentLevel) const{
void ScalarArray::serialize(ByteBuffer *buffer, SerializableControl *control) const {
control->ensureBuffer(1);
buffer->putByte(0x10 | typeCodeLUT[elementType]);
buffer->putByte(0x10 | getTypeCodeLUT());
}
void ScalarArray::deserialize(ByteBuffer *buffer, DeserializableControl *control) {
@@ -398,51 +426,47 @@ StructureConstPtr FieldCreate::appendFields(
}
static const int integerLUT[] =
{
pvByte, // 8-bits
pvShort, // 16-bits
pvInt, // 32-bits
pvLong, // 64-bits
-1,
-1,
-1,
-1,
pvUByte, // unsigned 8-bits
pvUShort, // unsigned 16-bits
pvUInt, // unsigned 32-bits
pvULong, // unsigned 64-bits
-1,
-1,
-1,
-1
};
static const int floatLUT[] =
{
-1, // reserved
-1, // 16-bits
pvFloat, // 32-bits
pvDouble, // 64-bits
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1
};
static int decodeScalar(int8 code)
{
static const int integerLUT[] =
{
pvByte, // 8-bits
pvShort, // 16-bits
pvInt, // 32-bits
pvLong, // 64-bits
-1,
-1,
-1,
-1,
pvUByte, // unsigned 8-bits
pvUShort, // unsigned 16-bits
pvUInt, // unsigned 32-bits
pvULong, // unsigned 64-bits
-1,
-1,
-1,
-1
};
static const int floatLUT[] =
{
-1, // reserved
-1, // 16-bits
pvFloat, // 32-bits
pvDouble, // 64-bits
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1
};
// bits 7-5
switch (code >> 5)
{

View File

@@ -19,8 +19,6 @@
namespace epics { namespace pvData {
static PVScalarPtr nullPVScalar;
PVAuxInfo::PVAuxInfo(PVField * pvField)
: pvField(pvField),

View File

@@ -27,8 +27,6 @@ using std::min;
namespace epics { namespace pvData {
static ConvertPtr convert = getConvert();
static FieldCreatePtr fieldCreate = getFieldCreate();
/** Default storage for scalar values
*/
@@ -455,7 +453,9 @@ typedef DefaultPVArray<String> BasePVStringArray;
// Factory
PVDataCreate::PVDataCreate(){ }
PVDataCreate::PVDataCreate()
: fieldCreate(getFieldCreate())
{ }
PVFieldPtr PVDataCreate::createPVField(FieldConstPtr const & field)
{
@@ -509,7 +509,7 @@ PVFieldPtr PVDataCreate::createPVField(PVFieldPtr const & fieldToClone)
StructureArrayConstPtr structureArray = from->getStructureArray();
PVStructureArrayPtr to = createPVStructureArray(
structureArray);
convert->copyStructureArray(from, to);
getConvert()->copyStructureArray(from, to);
return to;
}
}
@@ -559,7 +559,7 @@ PVScalarPtr PVDataCreate::createPVScalar(PVScalarPtr const & scalarToClone)
{
ScalarType scalarType = scalarToClone->getScalar()->getScalarType();
PVScalarPtr pvScalar = createPVScalar(scalarType);
convert->copyScalar(scalarToClone, pvScalar);
getConvert()->copyScalar(scalarToClone, pvScalar);
PVAuxInfoPtr from = scalarToClone->getPVAuxInfo();
PVAuxInfoPtr to = pvScalar->getPVAuxInfo();
PVAuxInfo::PVInfoMap & map = from->getInfoMap();
@@ -568,7 +568,7 @@ PVScalarPtr PVDataCreate::createPVScalar(PVScalarPtr const & scalarToClone)
PVScalarPtr pvFrom = iter->second;
ScalarConstPtr scalar = pvFrom->getScalar();
PVScalarPtr pvTo = to->createInfo(key,scalar->getScalarType());
convert->copyScalar(pvFrom,pvTo);
getConvert()->copyScalar(pvFrom,pvTo);
}
return pvScalar;
}
@@ -618,7 +618,7 @@ PVScalarArrayPtr PVDataCreate::createPVScalarArray(
{
PVScalarArrayPtr pvArray = createPVScalarArray(
arrayToClone->getScalarArray()->getElementType());
convert->copyScalarArray(arrayToClone,0, pvArray,0,arrayToClone->getLength());
getConvert()->copyScalarArray(arrayToClone,0, pvArray,0,arrayToClone->getLength());
PVAuxInfoPtr from = arrayToClone->getPVAuxInfo();
PVAuxInfoPtr to = pvArray->getPVAuxInfo();
PVAuxInfo::PVInfoMap & map = from->getInfoMap();
@@ -627,7 +627,7 @@ PVScalarArrayPtr PVDataCreate::createPVScalarArray(
PVScalarPtr pvFrom = iter->second;
ScalarConstPtr scalar = pvFrom->getScalar();
PVScalarPtr pvTo = to->createInfo(key,scalar->getScalarType());
convert->copyScalar(pvFrom,pvTo);
getConvert()->copyScalar(pvFrom,pvTo);
}
return pvArray;
}
@@ -666,7 +666,7 @@ PVStructurePtr PVDataCreate::createPVStructure(PVStructurePtr const & structToCl
}
StructureConstPtr structure = structToClone->getStructure();
PVStructurePtr pvStructure(new PVStructure(structure));
convert->copyStructure(structToClone,pvStructure);
getConvert()->copyStructure(structToClone,pvStructure);
return pvStructure;
}

View File

@@ -21,11 +21,10 @@ using std::size_t;
namespace epics { namespace pvData {
static String notImplemented("not implemented");
PVField::PVField(FieldConstPtr field)
: parent(NULL),field(field),
: notImplemented("not implemented"),
parent(NULL),field(field),
fieldOffset(0), nextFieldOffset(0),
immutable(false),
convert(getConvert())

View File

@@ -23,22 +23,22 @@ using std::size_t;
namespace epics { namespace pvData {
static PVFieldPtr nullPVField;
static PVBooleanPtr nullPVBoolean;
static PVBytePtr nullPVByte;
static PVShortPtr nullPVShort;
static PVIntPtr nullPVInt;
static PVLongPtr nullPVLong;
static PVUBytePtr nullPVUByte;
static PVUShortPtr nullPVUShort;
static PVUIntPtr nullPVUInt;
static PVULongPtr nullPVULong;
static PVFloatPtr nullPVFloat;
static PVDoublePtr nullPVDouble;
static PVStringPtr nullPVString;
static PVStructurePtr nullPVStructure;
static PVStructureArrayPtr nullPVStructureArray;
static PVScalarArrayPtr nullPVScalarArray;
PVFieldPtr PVStructure::nullPVField;
PVBooleanPtr PVStructure::nullPVBoolean;
PVBytePtr PVStructure::nullPVByte;
PVShortPtr PVStructure::nullPVShort;
PVIntPtr PVStructure::nullPVInt;
PVLongPtr PVStructure::nullPVLong;
PVUBytePtr PVStructure::nullPVUByte;
PVUShortPtr PVStructure::nullPVUShort;
PVUIntPtr PVStructure::nullPVUInt;
PVULongPtr PVStructure::nullPVULong;
PVFloatPtr PVStructure::nullPVFloat;
PVDoublePtr PVStructure::nullPVDouble;
PVStringPtr PVStructure::nullPVString;
PVStructurePtr PVStructure::nullPVStructure;
PVStructureArrayPtr PVStructure::nullPVStructureArray;
PVScalarArrayPtr PVStructure::nullPVScalarArray;
static PVFieldPtr findSubField(
String const &fieldName,
@@ -649,7 +649,7 @@ static PVFieldPtr findSubField(
String const & fieldName,
PVStructure const *pvStructure)
{
if( fieldName.length()<1) return nullPVField;
if( fieldName.length()<1) return PVFieldPtr();
String::size_type index = fieldName.find('.');
String name = fieldName;
String restOfName = String();
@@ -667,13 +667,13 @@ static PVFieldPtr findSubField(
size_t result = pvField->getFieldName().compare(name);
if(result==0) {
if(restOfName.length()==0) return pvFields[i];
if(pvField->getField()->getType()!=structure) return nullPVField;
if(pvField->getField()->getType()!=structure) return PVFieldPtr();
PVStructurePtr pvStructure =
std::tr1::static_pointer_cast<PVStructure>(pvField);
return findSubField(restOfName,pvStructure.get());
}
}
return nullPVField;
return PVFieldPtr();
}
}}

View File

@@ -20,14 +20,12 @@
namespace epics { namespace pvData {
static StandardFieldPtr standardField;
static FieldCreatePtr fieldCreate;
static PVDataCreatePtr pvDataCreate;
static String notImplemented("not implemented");
StandardPVField::StandardPVField(){}
StandardPVField::StandardPVField()
: standardField(getStandardField()),
fieldCreate(getFieldCreate()),
pvDataCreate(getPVDataCreate()),
notImplemented("not implemented")
{}
StandardPVField::~StandardPVField(){}
@@ -91,9 +89,6 @@ StandardPVFieldPtr StandardPVField::getStandardPVField()
Lock xx(mutex);
if(standardPVField.get()==NULL) {
standardField = getStandardField();
fieldCreate = getFieldCreate();
pvDataCreate = getPVDataCreate();
standardPVField= StandardPVFieldPtr(new StandardPVField());
}
return standardPVField;

View File

@@ -26,7 +26,6 @@
namespace epics { namespace pvData {
static String alreadyOn("already on list");
Event::~Event() {
epicsEventDestroy(id);
@@ -35,7 +34,8 @@ Event::~Event() {
Event::Event(bool full)
: id(epicsEventCreate(full?epicsEventFull : epicsEventEmpty))
: id(epicsEventCreate(full?epicsEventFull : epicsEventEmpty)),
alreadyOn("already on list")
{
}

View File

@@ -31,6 +31,7 @@ public:
bool tryWait (); /* false if empty */
private:
epicsEventId id;
String alreadyOn;
};
}}

View File

@@ -17,8 +17,8 @@ namespace epics { namespace pvData {
using std::tr1::static_pointer_cast;
static String noAlarmFound("No alarm structure found");
static String notAttached("Not attached to an alarm structure");
String PVAlarm::noAlarmFound("No alarm structure found");
String PVAlarm::notAttached("Not attached to an alarm structure");
bool PVAlarm::attach(PVFieldPtr const & pvField)
{

View File

@@ -33,6 +33,8 @@ private:
PVIntPtr pvSeverity;
PVIntPtr pvStatus;
PVStringPtr pvMessage;
static String noAlarmFound;
static String notAttached;
};
}}

View File

@@ -17,8 +17,8 @@ namespace epics { namespace pvData {
using std::tr1::static_pointer_cast;
static String noControlFound("No control structure found");
static String notAttached("Not attached to an control structure");
String PVControl::noControlFound("No control structure found");
String PVControl::notAttached("Not attached to an control structure");
bool PVControl::attach(PVFieldPtr const & pvField)
{

View File

@@ -29,6 +29,8 @@ public:
private:
PVDoublePtr pvLow;
PVDoublePtr pvHigh;
static String noControlFound;
static String notAttached;
};
}}

View File

@@ -17,8 +17,8 @@ namespace epics { namespace pvData {
using std::tr1::static_pointer_cast;
static String noDisplayFound("No display structure found");
static String notAttached("Not attached to an display structure");
String PVDisplay::noDisplayFound("No display structure found");
String PVDisplay::notAttached("Not attached to an display structure");
bool PVDisplay::attach(PVFieldPtr const & pvField)
{

View File

@@ -28,6 +28,8 @@ public:
void get(Display &) const;
bool set(Display const & display);
private:
static String noDisplayFound;
static String notAttached;
PVStringPtr pvDescription;
PVStringPtr pvFormat;
PVStringPtr pvUnits;

View File

@@ -17,8 +17,8 @@ namespace epics { namespace pvData {
using std::tr1::static_pointer_cast;
static String notFound("No enumerated structure found");
static String notAttached("Not attached to an enumerated structure");
String PVEnumerated::notFound("No enumerated structure found");
String PVEnumerated::notAttached("Not attached to an enumerated structure");
bool PVEnumerated::attach(PVFieldPtr const & pvField)
{

View File

@@ -34,6 +34,8 @@ public:
int32 getNumberChoices();
bool setChoices(StringArray & choices);
private:
static String notFound;
static String notAttached;
PVIntPtr pvIndex;
PVStringArrayPtr pvChoices;
};

View File

@@ -17,8 +17,8 @@ namespace epics { namespace pvData {
using std::tr1::static_pointer_cast;
static String noTimeStamp("No timeStamp structure found");
static String notAttached("Not attached to a timeStamp structure");
String PVTimeStamp::noTimeStamp("No timeStamp structure found");
String PVTimeStamp::notAttached("Not attached to a timeStamp structure");
bool PVTimeStamp::attach(PVFieldPtr const & pvField)
{

View File

@@ -31,6 +31,8 @@ public:
void get(TimeStamp &) const;
bool set(TimeStamp const & timeStamp);
private:
static String noTimeStamp;
static String notAttached;
PVLongPtr pvSecs;
PVIntPtr pvUserTag;
PVIntPtr pvNano;

View File

@@ -756,6 +756,10 @@ public:
void newLine(StringBuilder buf, int indentLevel);
private:
Convert();
PVDataCreatePtr pvDataCreate;
String trueString;
String falseString;
String illegalScalarType;
};
extern ConvertPtr getConvert();

View File

@@ -131,6 +131,7 @@ public:
*/
void toString(StringBuilder buf,int indentLevel);
private:
PVScalarPtr nullPVScalar;
PVField * pvField;
PVInfoMap pvInfos;
friend class PVDataCreate;
@@ -289,6 +290,7 @@ private:
void message(String message,MessageType messageType,String fullFieldName);
static void computeOffset(const PVField *pvField);
static void computeOffset(const PVField *pvField,std::size_t offset);
String notImplemented;
PVAuxInfoPtr pvAuxInfo;
String fieldName;
PVStructure *parent;
@@ -814,6 +816,23 @@ public:
*/
PVStructure(StructureConstPtr const & structure,PVFieldPtrArray const & pvFields);
private:
static PVFieldPtr nullPVField;
static PVBooleanPtr nullPVBoolean;
static PVBytePtr nullPVByte;
static PVShortPtr nullPVShort;
static PVIntPtr nullPVInt;
static PVLongPtr nullPVLong;
static PVUBytePtr nullPVUByte;
static PVUShortPtr nullPVUShort;
static PVUIntPtr nullPVUInt;
static PVULongPtr nullPVULong;
static PVFloatPtr nullPVFloat;
static PVDoublePtr nullPVDouble;
static PVStringPtr nullPVString;
static PVStructurePtr nullPVStructure;
static PVStructureArrayPtr nullPVStructureArray;
static PVScalarArrayPtr nullPVScalarArray;
PVFieldPtrArray pvFields;
StructureConstPtr structurePtr;
String extendsStructureName;
@@ -1051,6 +1070,7 @@ public:
PVStructurePtr createPVStructure(PVStructurePtr const & structToClone);
private:
PVDataCreate();
FieldCreatePtr fieldCreate;
};
/**

View File

@@ -283,6 +283,7 @@ public:
protected:
Scalar(ScalarType scalarType);
private:
const int8 getTypeCodeLUT() const;
ScalarType scalarType;
friend class FieldCreate;
};
@@ -329,6 +330,8 @@ protected:
*/
virtual ~ScalarArray();
private:
const int8 getTypeCodeLUT() const;
const String getIDScalarArrayLUT() const;
ScalarType elementType;
friend class FieldCreate;
};

View File

@@ -41,6 +41,10 @@ public:
PVStructurePtr enumerated(StringArray const &choices, String const & properties);
private:
StandardPVField();
StandardFieldPtr standardField;
FieldCreatePtr fieldCreate;
PVDataCreatePtr pvDataCreate;
String notImplemented;
};
extern StandardPVFieldPtr getStandardPVField();