String -> std::string, toString methods removed

This commit is contained in:
Matej Sekoranja
2014-06-19 14:27:48 +02:00
parent 6ec207141f
commit c6eed12139
82 changed files with 1606 additions and 1651 deletions
+29 -29
View File
@@ -63,12 +63,12 @@ static inline bool operator!=(const UnionArray& a, const UnionArray& b)
* pvUByte, pvUShort, pvUInt, pvULong,
* pvFloat, or pvDouble.</p>
*
* <p>getString converts any supported type to a String.
* <p>getString converts any supported type to a std::string.
* Code that implements a PVField interface should implement
* method toString by calling this method.</p>
*
* <p>fromString converts a String to a scalar.
* fromStringArray converts an array of Strings
* <p>fromString converts a std::string to a scalar.
* fromStringArray converts an array of std::strings
* to a pvArray, which must have a scaler element type.
* A scalar field is a numeric field or pvBoolean or pvString.</p>
* <p>All from methods put data into a PVField, e.g. from means where the PVField gets it's data.</p>
@@ -85,7 +85,7 @@ public:
* @param builder The builder that will have the result.
* @param pvField The pvField.
*/
void getFullName(StringBuilder buf,PVFieldPtr const & pvField)
void getFullName(std::string *buf,PVFieldPtr const & pvField)
{
*buf = pvField->getFullName();
}
@@ -121,7 +121,7 @@ public:
* If a PVField is a structure or array be prepared for a very long string.
* @param indentLevel indentation level
*/
inline void getString(StringBuilder buf,PVFieldPtr const & pvField,int indentLevel)
inline void getString(std::string *buf,PVFieldPtr const & pvField,int indentLevel)
{getString(buf, pvField.get(), indentLevel);}
/**
* Convert a PVField to a string.
@@ -129,7 +129,7 @@ public:
* @param pv The PVField to convert to a string.
* If the PVField is a structure or array be prepared for a very long string.
*/
inline void getString(StringBuilder buf,PVFieldPtr const & pvField)
inline void getString(std::string * buf,PVFieldPtr const & pvField)
{getString(buf, pvField.get(), 0);}
/**
* Convert a PVField to a string.
@@ -138,49 +138,49 @@ public:
* If a PVField is a structure or array be prepared for a very long string.
* @param indentLevel indentation level
*/
void getString(StringBuilder buf,PVField const * pvField,int indentLevel);
void getString(std::string * buf,PVField const * pvField,int indentLevel);
/**
* Convert a PVField to a string.
* param buf buffer for the result
* @param pv The PVField to convert to a string.
* If the PVField is a structure or array be prepared for a very long string.
*/
inline void getString(StringBuilder buf,PVField const * pvField)
inline void getString(std::string * buf,PVField const * pvField)
{getString(buf, pvField, 0);}
/**
* Convert from an array of String to a PVScalar
* Convert from an array of std::string to a PVScalar
* @param pv The PV.
* @param from The array of String value to convert and put into a PV.
* @param from The array of std::string value to convert and put into a PV.
* @param fromStartIndex The first element if the array of strings.
* @throws std::logic_error if the array of String does not have a valid values.
* @throws std::logic_error if the array of std::string does not have a valid values.
*/
std::size_t fromString(
PVStructurePtr const &pv,
StringArray const & from,
std::size_t fromStartIndex = 0);
/**
* Convert from a String to a PVScalar
* Convert from a std::string to a PVScalar
* @param pv The PV.
* @param from The String value to convert and put into a PV.
* @throws std::logic_error if the String does not have a valid value.
* @param from The std::string value to convert and put into a PV.
* @throws std::logic_error if the std::string does not have a valid value.
*/
void fromString(PVScalarPtr const & pv, String const & from)
void fromString(PVScalarPtr const & pv, std::string const & from)
{
pv->putFrom<String>(from);
pv->putFrom<std::string>(from);
}
/**
* Convert from a String to a PVScalarArray.
* The String must be a comma separated set of values optionally enclosed in []
* Convert from a std::string to a PVScalarArray.
* The std::string must be a comma separated set of values optionally enclosed in []
* @param pv The PV.
* @param from The String value to convert and put into a PV.
* @param from The std::string value to convert and put into a PV.
* @return The number of elements converted.
* @throws std::invalid_argument if the element Type is not a scalar.
* @throws std::logic_error if the String does not have a valid array values.
* @throws std::logic_error if the std::string does not have a valid array values.
*/
std::size_t fromString(PVScalarArrayPtr const & pv, String from);
std::size_t fromString(PVScalarArrayPtr const & pv, std::string from);
/**
* Convert a PVScalarArray from a String array.
* Convert a PVScalarArray from a std::string array.
* The array element type must be a scalar.
* @param pv The PV.
* @param offset Starting element in a PV.
@@ -189,7 +189,7 @@ public:
* @param fromOffset Starting element in the source array.
* @return The number of elements converted.
* @throws std::invalid_argument if the element Type is not a scalar.
* @throws std::logic_error if the String does not have a valid value.
* @throws std::logic_error if the std::string does not have a valid value.
*/
std::size_t fromStringArray(
PVScalarArrayPtr const & pv,
@@ -197,11 +197,11 @@ public:
StringArray const & from,
std::size_t fromOffset);
/**
* Convert a PVScalarArray to a String array.
* Convert a PVScalarArray to a std::string array.
* @param pv The PV.
* @param offset Starting element in the PV array.
* @param length Number of elements to convert to the string array.
* @param to String array to receive the converted PV data.
* @param to std::string array to receive the converted PV data.
* @param toOffset Starting element in the string array.
* @return Number of elements converted.
*/
@@ -401,11 +401,11 @@ public:
*/
inline double toDouble(PVScalarPtr const & pv) { return pv->getAs<double>();}
/**
* Convert a PV to a String
* Convert a PV to a std::string
* @param pv a PV
* @return converted value
*/
inline String toString(PVScalarPtr const & pv) { return pv->getAs<String>();}
inline std::string toString(PVScalarPtr const & pv) { return pv->getAs<std::string>();}
/**
* Convert a PV from a byte
* @param pv a PV
@@ -480,10 +480,10 @@ public:
/**
* Convenience method for implementing toString.
* It generates a newline and inserts blanks at the beginning of the newline.
* @param builder The StringBuilder being constructed.
* @param builder The std::string * being constructed.
* @param indentLevel Indent level, Each level is four spaces.
*/
void newLine(StringBuilder buf, int indentLevel);
void newLine(std::string * buf, int indentLevel);
};
static inline ConvertPtr getConvert() { return Convert::getConvert(); }
+1
View File
@@ -2,6 +2,7 @@
#define PRINTER_H
#include <ostream>
#include <shareLib.h>
#include "pvData.h"
+34 -111
View File
@@ -35,69 +35,6 @@ typedef class std::ios std::ios_base;
namespace epics { namespace pvData {
namespace format {
struct indent_level
{
long level;
indent_level(long l) : level(l) {}
};
inline long& indent_value(std::ios_base& ios)
{
static int indent_index = std::ios_base::xalloc();
return ios.iword(indent_index);
}
epicsShareExtern std::ostream& operator<<(std::ostream& os, indent_level const& indent);
struct indent_scope
{
long saved_level;
std::ios_base& stream;
indent_scope(std::ios_base& ios) :
stream(ios)
{
long& l = indent_value(ios);
saved_level = l;
l = saved_level + 1;
}
~indent_scope()
{
indent_value(stream) = saved_level;
}
};
struct indent
{
};
epicsShareExtern std::ostream& operator<<(std::ostream& os, indent const&);
struct array_at
{
std::size_t index;
array_at(std::size_t ix) : index(ix) {}
};
struct array_at_internal
{
std::size_t index;
std::ostream& stream;
array_at_internal(std::size_t ix, std::ostream& str) : index(ix), stream(str) {}
};
epicsShareExtern array_at_internal operator<<(std::ostream& str, array_at const& manip);
};
class PostHandler;
class PVField;
@@ -223,13 +160,13 @@ public:
* Get the fieldName for this field.
* @return The name or empty string if top level field.
*/
inline const String& getFieldName() const {return fieldName;}
inline const std::string& getFieldName() const {return fieldName;}
/**
* Fully expand the name of this field using the
* names of its parent fields with a dot '.' seperating
* each name.
*/
String getFullName() const;
std::string getFullName() const;
/**
* Get offset of the PVField field within top level structure.
* Every field within the PVStructure has a unique offset.
@@ -287,19 +224,6 @@ public:
* @return (false,true) if (is not,is) equal.
*/
virtual bool equals(PVField &pv);
/**
* Convert the PVField to a string.
* @param buf buffer for the result
*/
virtual void toString(StringBuilder buf) ;
/**
* Convert the PVField to a string.
* Each line is indented.
* @param buf buffer for the result
* @param indentLevel The indentation level.
*/
virtual void toString(StringBuilder buf,int indentLevel) ;
/**
* Puts the PVField raw value to the stream.
* @param o output stream.
@@ -307,19 +231,18 @@ public:
*/
virtual std::ostream& dumpValue(std::ostream& o) const = 0;
protected:
PVField::shared_pointer getPtrSelf()
{
return shared_from_this();
}
PVField(FieldConstPtr field);
void setParentAndName(PVStructure *parent, String const & fieldName);
void setParentAndName(PVStructure *parent, std::string const & fieldName);
private:
static void computeOffset(const PVField *pvField);
static void computeOffset(const PVField *pvField,std::size_t offset);
String notImplemented;
String fieldName;
std::string notImplemented;
std::string fieldName;
PVStructure *parent;
FieldConstPtr field;
size_t fieldOffset;
@@ -516,7 +439,7 @@ typedef std::tr1::shared_ptr<PVDouble> PVDoublePtr;
/**
* PVString is special case, since it implements SerializableArray
*/
class epicsShareClass PVString : public PVScalarValue<String>, SerializableArray {
class epicsShareClass PVString : public PVScalarValue<std::string>, SerializableArray {
public:
/**
* Destructor
@@ -524,7 +447,7 @@ public:
virtual ~PVString() {}
protected:
PVString(ScalarConstPtr const & scalar)
: PVScalarValue<String>(scalar) {}
: PVScalarValue<std::string>(scalar) {}
};
typedef std::tr1::shared_ptr<PVString> PVStringPtr;
@@ -709,10 +632,10 @@ public:
* @param fieldName The name of the field.
* @return Pointer to the field or null if field does not exist.
*/
PVFieldPtr getSubField(String const &fieldName) const;
PVFieldPtr getSubField(std::string const &fieldName) const;
template<typename PVT>
std::tr1::shared_ptr<PVT> getSubField(String const &fieldName) const
std::tr1::shared_ptr<PVT> getSubField(std::string const &fieldName) const
{
PVFieldPtr pvField = getSubField(fieldName);
if (pvField.get())
@@ -744,84 +667,84 @@ public:
* @param fieldName The name of the field to get.
* @return Pointer to the field of null if a field with that name and type does not exist.
*/
PVBooleanPtr getBooleanField(String const &fieldName) ;
PVBooleanPtr getBooleanField(std::string const &fieldName) ;
/**
* Get a byte field with the specified name.
* No longer needed. Use templete version of getSubField
* @param fieldName The name of the field to get.
* @return Pointer to the field of null if a field with that name and type does not exist.
*/
PVBytePtr getByteField(String const &fieldName) ;
PVBytePtr getByteField(std::string const &fieldName) ;
/**
* Get a short field with the specified name.
* No longer needed. Use templete version of getSubField
* @param fieldName The name of the field to get.
* @return Pointer to the field of null if a field with that name and type does not exist.
*/
PVShortPtr getShortField(String const &fieldName) ;
PVShortPtr getShortField(std::string const &fieldName) ;
/**
* Get a int field with the specified name.
* No longer needed. Use templete version of getSubField
* @param fieldName The name of the field to get.
* @return Pointer to the field of null if a field with that name and type does not exist.
*/
PVIntPtr getIntField(String const &fieldName) ;
PVIntPtr getIntField(std::string const &fieldName) ;
/**
* Get a long field with the specified name.
* No longer needed. Use templete version of getSubField
* @param fieldName The name of the field to get.
* @return Pointer to the field of null if a field with that name and type does not exist.
*/
PVLongPtr getLongField(String const &fieldName) ;
PVLongPtr getLongField(std::string const &fieldName) ;
/**
* Get an unsigned byte field with the specified name.
* No longer needed. Use templete version of getSubField
* @param fieldName The name of the field to get.
* @return Pointer to the field of null if a field with that name and type does not exist.
*/
PVUBytePtr getUByteField(String const &fieldName) ;
PVUBytePtr getUByteField(std::string const &fieldName) ;
/**
* Get an unsigned short field with the specified name.
* No longer needed. Use templete version of getSubField
* @param fieldName The name of the field to get.
* @return Pointer to the field of null if a field with that name and type does not exist.
*/
PVUShortPtr getUShortField(String const &fieldName) ;
PVUShortPtr getUShortField(std::string const &fieldName) ;
/**
* Get an unsigned int field with the specified name.
* No longer needed. Use templete version of getSubField
* @param fieldName The name of the field to get.
* @return Pointer to the field of null if a field with that name and type does not exist.
*/
PVUIntPtr getUIntField(String const &fieldName) ;
PVUIntPtr getUIntField(std::string const &fieldName) ;
/**
* Get an unsigned long field with the specified name.
* No longer needed. Use templete version of getSubField
* @param fieldName The name of the field to get.
* @return Pointer to the field of null if a field with that name and type does not exist.
*/
PVULongPtr getULongField(String const &fieldName) ;
PVULongPtr getULongField(std::string const &fieldName) ;
/**
* Get a float field with the specified name.
* No longer needed. Use templete version of getSubField
* @param fieldName The name of the field to get.
* @return Pointer to the field of null if a field with that name and type does not exist.
*/
PVFloatPtr getFloatField(String const &fieldName) ;
PVFloatPtr getFloatField(std::string const &fieldName) ;
/**
* Get a double field with the specified name.
* No longer needed. Use templete version of getSubField
* @param fieldName The name of the field to get.
* @return Pointer to the field of null if a field with that name and type does not exist.
*/
PVDoublePtr getDoubleField(String const &fieldName) ;
PVDoublePtr getDoubleField(std::string const &fieldName) ;
/**
* Get a string field with the specified name.
* No longer needed. Use templete version of getSubField
* @param fieldName The name of the field to get.
* @return Pointer to the field of null if a field with that name and type does not exist.
*/
PVStringPtr getStringField(String const &fieldName) ;
PVStringPtr getStringField(std::string const &fieldName) ;
/**
* Get a structure field with the specified name.
@@ -829,14 +752,14 @@ public:
* @param fieldName The name of the field to get.
* @return Pointer to the field of null if a field with that name and type does not exist.
*/
PVStructurePtr getStructureField(String const &fieldName) ;
PVStructurePtr getStructureField(std::string const &fieldName) ;
/**
* Get a union field with the specified name.
* No longer needed. Use templete version of getSubField
* @param fieldName The name of the field to get.
* @return Pointer to the field of null if a field with that name and type does not exist.
*/
PVUnionPtr getUnionField(String const &fieldName) ;
PVUnionPtr getUnionField(std::string const &fieldName) ;
/**
* Get a scalarArray field with the specified name.
* No longer needed. Use templete version of getSubField
@@ -845,21 +768,21 @@ public:
* @return Pointer to the field of null if a field with that name and type does not exist.
*/
PVScalarArrayPtr getScalarArrayField(
String const &fieldName,ScalarType elementType) ;
std::string const &fieldName,ScalarType elementType) ;
/**
* Get a structureArray field with the specified name.
* No longer needed. Use templete version of getSubField
* @param fieldName The name of the field to get.
* @return Pointer to the field of null if a field with that name and type does not exist.
*/
PVStructureArrayPtr getStructureArrayField(String const &fieldName) ;
PVStructureArrayPtr getStructureArrayField(std::string const &fieldName) ;
/**
* Get a unionArray field with the specified name.
* No longer needed. Use templete version of getSubField
* @param fieldName The name of the field to get.
* @return Pointer to the field of null if a field with that name and type does not exist.
*/
PVUnionArrayPtr getUnionArrayField(String const &fieldName) ;
PVUnionArrayPtr getUnionArrayField(std::string const &fieldName) ;
/**
* Serialize.
* @param pbuffer The byte buffer.
@@ -926,7 +849,7 @@ private:
PVFieldPtrArray pvFields;
StructureConstPtr structurePtr;
String extendsStructureName;
std::string extendsStructureName;
friend class PVDataCreate;
};
@@ -988,10 +911,10 @@ public:
* @return corresponding PVField (of undetermined value).
* @throws {@code std::invalid_argument} if field does not exist.
*/
PVFieldPtr select(String const & fieldName);
PVFieldPtr select(std::string const & fieldName);
template<typename PVT>
std::tr1::shared_ptr<PVT> select(String const & fieldName) {
std::tr1::shared_ptr<PVT> select(std::string const & fieldName) {
return std::tr1::dynamic_pointer_cast<PVT>(select(fieldName));
}
@@ -1005,7 +928,7 @@ public:
* Get selected field name.
* @return selected field name, empty string if field does not exist.
*/
String getSelectedFieldName() const;
std::string getSelectedFieldName() const;
/**
* Set the {@code PVField} (by reference!) as selected field.
@@ -1025,12 +948,12 @@ public:
/**
* Set the {@code PVField} (by reference!) as field by given name.
* If a value is not a valid union field an {@code std::invalid_argument} exception is thrown.
* Use {@code select(String)} to put by value.
* Use {@code select(std::string)} to put by value.
* @param fieldName Name of the field to put.
* @param value the field to set.
* @see #select(String)
* @see #select(std::string)
*/
void set(String const & fieldName, PVFieldPtr const & value);
void set(std::string const & fieldName, PVFieldPtr const & value);
/**
* Serialize.
@@ -1429,7 +1352,7 @@ typedef std::tr1::shared_ptr<PVFloatArray> PVFloatArrayPtr;
typedef PVValueArray<double> PVDoubleArray;
typedef std::tr1::shared_ptr<PVDoubleArray> PVDoubleArrayPtr;
typedef PVValueArray<String> PVStringArray;
typedef PVValueArray<std::string> PVStringArray;
typedef std::tr1::shared_ptr<PVStringArray> PVStringArrayPtr;
/**
+147 -115
View File
@@ -12,6 +12,7 @@
#include <string>
#include <stdexcept>
#include <iostream>
#include <pv/noDefaultMethods.h>
#include <pv/pvType.h>
@@ -22,6 +23,67 @@
namespace epics { namespace pvData {
namespace format {
struct indent_level
{
long level;
indent_level(long l) : level(l) {}
};
inline long& indent_value(std::ios_base& ios)
{
static int indent_index = std::ios_base::xalloc();
return ios.iword(indent_index);
}
epicsShareExtern std::ostream& operator<<(std::ostream& os, indent_level const& indent);
struct indent_scope
{
long saved_level;
std::ios_base& stream;
indent_scope(std::ios_base& ios) :
stream(ios)
{
long& l = indent_value(ios);
saved_level = l;
l = saved_level + 1;
}
~indent_scope()
{
indent_value(stream) = saved_level;
}
};
struct indent
{
};
epicsShareExtern std::ostream& operator<<(std::ostream& os, indent const&);
struct array_at
{
std::size_t index;
array_at(std::size_t ix) : index(ix) {}
};
struct array_at_internal
{
std::size_t index;
std::ostream& stream;
array_at_internal(std::size_t ix, std::ostream& str) : index(ix), stream(str) {}
};
epicsShareExtern array_at_internal operator<<(std::ostream& str, array_at const& manip);
};
class Field;
class Scalar;
class Array;
@@ -108,14 +170,11 @@ namespace TypeFunc {
* @return The name for the type.
*/
epicsShareExtern const char* name(Type type);
/**
* Convert the type to a string and add it to builder.
* @param builder The string builder.
* @param type The type.
*/
epicsShareExtern void toString(StringBuilder builder,const Type type);
};
epicsShareExtern std::ostream& operator<<(std::ostream& o, const Type& type);
/**
* Definition of support scalar types.
*/
@@ -206,24 +265,21 @@ namespace ScalarTypeFunc {
* @return The scalarType.
* An exception is thrown if the name is not the name of a scalar type.
*/
epicsShareExtern ScalarType getScalarType(String const &value);
epicsShareExtern ScalarType getScalarType(std::string const &value);
/**
* Get a name for the scalarType.
* @param scalarType The type.
* @return The name for the scalarType.
*/
epicsShareExtern const char* name(ScalarType scalarType);
/**
* Convert the scalarType to a string and add it to builder.
* @param builder The string builder.
* @param scalarType The type.
*/
epicsShareExtern void toString(StringBuilder builder,ScalarType scalarType);
//! gives sizeof(T) where T depends on the scalar type id.
epicsShareExtern size_t elementSize(ScalarType id);
};
epicsShareExtern std::ostream& operator<<(std::ostream& o, const ScalarType& scalarType);
/**
* This class implements introspection object for field.
*/
@@ -245,18 +301,15 @@ public:
* Get the identification string.
* @return The identification string, can be empty.
*/
virtual String getID() const = 0;
virtual std::string getID() const = 0;
/**
* Convert the scalarType to a string and add it to builder.
* @param builder The string builder.
* Puts the string representation to the stream.
* @param o output stream.
* @return The output stream.
*/
virtual void toString(StringBuilder builder) const{toString(builder,0);}
/**
* Convert the scalarType to a string and add it to builder.
* @param builder The string builder.
* @param indentLevel The number of blanks at the beginning of new lines.
*/
virtual void toString(StringBuilder builder,int indentLevel) const;
virtual std::ostream& dump(std::ostream& o) const = 0;
protected:
/**
* Constructor
@@ -276,6 +329,8 @@ private:
struct Deleter{void operator()(Field *p){delete p;}};
};
epicsShareExtern std::ostream& operator<<(std::ostream& o, const Field& field);
/**
* This class implements introspection object for Scalar.
@@ -294,19 +349,10 @@ public:
* @return the scalarType
*/
ScalarType getScalarType() const {return scalarType;}
/**
* Convert the scalar to a string and add it to builder.
* @param builder The string builder.
*/
virtual void toString(StringBuilder buf) const{toString(buf,0);}
/**
* Convert the scalar to a string and add it to builder.
* @param builder The string builder.
* @param indentLevel The number of blanks at the beginning of new lines.
*/
virtual void toString(StringBuilder buf,int indentLevel) const;
virtual std::string getID() const;
virtual String getID() const;
virtual std::ostream& dump(std::ostream& o) const;
virtual void serialize(ByteBuffer *buffer, SerializableControl *control) const;
virtual void deserialize(ByteBuffer *buffer, DeserializableControl *control);
@@ -367,19 +413,10 @@ public:
* @return the scalarType
*/
ScalarType getElementType() const {return elementType;}
/**
* Convert the scalarType to a string and add it to builder.
* @param builder The string builder.
*/
virtual void toString(StringBuilder buf) const{toString(buf,0);}
/**
* Convert the scalarType to a string and add it to builder.
* @param builder The string builder.
* @param indentLevel The number of blanks at the beginning of new lines.
*/
virtual void toString(StringBuilder buf,int indentLevel) const;
virtual String getID() const;
virtual std::string getID() const;
virtual std::ostream& dump(std::ostream& o) const;
virtual void serialize(ByteBuffer *buffer, SerializableControl *control) const;
virtual void deserialize(ByteBuffer *buffer, DeserializableControl *control);
@@ -391,7 +428,7 @@ protected:
virtual ~ScalarArray();
private:
int8 getTypeCodeLUT() const;
const String getIDScalarArrayLUT() const;
const std::string getIDScalarArrayLUT() const;
ScalarType elementType;
friend class FieldCreate;
};
@@ -411,14 +448,9 @@ public:
*/
StructureConstPtr getStructure() const {return pstructure;}
/**
* Convert the scalarType to a string and add it to builder.
* @param builder The string builder.
* @param indentLevel The number of blanks at the beginning of new lines.
*/
virtual void toString(StringBuilder buf,int indentLevel=0) const;
virtual String getID() const;
virtual std::string getID() const;
virtual std::ostream& dump(std::ostream& o) const;
virtual void serialize(ByteBuffer *buffer, SerializableControl *control) const;
virtual void deserialize(ByteBuffer *buffer, DeserializableControl *control);
@@ -453,14 +485,9 @@ public:
*/
UnionConstPtr getUnion() const {return punion;}
/**
* Convert the scalarType to a string and add it to builder.
* @param builder The string builder.
* @param indentLevel The number of blanks at the beginning of new lines.
*/
virtual void toString(StringBuilder buf,int indentLevel=0) const;
virtual String getID() const;
virtual std::string getID() const;
virtual std::ostream& dump(std::ostream& o) const;
virtual void serialize(ByteBuffer *buffer, SerializableControl *control) const;
virtual void deserialize(ByteBuffer *buffer, DeserializableControl *control);
@@ -490,7 +517,7 @@ public:
/**
* Default structure ID.
*/
static epics::pvData::String DEFAULT_ID;
static std::string DEFAULT_ID;
/**
* Destructor.
@@ -510,7 +537,7 @@ public:
* @return The introspection interface.
* This will hold a null pointer if the field is not in the structure.
*/
FieldConstPtr getField(String const &fieldName) const;
FieldConstPtr getField(std::string const &fieldName) const;
/**
* Get the field for the specified fieldName.
* @param fieldName The index of the field to get;
@@ -523,7 +550,7 @@ public:
* @return The introspection interface.
* This will be -1 if the field is not in the structure.
*/
std::size_t getFieldIndex(String const &fieldName) const;
std::size_t getFieldIndex(std::string const &fieldName) const;
/**
* Get the fields in the structure.
* @return The array of fields.
@@ -539,33 +566,26 @@ public:
* @param fieldIndex The index of the desired field.
* @return The fieldName.
*/
String getFieldName(std::size_t fieldIndex) const {return fieldNames[fieldIndex];}
/**
* Convert the structure to a string and add it to builder.
* @param builder The string builder.
*/
virtual void toString(StringBuilder buf) const{toString(buf,0);}
/**
* Convert the structure to a string and add it to builder.
* @param builder The string builder.
* @param indentLevel The number of blanks at the beginning of new lines.
*/
virtual void toString(StringBuilder buf,int indentLevel) const;
virtual String getID() const;
std::string getFieldName(std::size_t fieldIndex) const {return fieldNames[fieldIndex];}
virtual std::string getID() const;
virtual std::ostream& dump(std::ostream& o) const;
virtual void serialize(ByteBuffer *buffer, SerializableControl *control) const;
virtual void deserialize(ByteBuffer *buffer, DeserializableControl *control);
protected:
Structure(StringArray const & fieldNames, FieldConstPtrArray const & fields, String const & id = DEFAULT_ID);
Structure(StringArray const & fieldNames, FieldConstPtrArray const & fields, std::string const & id = DEFAULT_ID);
private:
void toStringCommon(StringBuilder buf,int indentLevel) const;
StringArray fieldNames;
FieldConstPtrArray fields;
String id;
friend class FieldCreate;
friend class Union;
std::string id;
virtual void dumpFields(std::ostream& o) const;
friend class FieldCreate;
friend class Union;
};
/**
@@ -578,12 +598,12 @@ public:
/**
* Default union ID.
*/
static epics::pvData::String DEFAULT_ID;
static std::string DEFAULT_ID;
/**
* Default variant union ID.
*/
static epics::pvData::String ANY_ID;
static std::string ANY_ID;
/**
* Destructor.
@@ -603,7 +623,7 @@ public:
* @return The introspection interface.
* This will hold a null pointer if the field is not in the union.
*/
FieldConstPtr getField(String const &fieldName) const;
FieldConstPtr getField(std::string const &fieldName) const;
/**
* Get the field for the specified fieldName.
* @param fieldName The index of the field to get;
@@ -616,7 +636,7 @@ public:
* @return The introspection interface.
* This will be -1 if the field is not in the union.
*/
std::size_t getFieldIndex(String const &fieldName) const;
std::size_t getFieldIndex(std::string const &fieldName) const;
/**
* Get the fields in the union.
* @return The array of fields.
@@ -632,37 +652,30 @@ public:
* @param fieldIndex The index of the desired field.
* @return The fieldName.
*/
String getFieldName(std::size_t fieldIndex) const {return fieldNames[fieldIndex];}
std::string getFieldName(std::size_t fieldIndex) const {return fieldNames[fieldIndex];}
/**
* Check if this union is variant union (aka any type).
* @return <code>true</code> if this union is variant union, otherwise <code>false</code>.
*/
bool isVariant() const {return (fieldNames.size() == 0);}
/**
* Convert the union to a string and add it to builder.
* @param builder The string builder.
*/
virtual void toString(StringBuilder buf) const{toString(buf,0);}
/**
* Convert the union to a string and add it to builder.
* @param builder The string builder.
* @param indentLevel The number of blanks at the beginning of new lines.
*/
virtual void toString(StringBuilder buf,int indentLevel) const;
virtual String getID() const;
virtual std::string getID() const;
virtual std::ostream& dump(std::ostream& o) const;
virtual void serialize(ByteBuffer *buffer, SerializableControl *control) const;
virtual void deserialize(ByteBuffer *buffer, DeserializableControl *control);
protected:
Union();
Union(StringArray const & fieldNames, FieldConstPtrArray const & fields, String const & id = DEFAULT_ID);
Union(StringArray const & fieldNames, FieldConstPtrArray const & fields, std::string const & id = DEFAULT_ID);
private:
void toStringCommon(StringBuilder buf,int indentLevel) const;
StringArray fieldNames;
FieldConstPtrArray fields;
String id;
StringArray fieldNames;
FieldConstPtrArray fields;
std::string id;
virtual void dumpFields(std::ostream& o) const;
friend class FieldCreate;
friend class Structure;
};
@@ -778,8 +791,8 @@ public:
/**
* Complete the creation of a nested object.
* @see #addNestedStructure(String)
* @see #addNestedUnion(String)
* @see #addNestedStructure(std::string)
* @see #addNestedUnion(std::string)
* @return a previous (parent) {@code FieldBuilder}.
*/
FieldBuilderPtr endNested();
@@ -864,7 +877,7 @@ public:
* @return a {@code Structure} interface for the newly created object.
*/
StructureConstPtr createStructure (
String const & id,
std::string const & id,
StringArray const & fieldNames,
FieldConstPtrArray const & fields) const;
/**
@@ -901,7 +914,7 @@ public:
* @return a {@code Union} interface for the newly created object.
*/
UnionConstPtr createUnion (
String const & id,
std::string const & id,
StringArray const & fieldNames,
FieldConstPtrArray const & fields) const;
/**
@@ -913,7 +926,7 @@ public:
*/
StructureConstPtr appendField(
StructureConstPtr const & structure,
String const & fieldName, FieldConstPtr const & field) const;
std::string const & fieldName, FieldConstPtr const & field) const;
/**
* Append fields to a structure.
* @param structure The structure to which the fields appended.
@@ -986,8 +999,27 @@ OP(pvUInt, uint32)
OP(pvULong, uint64)
OP(pvFloat, float)
OP(pvDouble, double)
OP(pvString, String)
OP(pvString, std::string)
#undef OP
struct ScalarHashFunction {
size_t operator() (const Scalar& scalar) const { return scalar.getScalarType(); }
};
struct ScalarArrayHashFunction {
size_t operator() (const ScalarArray& scalarArray) const { return 0x10 | scalarArray.getElementType(); }
};
struct StructureHashFunction {
size_t operator() (const Structure& /*structure*/) const { return 0; }
// TODO hash
// final int PRIME = 31;
// return PRIME * Arrays.hashCode(fieldNames) + Arrays.hashCode(fields);
};
struct StructureArrayHashFunction {
size_t operator() (const StructureArray& structureArray) const { StructureHashFunction shf; return (0x10 | shf(*(structureArray.getStructure()))); }
};
}}
#endif /* PVINTROSPECT_H */
+8 -18
View File
@@ -93,29 +93,24 @@ typedef uint64_t uint64;
// float and double are types
/**
* A string
*/
typedef std::string String;
/**
* A string array.
*/
typedef std::vector<String> StringArray;
typedef std::vector<std::string> StringArray;
typedef std::tr1::shared_ptr<StringArray> StringArrayPtr;
inline String * get(StringArray &value)
inline std::string * get(StringArray &value)
{
return &value[0];
}
inline String const * get(StringArray const &value)
inline std::string const * get(StringArray const &value)
{
return static_cast<String const *>(&value[0]);
return static_cast<std::string const *>(&value[0]);
}
inline String * get(StringArrayPtr &value)
inline std::string * get(StringArrayPtr &value)
{
return get(*value.get());
}
inline String const * get(StringArrayPtr const &value)
inline std::string const * get(StringArrayPtr const &value)
{
return get(*value.get());
}
@@ -127,13 +122,8 @@ inline StringArray const & getVector(StringArrayPtr const &value)
{
return *value.get();
}
typedef std::vector<String>::iterator StringArray_iterator;
typedef std::vector<String>::const_iterator StringArray_const_iterator;
/**
* A convenience definition for toString methods
*/
typedef String * StringBuilder;
typedef std::vector<std::string>::iterator StringArray_iterator;
typedef std::vector<std::string>::const_iterator StringArray_const_iterator;
}}
#endif /* PVTYPE_H */
+12 -12
View File
@@ -38,9 +38,9 @@ typedef std::tr1::shared_ptr<StandardField> StandardFieldPtr;
* For example the call:
* {@code
StructureConstPtr example = standardField->scalar(
String("value"),
std::string("value"),
pvDouble,
String("value,alarm,timeStamp"));
std::string("value,alarm,timeStamp"));
* }
* Will result in a Field definition that has the form: {@code
structure example
@@ -75,7 +75,7 @@ public:
* This is some combination of "alarm,timeStamp,display,control,valueAlarm".
* @return The const shared pointer to the structure.
*/
StructureConstPtr scalar(ScalarType type,String const & properties);
StructureConstPtr scalar(ScalarType type,std::string const & properties);
/** Create a structure that has a union value field.
* @param punion The interface for value field.
* @param properties A comma separated list of properties.
@@ -84,20 +84,20 @@ public:
*/
StructureConstPtr regUnion(
UnionConstPtr const & punion,
String const & properties);
std::string const & properties);
/** Create a structure that has a varient union value field.
* @param properties A comma separated list of properties.
* This is some combination of "alarm,timeStamp,display,control,valueAlarm".
* @return The const shared pointer to the structure.
*/
StructureConstPtr variantUnion(String const & properties);
StructureConstPtr variantUnion(std::string const & properties);
/** Create a structure that has a scalarArray value field.
* @param type The type.
* @param properties A comma separated list of properties.
* This is some combination of "alarm,timeStamp,display,control,valueAlarm".
* @return The const shared pointer to the structure.
*/
StructureConstPtr scalarArray(ScalarType elementType, String const & properties);
StructureConstPtr scalarArray(ScalarType elementType, std::string const & properties);
/** Create a structure that has a structureArray value field.
* @param type The type.
* @param properties A comma separated list of properties.
@@ -106,7 +106,7 @@ public:
*/
StructureConstPtr structureArray(
StructureConstPtr const & structure,
String const & properties);
std::string const & properties);
/** Create a structure that has a unionArray value field.
* @param type The type.
* @param properties A comma separated list of properties.
@@ -115,7 +115,7 @@ public:
*/
StructureConstPtr unionArray(
UnionConstPtr const & punion,
String const & properties);
std::string const & properties);
/** Create a structure that has an enumerated structure value field.
* The id for the structure is "enum-t".
* @return The const shared pointer to the structure.
@@ -127,7 +127,7 @@ public:
* This is some combination of "alarm,timeStamp,display,control,valueAlarm".
* @return The const shared pointer to the structure.
*/
StructureConstPtr enumerated(String const & properties);
StructureConstPtr enumerated(std::string const & properties);
/**
* create an alarm structure
* @return The const shared pointer to the structure.
@@ -212,10 +212,10 @@ private:
StandardField();
void init();
StructureConstPtr createProperties(
String id,FieldConstPtr field,String properties);
std::string id,FieldConstPtr field,std::string properties);
FieldCreatePtr fieldCreate;
String notImplemented;
String valueFieldName;
std::string notImplemented;
std::string valueFieldName;
StructureConstPtr alarmField;
StructureConstPtr timeStampField;
StructureConstPtr displayField;
+6 -6
View File
@@ -50,7 +50,7 @@ public:
* This is some combination of "alarm,timeStamp,display,control,valueAlarm".
* @return The const shared pointer to the structure.
*/
PVStructurePtr scalar(ScalarType type,String const & properties);
PVStructurePtr scalar(ScalarType type,std::string const & properties);
/**
* Create a structure that has a scalar array value field.
* @param type The type.
@@ -58,7 +58,7 @@ public:
* This is some combination of "alarm,timeStamp,display,control,valueAlarm".
* @return The const shared pointer to the structure.
*/
PVStructurePtr scalarArray(ScalarType elementType, String const & properties);
PVStructurePtr scalarArray(ScalarType elementType, std::string const & properties);
/**
* Create a structure that has a structure array value field.
* @param type The type.
@@ -66,7 +66,7 @@ public:
* This is some combination of "alarm,timeStamp,display,control,valueAlarm".
* @return The const shared pointer to the structure.
*/
PVStructurePtr structureArray(StructureConstPtr const &structure,String const & properties);
PVStructurePtr structureArray(StructureConstPtr const &structure,std::string const & properties);
/**
* Create a structure that has a union array value field.
* @param type The type.
@@ -74,7 +74,7 @@ public:
* This is some combination of "alarm,timeStamp,display,control,valueAlarm".
* @return The const shared pointer to the structure.
*/
PVStructurePtr unionArray(UnionConstPtr const &punion,String const & properties);
PVStructurePtr unionArray(UnionConstPtr const &punion,std::string const & properties);
/**
* Create a structure that has an enumerated structure value field.
* The id for the structure is "enum_t".
@@ -89,13 +89,13 @@ public:
* @param properties A comma separated list of properties.
* @return The const shared pointer to the structure.
*/
PVStructurePtr enumerated(StringArray const &choices, String const & properties);
PVStructurePtr enumerated(StringArray const &choices, std::string const & properties);
private:
StandardPVField();
StandardFieldPtr standardField;
FieldCreatePtr fieldCreate;
PVDataCreatePtr pvDataCreate;
String notImplemented;
std::string notImplemented;
};
epicsShareExtern StandardPVFieldPtr getStandardPVField();