/*FieldCreateFactory.cpp*/ /** * Copyright - See the COPYRIGHT that is included with this distribution. * EPICS pvDataCPP is distributed subject to a Software License Agreement found * in file LICENSE that is included with this distribution. */ #include #include #include #include #include #include "pvIntrospect.h" #include "convert.h" #include "factory.h" #include "CDRMonitor.h" using std::tr1::static_pointer_cast; namespace epics { namespace pvData { static DebugLevel debugLevel = lowDebug; static void newLine(StringBuilder buffer, int indentLevel) { *buffer += "\n"; for(int i=0; itoString(buffer,indentLevel + 1); } Structure::Structure (String fieldName, int numberFields, FieldConstPtrArray infields) : Field(fieldName,structure), numberFields(numberFields), fields(infields) { for(int i=0; igetFieldName(); // look for duplicates for(int j=i+1; jgetFieldName(); int result = name.compare(otherName); if(result==0) { String message("duplicate fieldName "); message += name; delete[] fields; throw std::invalid_argument(message); } } } } Structure::~Structure() { if(debugLevel==highDebug) printf("~Structure %s\n",Field::getFieldName().c_str()); delete[] fields; } FieldConstPtr Structure::getField(String fieldName) const { for(int i=0; igetFieldName()); if(result==0) return pfield; } return FieldConstPtr(); } int Structure::getFieldIndex(String fieldName) const { for(int i=0; igetFieldName()); if(result==0) return i; } return -1; } void Structure::appendField(FieldConstPtr field) { FieldConstPtr *newFields = new FieldConstPtr[numberFields+1]; for(int i=0; i=numberFields) { throw std::invalid_argument( String("Structure::removeField index out of bounds")); } FieldConstPtr *newFields = new FieldConstPtr[numberFields-1]; int ind=0; for(int i=0; itoString(buffer,indentLevel+1); if(igetType(); switch(type) { case scalar: { ScalarConstPtr pscalar = static_pointer_cast(pfield); return createScalar(fieldName,pscalar->getScalarType()); } case scalarArray: { ScalarArrayConstPtr pscalarArray = static_pointer_cast(pfield); return createScalarArray(fieldName,pscalarArray->getElementType()); } case structure: { StructureConstPtr pstructure = static_pointer_cast(pfield); return createStructure(fieldName,pstructure->getNumberFields(),pstructure->getFields()); } case structureArray: { StructureArrayConstPtr pstructureArray = static_pointer_cast(pfield); return createStructureArray(fieldName,pstructureArray->getStructure()); } } String message("field "); message += fieldName; THROW_EXCEPTION2(std::logic_error, message); } static FieldCreate* fieldCreate = 0; FieldCreate::FieldCreate() { } FieldCreate * getFieldCreate() { static Mutex mutex; Lock xx(mutex); if(fieldCreate==0) fieldCreate = new FieldCreate(); return fieldCreate; } }}