本文整理汇总了C++中DynamicObject::getAttribute方法的典型用法代码示例。如果您正苦于以下问题:C++ DynamicObject::getAttribute方法的具体用法?C++ DynamicObject::getAttribute怎么用?C++ DynamicObject::getAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DynamicObject
的用法示例。
在下文中一共展示了DynamicObject::getAttribute方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sizeOut
bool Nitf::SectgaParser::fromDynamicObject(const DynamicObject& input, ostream& output, size_t& numBytesWritten,
string &errorMessage) const
{
if (output.tellp() < 0 || static_cast<uint64_t>(output.tellp()) > std::numeric_limits<size_t>::max())
{
return false;
}
size_t sizeIn = max<size_t>(0, static_cast<size_t>(output.tellp()));
size_t sizeOut(sizeIn);
try
{
output << sizeString(dv_cast<string>(input.getAttribute(SECTGA::SEC_ID)), 12);
output << sizeString(dv_cast<string>(input.getAttribute(SECTGA::SEC_BE)), 15);
output << toString(dv_cast<unsigned int>(input.getAttribute(SECTGA::RESERVED001)), 1, -1);
}
catch (const bad_cast&)
{
return false;
}
if (output.tellp() < 0 || static_cast<uint64_t>(output.tellp()) > std::numeric_limits<size_t>::max())
{
return false;
}
sizeOut = static_cast<size_t>(output.tellp());
numBytesWritten = sizeOut - sizeIn;
return true;
}
示例2: setAttributeByPath
bool DynamicObjectImp::setAttributeByPath(QStringList pathComponents, DataVariant& value, bool swap)
{
if (!value.isValid())
{
return false;
}
QString finalName = pathComponents.back();
pathComponents.pop_back();
string loopType = "DynamicObject";
DynamicObject* pLoopObj = dynamic_cast<DynamicObject*>(this);
DynamicObject* pCurObj = pLoopObj;
for (QStringList::const_iterator iter = pathComponents.begin();
iter != pathComponents.end(); ++iter)
{
if (pLoopObj == NULL || loopType != "DynamicObject")
{
return false;
}
pCurObj = pLoopObj;
DataVariant& attrValue = pCurObj->getAttribute(iter->toStdString());
loopType = attrValue.getTypeName();
pLoopObj = attrValue.getPointerToValue<DynamicObject>();
if ((pLoopObj != NULL) && (loopType != "DynamicObject"))
{
return false;
}
if (pLoopObj == NULL)
{
FactoryResource<DynamicObject> pNewObj;
if (pCurObj != NULL)
{
pCurObj->setAttribute(iter->toStdString(), *pNewObj.get());
DataVariant& currentValue = pCurObj->getAttribute(iter->toStdString());
loopType = currentValue.getTypeName();
pLoopObj = currentValue.getPointerToValue<DynamicObject>();
}
}
}
if (pLoopObj == NULL || loopType != "DynamicObject")
{
return false;
}
pCurObj = pLoopObj;
DynamicObjectImp* const pCurObjImp = dynamic_cast<DynamicObjectImp*>(pCurObj);
VERIFY(pCurObjImp != NULL);
return pCurObjImp->setAttribute(finalName.toStdString(), value, swap);
}
示例3: sizeOut
bool Nitf::EngrdaParser::fromDynamicObject(const DynamicObject& input,
std::ostream& output,
size_t& numBytesWritten,
std::string &errorMessage) const
{
if (output.tellp() < 0 || static_cast<uint64_t>(output.tellp()) > std::numeric_limits<size_t>::max())
{
return false;
}
size_t sizeIn = std::max<size_t>(0, static_cast<size_t>(output.tellp()));
size_t sizeOut(sizeIn);
try
{
output << sizeString(dv_cast<std::string>(input.getAttribute(ENGRDA::RESRC)), 20);
unsigned int cnt = dv_cast<unsigned int>(input.getAttribute(ENGRDA::RECNT));
output << toString(cnt, 3);
for (size_t recNum = 0; recNum < cnt; ++recNum)
{
const DynamicObject& rec = dv_cast<const DynamicObject>(
input.getAttribute(StringUtilities::toXmlString(recNum)));
std::string lbl = dv_cast<std::string>(rec.getAttribute(ENGRDA::ENGLBL));
output << toString(lbl.size(), 2);
output << sizeString(lbl, lbl.size());
output << toString(dv_cast<unsigned int>(rec.getAttribute(ENGRDA::ENGMTXC)), 4);
output << toString(dv_cast<unsigned int>(rec.getAttribute(ENGRDA::ENGMTXR)), 4);
output << sizeString(dv_cast<std::string>(rec.getAttribute(ENGRDA::ENGTYP)), 1);
unsigned int dts = dv_cast<unsigned int>(rec.getAttribute(ENGRDA::ENGDTS));
output << toString(dts, 1);
output << sizeString(dv_cast<std::string>(rec.getAttribute(ENGRDA::ENGDATU)), 2);
const Blob* data = dv_cast<Blob>(&rec.getAttribute(ENGRDA::ENGDATA));
const std::vector<unsigned char>& rawData = data->get();
unsigned int datc = rawData.size() / dts;
output << toString(datc, 8);
output.write(reinterpret_cast<const char*>(&(rawData.front())), rawData.size());
}
}
catch (const std::bad_cast&)
{
return false;
}
if (output.tellp() < 0 || static_cast<uint64_t>(output.tellp()) > std::numeric_limits<size_t>::max())
{
return false;
}
sizeOut = static_cast<size_t>(output.tellp());
numBytesWritten = sizeOut - sizeIn;
return true;
}
示例4: updateFields
void FeatureClassDlg::updateFields()
{
mpFieldTree->clear();
DynamicObject* pClass = getCurrentFeatureClass();
if (pClass == NULL)
{
return;
}
std::vector<std::string> fieldNames;
pClass->getAttributeNames(fieldNames);
for (std::vector<std::string>::const_iterator iter = fieldNames.begin(); iter != fieldNames.end(); ++iter)
{
std::string fieldName = *iter;
if (fieldName.empty() == false)
{
const DataVariant& field = pClass->getAttribute(fieldName);
QString fieldType = QString::fromStdString(field.getTypeName());
QString fieldValue = QString::fromStdString(field.toDisplayString());
QTreeWidgetItem* pFieldItem = new QTreeWidgetItem(mpFieldTree);
pFieldItem->setData(0, Qt::UserRole, QVariant(QString::fromStdString(fieldName)));
pFieldItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable);
pFieldItem->setText(0, QString::fromStdString(fieldName));
pFieldItem->setText(1, fieldType);
pFieldItem->setText(2, fieldValue);
}
}
}
示例5: success
bool Nitf::EngrdaParser::toDynamicObject(std::istream& input,
size_t numBytes,
DynamicObject& output,
std::string &errorMessage) const
{
std::vector<char> buf;
bool success(true);
Nitf::readField<std::string>(input, output, success, ENGRDA::RESRC, 20, errorMessage, buf);
Nitf::readField<unsigned int>(input, output, success, ENGRDA::RECNT, 3, errorMessage, buf);
unsigned int recnt = QString(&buf.front()).toUInt();
for (unsigned int rec = 0; rec < recnt; ++rec)
{
std::string recId = QString::number(rec).toStdString();
{
FactoryResource<DynamicObject> record;
output.setAttribute(recId, *record.get());
}
DynamicObject& record = dv_cast<DynamicObject>(output.getAttribute(recId));
unsigned int lbln(0);
Nitf::readAndConvertFromStream(input, lbln, success, ENGRDA::ENGLN, 2, errorMessage, buf);
Nitf::readField<std::string>(input, record, success, ENGRDA::ENGLBL, lbln, errorMessage, buf);
Nitf::readField<unsigned int>(input, record, success, ENGRDA::ENGMTXC, 4, errorMessage, buf);
Nitf::readField<unsigned int>(input, record, success, ENGRDA::ENGMTXR, 4, errorMessage, buf);
Nitf::readField<std::string>(input, record, success, ENGRDA::ENGTYP, 1, errorMessage, buf);
Nitf::readField<unsigned int>(input, record, success, ENGRDA::ENGDTS, 1, errorMessage, buf);
int dts = QString(&buf.front()).toInt(); // bytes per element
Nitf::readField<std::string>(input, record, success, ENGRDA::ENGDATU, 2, errorMessage, buf);
unsigned int datc(0); // data count
Nitf::readAndConvertFromStream(input, datc, success, ENGRDA::ENGDATC, 8, errorMessage, buf);
// read the data
Nitf::readFromStream(input, buf, datc * dts, false);
record.setAttribute(ENGRDA::ENGDATA, Blob(&buf.front(), buf.size()));
}
int64_t numRead = input.tellg();
if (numRead < 0 || static_cast<uint64_t>(numRead) > std::numeric_limits<size_t>::max() ||
numRead != static_cast<int64_t>(numBytes))
{
numReadErrMsg(numRead, numBytes, errorMessage);
return false;
}
return success;
}
示例6: getAttributeIndex
int ShapeFile::getAttributeIndex(const GraphicObject& graphicObject, const DynamicObject& dynObj) const
{
const string objectId = graphicObject.getId();
VERIFYRV(objectId.empty() == false, -1);
DataVariant idsVar = dynObj.getAttribute(graphicObjectIdAttrName);
vector<string> objectIds;
idsVar.getValue(objectIds);
for (vector<string>::size_type i = 0; i < objectIds.size(); ++i)
{
if (objectIds[i] == objectId)
{
return static_cast<int>(i);
}
}
return -1;
}
示例7: copyMetadata
bool ShapeFile::copyMetadata(const vector<string>& attrNames, int idx, const DynamicObject& dynObj,
Feature& feature) const
{
for (vector<string>::const_iterator iter = attrNames.begin(); iter != attrNames.end(); ++iter)
{
string attrName = *iter;
const DataVariant dv = dynObj.getAttribute(attrName);
string typeName = dv.getTypeName();
if (typeName.compare("vector<int>") == 0)
{
const vector<int>* pValues = dv.getPointerToValue<vector<int> >();
if (idx < static_cast<int>(pValues->size()))
{
feature.addField(attrName, int());
feature.setFieldValue(attrName, pValues->at(idx));
}
}
else if (typeName.compare("vector<double>") == 0)
{
const vector<double>* pValues = dv.getPointerToValue<vector<double> >();
if (idx < static_cast<int>(pValues->size()))
{
feature.addField(attrName, double());
feature.setFieldValue(attrName, pValues->at(idx));
}
}
else if (typeName.compare("vector<string>") == 0)
{
const vector<string>* pValues = dv.getPointerToValue<vector<string> >();
if (idx < static_cast<int>(pValues->size()))
{
feature.addField(attrName, string());
feature.setFieldValue(attrName, pValues->at(idx));
}
}
}
return true;
}
示例8: status
Nitf::TreState Nitf::BandsaParser::isTreValid(const DynamicObject& tre, ostream& reporter) const
{
TreState status(VALID);
set<string> testSet;
unsigned int numFields = 0;
unsigned int bandcount(0);
try
{
bandcount = dv_cast<unsigned int>(tre.getAttribute(BANDSA::BANDCOUNT));
numFields++;
}
catch (const bad_cast&)
{
reporter << "Field \"" << "BANDCOUNT" << "\" missing from the Dynamic Object";
status = INVALID;
}
status = MaxState(status, testTagValueRange(reporter, bandcount, 1U, 999U));
status = MaxState(status, testTagValueRange<double>(tre, reporter,
&numFields, BANDSA::ROW_SPACING, 0.0F, 9999.99F));
testSet.clear();
testSet.insert("f");
testSet.insert("m");
testSet.insert("r");
status = MaxState(status, testTagValidBcsASet(tre, reporter,
&numFields, BANDSA::ROW_SPACING_UNITS, testSet, true, true, true));
status = MaxState(status, testTagValueRange<double>(tre, reporter,
&numFields, BANDSA::COL_SPACING, 0.0F, 9999.99F));
testSet.clear();
testSet.insert("f");
testSet.insert("m");
testSet.insert("r");
status = MaxState(status, testTagValidBcsASet(tre, reporter,
&numFields, BANDSA::COL_SPACING_UNITS, testSet, true, true, true));
status = MaxState(status, testTagValueRange<double>(tre, reporter,
&numFields, BANDSA::FOCAL_LENGTH, 0.005F, 999.99F));
for (unsigned int i = 0; i < bandcount; ++i)
{
stringstream bandStreamStr;
bandStreamStr << "#" << i;
string bandStr(bandStreamStr.str());
string fieldName;
// In the following cases add 1/2 of the next decimal place (eg +0.005 to 0.01)
// to the test range to allow for floating point round off
fieldName = BANDSA::BANDPEAK + bandStr;
status = MaxState(status, testTagValueRange<double>(tre, reporter,
&numFields, fieldName, 0.005F, 19.995F, true));
fieldName = BANDSA::BANDLBOUND + bandStr;
status = MaxState(status, testTagValueRange<double>(tre, reporter,
&numFields, fieldName, 0.005F, 19.995F, true));
fieldName = BANDSA::BANDUBOUND + bandStr;
status = MaxState(status, testTagValueRange<double>(tre, reporter,
&numFields, fieldName, 0.005F, 19.995F, true));
fieldName = BANDSA::BANDWIDTH + bandStr;
status = MaxState(status, testTagValueRange<double>(tre, reporter,
&numFields, fieldName, 0.005F, 19.995F, true));
fieldName = BANDSA::BANDCALDRK + bandStr;
status = MaxState(status, testTagValueRange<double>(tre, reporter,
&numFields, fieldName, 0.05F, 9999.95F, true));
fieldName = BANDSA::BANDCALINC + bandStr;
status = MaxState(status, testTagValueRange<double>(tre, reporter,
&numFields, fieldName, 0.005F, 19.995F, true));
fieldName = BANDSA::BANDRESP + bandStr;
status = MaxState(status, testTagValueRange<double>(tre, reporter,
&numFields, fieldName, 0.05F, 999.995F, true));
fieldName = BANDSA::BANDASD + bandStr;
status = MaxState(status, testTagValueRange<double>(tre, reporter,
&numFields, fieldName, 0.05F, 999.995F, true));
fieldName = BANDSA::BANDGSD + bandStr;
status = MaxState(status, testTagValueRange<double>(tre, reporter,
&numFields, fieldName, 0.005F, 99.995F, true));
}
unsigned int totalFields = tre.getNumAttributes();
if (status != INVALID && totalFields != numFields)
{
reporter << "Total fields in the Dynamic Object(" <<
totalFields << ") did not match the number found(" << numFields << ") ";
status = INVALID;
}
if (status == INVALID)
{
reporter << " INVALID fields found in the BANDSA TAG/SDE\n" ;
//.........这里部分代码省略.........
示例9: sizeOut
bool Nitf::RpcParser::fromDynamicObject(const DynamicObject& input, ostream& output, size_t& numBytesWritten,
string &errorMessage) const
{
if (output.tellp() < 0 || static_cast<uint64_t>(output.tellp()) > std::numeric_limits<size_t>::max())
{
return false;
}
size_t sizeIn = max<size_t>(0, static_cast<size_t>(output.tellp()));
size_t sizeOut(sizeIn);
try
{
output << dv_cast<bool>(input.getAttribute(SUCCESS)) ? "1" : "0";
output << toString(dv_cast<double>(input.getAttribute(ERR_BIAS)), 7, 2);
output << toString(dv_cast<double>(input.getAttribute(ERR_RAND)), 7, 2);
output << toString(dv_cast<unsigned int>(input.getAttribute(LINE_OFFSET)), 6);
output << toString(dv_cast<unsigned int>(input.getAttribute(SAMP_OFFSET)), 5);
output << toString(dv_cast<double>(input.getAttribute(LAT_OFFSET)), 8, 4, ZERO_FILL, POS_SIGN_TRUE);
output << toString(dv_cast<double>(input.getAttribute(LONG_OFFSET)), 9, 4, ZERO_FILL, POS_SIGN_TRUE);
output << toString(dv_cast<int>(input.getAttribute(HEIGHT_OFFSET)), 5, -1, ZERO_FILL, POS_SIGN_TRUE);
output << toString(dv_cast<unsigned int>(input.getAttribute(LINE_SCALE)), 6);
output << toString(dv_cast<unsigned int>(input.getAttribute(SAMP_SCALE)), 5);
output << toString(dv_cast<double>(input.getAttribute(LAT_SCALE)), 8, 4, ZERO_FILL, POS_SIGN_TRUE);
output << toString(dv_cast<double>(input.getAttribute(LONG_SCALE)), 9, 4, ZERO_FILL, POS_SIGN_TRUE);
output << toString(dv_cast<int>(input.getAttribute(HEIGHT_SCALE)), 5, -1, ZERO_FILL, POS_SIGN_TRUE);
unsigned int u;
for (u = 1; u <= 20; ++u)
{
output << toString(dv_cast<double>(input.getAttribute(getRpcCoefficient(LINE_NUMERATOR_COEF_PREFIX, u))),
12, 6, ZERO_FILL, POS_SIGN_TRUE, USE_SCIENTIFIC_NOTATION, ONE_EXP_DIGIT);
}
for (u = 1; u <= 20; ++u)
{
output << toString(dv_cast<double>(input.getAttribute(getRpcCoefficient(LINE_DENOMINATOR_COEF_PREFIX, u))),
12, 6, ZERO_FILL, POS_SIGN_TRUE, USE_SCIENTIFIC_NOTATION, ONE_EXP_DIGIT);
}
for (u = 1; u <= 20; ++u)
{
output << toString(dv_cast<double>(input.getAttribute(getRpcCoefficient(SAMPLE_NUMERATOR_COEF_PREFIX, u))),
12, 6, ZERO_FILL, POS_SIGN_TRUE, USE_SCIENTIFIC_NOTATION, ONE_EXP_DIGIT);
}
for (u = 1; u <= 20; ++u)
{
output << toString(dv_cast<double>(input.getAttribute(getRpcCoefficient(SAMPLE_DENOMINATOR_COEF_PREFIX, u))),
12, 6, ZERO_FILL, POS_SIGN_TRUE, USE_SCIENTIFIC_NOTATION, ONE_EXP_DIGIT);
}
}
catch (const bad_cast&)
{
return false;
}
if (output.tellp() < 0 || static_cast<uint64_t>(output.tellp()) > std::numeric_limits<size_t>::max())
{
return false;
}
sizeOut = static_cast<size_t>(output.tellp());
numBytesWritten = sizeOut - sizeIn;
return true;
}
示例10: sizeOut
bool Nitf::PatchbParser::fromDynamicObject(const DynamicObject& input, ostream& output, size_t& numBytesWritten,
string &errorMessage) const
{
if (output.tellp() < 0 || static_cast<uint64_t>(output.tellp()) > std::numeric_limits<size_t>::max())
{
return false;
}
size_t sizeIn = max<size_t>(0, static_cast<size_t>(output.tellp()));
size_t sizeOut(sizeIn);
try
{
output << toString(dv_cast<int>(input.getAttribute(PATCHB::PAT_NO)), 4);
output << toString(dv_cast<int>(input.getAttribute(PATCHB::LAST_PAT_FLAG)), 1,
-1, ZERO_FILL, false, false, 3, true);
output << toString(dv_cast<int>(input.getAttribute(PATCHB::LNSTRT)), 7);
output << toString(dv_cast<int>(input.getAttribute(PATCHB::LNSTOP)), 7);
output << toString(dv_cast<int>(input.getAttribute(PATCHB::AZL)), 5);
output << toString(dv_cast<int>(input.getAttribute(PATCHB::NVL)), 5,
-1, ZERO_FILL, false, false, 3, true);
output << toString(dv_cast<int>(input.getAttribute(PATCHB::FVL)), 3,
-1, ZERO_FILL, false, false, 3, true);
output << toString(dv_cast<int>(input.getAttribute(PATCHB::NPIXEL)), 5);
output << toString(dv_cast<int>(input.getAttribute(PATCHB::FVPIX)), 5);
output << toString(dv_cast<int>(input.getAttribute(PATCHB::FRAME)), 3,
-1, ZERO_FILL, false, false, 3, true);
output << toString(dv_cast<double>(input.getAttribute(PATCHB::UTC)), 8, 2);
output << toString(dv_cast<double>(input.getAttribute(PATCHB::SHEAD)), 7, 3);
output << toString(dv_cast<double>(input.getAttribute(PATCHB::GRAVITY)), 7, 4,
ZERO_FILL, false, false, 3, true);
output << toString(dv_cast<int>(input.getAttribute(PATCHB::INS_V_NC)), 5, -1, ZERO_FILL, POS_SIGN_TRUE);
output << toString(dv_cast<int>(input.getAttribute(PATCHB::INS_V_EC)), 5, -1, ZERO_FILL, POS_SIGN_TRUE);
output << toString(dv_cast<int>(input.getAttribute(PATCHB::INS_V_DC)), 5, -1, ZERO_FILL, POS_SIGN_TRUE);
output << toString(dv_cast<double>(input.getAttribute(PATCHB::OFFLAT)), 8, 4, ZERO_FILL, POS_SIGN_TRUE,
false, 3, true);
output << toString(dv_cast<double>(input.getAttribute(PATCHB::OFFLONG)), 8, 4, ZERO_FILL, POS_SIGN_TRUE,
false, 3, true);
output << toString(dv_cast<int>(input.getAttribute(PATCHB::TRACK)), 3);
output << toString(dv_cast<double>(input.getAttribute(PATCHB::GSWEEP)), 6, 2);
output << toString(dv_cast<double>(input.getAttribute(PATCHB::SHEAR)), 8,
-1, ZERO_FILL, false, false, 3, true);
output << toString(dv_cast<int>(input.getAttribute(PATCHB::BATCH_NO)), 6,
-1, ZERO_FILL, false, false, 3, true);
}
catch (const bad_cast&)
{
return false;
}
if (output.tellp() < 0 || static_cast<uint64_t>(output.tellp()) > std::numeric_limits<size_t>::max())
{
return false;
}
sizeOut = static_cast<size_t>(output.tellp());
numBytesWritten = sizeOut - sizeIn;
return true;
}
示例11: sizeOut
bool Nitf::BandsaParser::fromDynamicObject(const DynamicObject& input, ostream& output, size_t& numBytesWritten,
string &errorMessage) const
{
if (output.tellp() < 0 || static_cast<uint64_t>(output.tellp()) > std::numeric_limits<size_t>::max())
{
return false;
}
size_t sizeIn = max<size_t>(0, static_cast<size_t>(output.tellp()));
size_t sizeOut(sizeIn);
try
{
output << toString(dv_cast<double>(input.getAttribute(BANDSA::ROW_SPACING)), 7, 4);
output << sizeString(dv_cast<string>(input.getAttribute(BANDSA::ROW_SPACING_UNITS)), 1);
output << toString(dv_cast<double>(input.getAttribute(BANDSA::COL_SPACING)), 7, 4);
output << sizeString(dv_cast<string>(input.getAttribute(BANDSA::COL_SPACING_UNITS)), 1);
output << toString(dv_cast<double>(input.getAttribute(BANDSA::FOCAL_LENGTH)), 6, 2);
unsigned int bandcount = dv_cast<unsigned int>(input.getAttribute(BANDSA::BANDCOUNT));
output << toString(bandcount, 4);
for (unsigned int i = 0; i < bandcount; ++i)
{
stringstream bandStreamStr;
bandStreamStr << "#" << i;
string bandStr(bandStreamStr.str());
string fieldName;
fieldName = BANDSA::BANDPEAK + bandStr;
output << toString(dv_cast<double>(input.getAttribute(fieldName)), 5, 2, ZERO_FILL, false, false, 3, true);
fieldName = BANDSA::BANDLBOUND + bandStr;
output << toString(dv_cast<double>(input.getAttribute(fieldName)), 5, 2, ZERO_FILL, false, false, 3, true);
fieldName = BANDSA::BANDUBOUND + bandStr;
output << toString(dv_cast<double>(input.getAttribute(fieldName)), 5, 2, ZERO_FILL, false, false, 3, true);
fieldName = BANDSA::BANDWIDTH + bandStr;
output << toString(dv_cast<double>(input.getAttribute(fieldName)), 5, 2, ZERO_FILL, false, false, 3, true);
fieldName = BANDSA::BANDCALDRK + bandStr;
output << toString(dv_cast<double>(input.getAttribute(fieldName)), 6, 1, ZERO_FILL, false, false, 3, true);
fieldName = BANDSA::BANDCALINC + bandStr;
output << toString(dv_cast<double>(input.getAttribute(fieldName)), 5, 2, ZERO_FILL, false, false, 3, true);
fieldName = BANDSA::BANDRESP + bandStr;
output << toString(dv_cast<double>(input.getAttribute(fieldName)), 5, 1, ZERO_FILL, false, false, 3, true);
fieldName = BANDSA::BANDASD + bandStr;
output << toString(dv_cast<double>(input.getAttribute(fieldName)), 5, 2, ZERO_FILL, false, false, 3, true);
fieldName = BANDSA::BANDGSD + bandStr;
output << toString(dv_cast<double>(input.getAttribute(fieldName)), 5, 2, ZERO_FILL, false, false, 3, true);
}
}
catch (const bad_cast&)
{
return false;
}
if (output.tellp() < 0 || static_cast<uint64_t>(output.tellp()) > std::numeric_limits<size_t>::max())
{
return false;
}
sizeOut = static_cast<size_t>(output.tellp());
numBytesWritten = sizeOut - sizeIn;
return true;
}
示例12: updateData
void EngrdaWidget::updateData(QTreeWidgetItem* pItem)
{
if (pItem != NULL && pItem->childCount() == 0)
{
mpValueType->setEnabled(true);
mpDataUnits->setEnabled(true);
mpData->setEnabled(true);
DynamicObject* pDo = reinterpret_cast<DynamicObject*>(qvariant_cast<void*>(pItem->data(0, Qt::UserRole)));
try
{
if (pDo != NULL)
{
Endian endian(BIG_ENDIAN_ORDER);
unsigned int cols = dv_cast<unsigned int>(pDo->getAttribute(Nitf::TRE::ENGRDA::ENGMTXC));
unsigned int rows = dv_cast<unsigned int>(pDo->getAttribute(Nitf::TRE::ENGRDA::ENGMTXR));
std::string type = dv_cast<std::string>(pDo->getAttribute(Nitf::TRE::ENGRDA::ENGTYP));
std::string units = dv_cast<std::string>(pDo->getAttribute(Nitf::TRE::ENGRDA::ENGDATU));
unsigned int dts = dv_cast<unsigned int>(pDo->getAttribute(Nitf::TRE::ENGRDA::ENGDTS));
if (dts == 0)
{
return;
}
const std::vector<unsigned char>& data = dv_cast<Blob>(pDo->getAttribute(Nitf::TRE::ENGRDA::ENGDATA));
if (data.empty())
{
return;
}
const void* pData = reinterpret_cast<const void*>(&data.front());
mpValueType->setText(QString("%1 byte %2").arg(dts).arg(QString::fromStdString(type)));
mpDataUnits->setText(QString::fromStdString(units));
mpData->setColumnCount(cols);
mpData->setRowCount(rows);
bool isAscii = false;
EncodingType encoding;
if (type == "S" && dts == 1)
{
encoding = INT1SBYTE;
}
else if (type == "S" && dts == 2)
{
encoding = INT1SBYTE;
}
else if (type == "S" && dts == 2)
{
encoding = INT2SBYTES;
}
else if (type == "S" && dts == 4)
{
encoding = INT4SBYTES;
}
else if (type == "R" && dts == 4)
{
encoding = FLT4BYTES;
}
else if (type == "R" && dts == 8)
{
encoding = FLT8BYTES;
}
else if (type == "C" && dts == 8)
{
encoding = FLT8COMPLEX;
}
else if (type == "I" && dts == 1)
{
encoding = INT1UBYTE;
}
else if (type == "I" && dts == 2)
{
encoding = INT2UBYTES;
}
else if (type == "I" && dts == 4)
{
encoding = INT4UBYTES;
}
else if (type == "A")
{
isAscii = true;
if (dts != 1)
{
return;
}
}
unsigned int datc = data.size() / dts;
if ((!encoding.isValid() && !isAscii) || datc != (rows * cols))
{
mpData->setEnabled(false);
return;
}
for (size_t row = 0; row < rows ; ++row)
{
for (size_t col = 0; col < cols; ++col)
{
if (isAscii)
{
// Not tested due to lack of test data
size_t idx = col + (row * cols); // datc chars per item
const QByteArray buf(reinterpret_cast<const char*>(pData) + idx, 1);
QTableWidgetItem* pItem = new QTableWidgetItem(QString(buf));
//.........这里部分代码省略.........
示例13: setFieldData
void FeatureClassDlg::setFieldData(QTreeWidgetItem* pItem, int column)
{
if (pItem == NULL)
{
return;
}
DynamicObject* pClass = getCurrentFeatureClass();
if (pClass == NULL)
{
return;
}
QString fieldName = pItem->text(0);
if (column == 0) // Name
{
QString oldFieldName = pItem->data(column, Qt::UserRole).toString();
if (fieldName == oldFieldName)
{
return;
}
if (mpFieldTree->findItems(fieldName, Qt::MatchExactly, column).count() > 1)
{
QMessageBox::warning(this, windowTitle(), "Another field exists with the same name. "
"Please choose a unique name for the field.");
pItem->setText(column, oldFieldName);
return;
}
DataVariant field = pClass->getAttribute(oldFieldName.toStdString());
pClass->removeAttribute(oldFieldName.toStdString());
pClass->setAttribute(fieldName.toStdString(), field);
pItem->setData(column, Qt::UserRole, QVariant(fieldName));
}
else // Type or Value
{
QString fieldType = pItem->text(1);
QString fieldValue = pItem->text(2);
if (column == 1) // Type
{
// If the type changed, ensure that the value is valid with the new type and reset the value if necessary
QString validateString = fieldValue;
int pos = 0;
if (fieldType == "int")
{
QIntValidator validator(this);
if (validator.validate(validateString, pos) != QValidator::Acceptable)
{
pItem->setText(2, "0");
return; // Return since this method will be called again as a result to changing the value text
}
}
else if (fieldType == "double")
{
QDoubleValidator validator(this);
if (validator.validate(fieldValue, pos) != QValidator::Acceptable)
{
pItem->setText(2, "0.0");
return; // Return since this method will be called again as a result to changing the value text
}
}
}
DataVariant field;
if (fieldType == "int")
{
int intValue = fieldValue.toInt();
field = DataVariant(intValue);
}
else if (fieldType == "double")
{
double doubleValue = fieldValue.toDouble();
field = DataVariant(doubleValue);
}
else if (fieldType == "string")
{
std::string stringValue = fieldValue.toStdString();
field = DataVariant(stringValue);
}
pClass->setAttribute(fieldName.toStdString(), field);
}
}