/* * Adds a row to the list, keeping the null row and '...' row in the correct positions. * Must copy data to new array due to limitations in the forms library. */ void ListBox::addRow(const std::string& str) { FIELD **pNewFields = new FIELD*[m_numRows + (m_editable ? 2 : 1)]; //Copy existing fields, up to the second last ('...') row for (int i = 0; i < m_numRows - 1; i++) { pNewFields[i] = m_pFields[i]; } //Create '...' row if (m_editable) { //Create new field at third-to-last index (before '...' row) createField(&pNewFields[m_numRows - 1], m_numRows - 1, str); createField(&pNewFields[m_numRows], m_numRows, "..."); set_field_userptr(pNewFields[m_numRows], (void*)true); } else { createField(&pNewFields[m_numRows], m_numRows, str); } //Create null field pNewFields[m_editable ? m_numRows + 1 : m_numRows] = 0; for (int i = 0; i < m_numRows; i++) { if (m_pFields[i] != 0) { free_field(m_pFields[i]); } } m_numRows++; m_pFields = pNewFields; createForm(); }
static cols_base* setup_field(IFieldsEdit* pFields, SEXP it, const wchar_t* str) { cols_base* item = NULL; switch (TYPEOF(it)) { case NILSXP: case SYMSXP: case RAWSXP: case LISTSXP: case CLOSXP: case ENVSXP: case PROMSXP: case LANGSXP: case SPECIALSXP: case BUILTINSXP: case CPLXSXP: case DOTSXP: case ANYSXP: case VECSXP: case EXPRSXP: case BCODESXP: case EXTPTRSXP: case WEAKREFSXP: case S4SXP: default: return NULL; case INTSXP: item = new cols_wrap<int>(it); item->pos = createField(str, esriFieldTypeInteger, pFields); break; case REALSXP: item = new cols_wrap<double>(it); item->pos = createField(str, esriFieldTypeDouble, pFields); break; case STRSXP: case CHARSXP: item = new cols_wrap<std::string>(it); item->pos = createField(str, esriFieldTypeString, pFields); break; case LGLSXP: item = new cols_wrap<bool>(it); item->pos = createField(str, esriFieldTypeInteger, pFields); break; } return item; }
void testWhereCompare() { // Date not implemented yet! // struct Field* dateField = createField("name", "1/1/1990", DATE); struct Field* textField = createField("name", "value", TEXT); struct Field* intField = createField("name", "1", INTEGER); struct Where* where1 = createWhere(textField, GREATHER_THAN); struct Where* where2 = createWhere(textField, EQUAL); struct Where* where3 = createWhere(intField, EQUAL); struct Where* where4 = createWhere(intField, LESS_THAN); struct Where* where5 = createWhere(intField, GREATHER_THAN_OR_EQ); // struct Where* where6 = createWhere(dateField, EQUAL); // struct Where* where7 = createWhere(dateField, LESS_THAN); // struct Where* where8 = createWhere(dateField, GREATHER_THAN); assert(!whereCompare(where1), "should be not eq!"); assert(whereCompare(where2), "should be eq!"); assert(whereCompare(where3), "should be eq!"); assert(!whereCompare(where4), "should be not eq!"); assert(whereCompare(where5), "should be eq!"); //assert(whereCompare(where3), "should be eq!"); //assert(!whereCompare(where4), "should be not eq!"); //assert(whereCompare(where5), "should be eq!"); }
void testRetrieve(void) { // This depends on testStore being run. because reasons! char names[FIELD_SIZE][NAME_LIMIT] = { "name4", "name2", "name3", "name1", }; FieldType types[FIELD_SIZE][1] = { INTEGER, TEXT, DATE, INTEGER, }; struct Field* projection = createFieldList(names, NULL, types, 4); struct Field* whereField = createField("name1", "2", INTEGER); struct Where* compare = createWhere(whereField, EQUAL); struct Command* selectCmd = createSelectCommand("table", projection, compare); struct Table* results = retrieve(selectCmd); printTable(results); assert(results->count == 1, "Did not retrieve correct number of records"); assert(strcmp(results->name, "table") == 0, "Table name was not set in the resultset"); assert(strcmp(results->tuples[0].fields[0].name, "name1") == 0 , "Problem with resultset"); assert(strcmp(results->tuples[0].fields[1].name, "name2") == 0 , "Problem with resultset"); assert(strcmp(results->tuples[0].fields[2].name, "name3") == 0 , "Problem with resultset"); assert(strcmp(results->tuples[0].fields[3].name, "name4") == 0 , "Problem with resultset"); assert(results->tuples[0].fields[4].name == 0 , "Problem with resultset"); // make sure null terminated assert(strcmp((char*) results->tuples[0].fields[0].value, "2") == 0 , "Problem with resultset"); assert(strcmp((char*) results->tuples[0].fields[1].value, "value2") == 0 , "Problem with resultset"); assert(strcmp((char*) results->tuples[0].fields[2].value, "1/1/2015") == 0 , "Problem with resultset"); assert(strcmp((char*) results->tuples[0].fields[3].value, "3") == 0 , "Problem with resultset"); assert(results->tuples[0].fields[4].name == 0 , "Problem with resultset"); }
/*! Returns a list of all the index's field names. Only generated fields are included in the list (see \l{isGenerated()}). If a \a prefix is specified, e.g. a table name, all fields are prefixed in the form: "\a{prefix}.<fieldname>" If \a verbose is true (the default), each field contains a suffix indicating an ASCending or DESCending sort order. Note that if you want to iterate over the list, you should iterate over a copy, e.g. \snippet doc/src/snippets/code/src_sql_kernel_qsqlindex.cpp 0 */ QStringList QSqlIndex::toStringList(const QString& prefix, bool verbose) const { QStringList s; for (int i = 0; i < count(); ++i) s += createField(i, prefix, verbose); return s; }
void SubmitFieldWidget::setFields(const QStringList & f) { // remove old fields for (int i = d->fieldEntries.size() - 1 ; i >= 0 ; i--) removeField(i); d->fields = f; if (!f.empty()) createField(f.front()); }
Field::Field(int size, int capacity, QWidget *parent) : QWidget(parent), ui(new Ui::Field) , m_hive(new Hive(size, capacity, this)) { ui->setupUi(this); createField(); connect(m_hive, SIGNAL(cellChanged(int,QPair<int,int>)), this, SLOT(onCellChanged(int,QPair<int,int>))); }
QString QSqlIndex::toString(const QString& prefix, const QString& sep, bool verbose) const { QString s; bool comma = false; for (int i = 0; i < count(); ++i) { if(comma) s += sep + QLatin1Char(' '); s += createField(i, prefix, verbose); comma = true; } return s; }
IHqlExpression * buildDiskFileViewerEcl(const char * logicalName, IHqlExpression * record) { //Add filepos to the incomming record structure... IHqlExpression * filePosAttr = createAttribute(virtualAtom, createAttribute(filepositionAtom)); OwnedHqlExpr filepos = createField(fileposName, makeIntType(8, false), NULL, filePosAttr); IHqlExpression * sizeofAttr = createAttribute(virtualAtom, createAttribute(sizeofAtom)); OwnedHqlExpr reclen = createField(recordlenName, makeIntType(2, false), NULL, sizeofAttr); HqlExprArray fields; unwindChildren(fields, record); fields.append(*filepos.getLink()); fields.append(*reclen.getLink()); OwnedHqlExpr newRecord = createRecord(fields); newRecord.setown(createSymbol(createIdentifierAtom("_SourceRecord_"), newRecord.getLink(), ob_private)); OwnedHqlExpr dataset = createNewDataset(createConstant(logicalName), newRecord.getLink(), createValue(no_thor), NULL, NULL, NULL); OwnedHqlExpr filtered = addFilter(dataset, filepos); OwnedHqlExpr projected = addSimplifyProject(filtered); OwnedHqlExpr output = addOutput(projected); return output.getClear(); }
void GenericDatabase::createFields(QSharedPointer<IXMLContent> configuration, IFactory *factory) { m_Logger->logTrace(__FILE__, __LINE__, "GenericDatabasePlugin", "void GenericDatabase::createFields(IXMLContent* configuration)"); QSharedPointer<XMLCollection> confFields = configuration.dynamicCast<XMLCollection>(); int count = confFields->get("count").dynamicCast<XMLElement>()->value().toInt(); for (int i = 1; i <= count; ++i) { QString fieldName = "field" + QString::number(i); QSharedPointer<IFieldDefinition> fDef = createField(confFields->get(fieldName), factory); m_Fields[fDef->name()] = fDef; m_FieldsBasedOnDatabase[fDef.dynamicCast<FieldDefinition>()->fieldNameInDatabase()] = fDef; } }
Map::Map(const sf::Vector2u& resolution, std::string folder) : _map_info { utils::ensureDirectoryEnd(folder) + "info" } , _object_size { (float)resolution.x / _nbr_tiles_x, (float)resolution.y / _nbr_tiles_y } , _view { mapPosToPixelPos( getPlayerStartingPosition() ), {static_cast<float>(resolution.x), static_cast<float>(resolution.y)} } , _player { _object_size, _view.getCenter() } { createField(folder); // Map limits _map_left_limit = 0; _map_right_limit = _objects.front().size() * _object_size.x; // Set view limits _view_left_limit = (_nbr_tiles_x / 2) * _object_size.x; _view_right_limit = _map_right_limit - _view_left_limit; }
// Handle change of a combo. Return "false" if the combo // is to be reset (refuse new field). bool SubmitFieldWidget::comboIndexChange(int pos, int index) { const QString newField = d->fieldEntries.at(pos).combo->itemText(index); // If the field is visible elsewhere: focus the existing one and refuse if (!d->allowDuplicateFields) { const int existingFieldIndex = d->findField(newField, pos); if (existingFieldIndex != -1) { d->focusField(existingFieldIndex); return false; } } // Empty value: just change the field if (d->fieldValue(pos).isEmpty()) return true; // Non-empty: Create a new field and reset the triggering combo createField(newField); return false; }
void testRetrieve(void) { // This depends on testStore being run. because reasons! char names[FIELD_SIZE][NAME_LIMIT] = { "name1", "name2", "name3", "name4", }; char values[FIELD_SIZE][VALUE_LIMIT] = { "1", "value2", "1/1/2015", "3", }; char names[FIELD_SIZE][NAME_LIMIT] = { "name4", "name2", "name3", "name1", }; FieldType types[FIELD_SIZE][1] = { INTEGER_t, TEXT_t, DATE_t, INTEGER_t, }; for (int i=0; i<4; i++) struct Field* projection[i] = createField(names[i], NULL, types[i]); struct Command* selectCmd = createSelectCommand("table", projection, NULL); struct Table* results = retrieve(selectCmd); assert(results->count == 2, "Did not retrieve correct number of records"); assert(strcmp(results->name, "table") == 0, "Table name was not set in the resultset"); assert(strcmp(results->tuples[0].fields[0].name, "name1") == 0 , "Problem with resultset"); assert(strcmp(results->tuples[0].fields[1].name, "name2") == 0 , "Problem with resultset"); assert(strcmp(results->tuples[0].fields[2].name, "name3") == 0 , "Problem with resultset"); assert(strcmp(results->tuples[0].fields[3].name, "name4") == 0 , "Problem with resultset"); assert(results->tuples[0].fields[4].name == 0 , "Problem with resultset"); // make sure null terminated assert(strcmp((char*) results->tuples[0].fields[0].value, "1") == 0 , "Problem with resultset"); assert(strcmp((char*) results->tuples[0].fields[1].value, "value2") == 0 , "Problem with resultset"); assert(strcmp((char*) results->tuples[0].fields[2].value, "1/1/2015") == 0 , "Problem with resultset"); assert(strcmp((char*) results->tuples[0].fields[3].value, "3") == 0 , "Problem with resultset"); assert(results->tuples[0].fields[4].name == 0 , "Problem with resultset"); assert(strcmp(results->tuples[1].fields[0].name, "name1") == 0 , "Problem with resultset"); assert(strcmp(results->tuples[1].fields[1].name, "name2") == 0 , "Problem with resultset"); assert(strcmp(results->tuples[1].fields[2].name, "name3") == 0 , "Problem with resultset"); assert(strcmp(results->tuples[1].fields[3].name, "name4") == 0 , "Problem with resultset"); assert(results->tuples[1].fields[4].name == 0 , "Problem with resultset"); // make sure null terminated assert(strcmp((char*) results->tuples[1].fields[0].value, "1") == 0 , "Problem with resultset"); assert(strcmp((char*) results->tuples[1].fields[1].value, "value2") == 0 , "Problem with resultset"); assert(strcmp((char*) results->tuples[1].fields[2].value, "1/1/2015") == 0 , "Problem with resultset"); assert(strcmp((char*) results->tuples[1].fields[3].value, "3") == 0 , "Problem with resultset"); assert(results->tuples[1].fields[4].name == 0 , "Problem with resultset"); }
ListBox::ListBox(Panel *pPanel, int x, int y, int w, int h, bool editable) : Component(pPanel, x, y, w, h) { setSelectable(true); m_editable = true;//editable; TODO: revisit m_numRows = m_editable ? 1 : 0; m_pForm = 0; m_curRow = 0; //Create field array, init to null if (m_editable) { m_pFields = new FIELD*[2]; createField(&m_pFields[0], 0, "..."); set_field_userptr(m_pFields[0], (void*)true); m_pFields[1] = 0; } else { m_pFields = new FIELD*[1]; m_pFields[0] = 0; } createForm(); }
void lets_draw(void){ glClear(GL_COLOR_BUFFER_BIT); createField(); glFlush(); }
IHqlExpression * PositionTransformer::createTransformed(IHqlExpression * _expr) { OwnedHqlExpr transformed = NewHqlTransformer::createTransformed(_expr); switch (transformed->getOperator()) { case no_table: { IHqlExpression * mode = transformed->queryChild(2); HqlExprArray fields; HqlExprArray args; if (mode->getOperator() == no_thor) { unwindChildren(fields, transformed->queryChild(1)); IHqlExpression * filePosAttr = createComma(createAttribute(virtualAtom, createAttribute(filepositionAtom)), insertedAttr.getLink()); IHqlExpression * sizeofAttr = createComma(createAttribute(virtualAtom, createAttribute(sizeofAtom)), insertedAttr.getLink()); fields.append(*createField(fileposName, makeIntType(8, false), NULL, filePosAttr)); fields.append(*createField(recordlenName, makeIntType(2, false), NULL, sizeofAttr)); unwindChildren(args, transformed); args.replace(*createRecord(fields), 1); return transformed->clone(args); } } break; case no_iterate: case no_hqlproject: { HqlExprArray args; HqlExprArray assigns; IHqlExpression * transform = transformed->queryChild(1); unwindChildren(args, transformed); unwindChildren(assigns, transform); IHqlExpression * inRecord = transformed->queryChild(0)->queryRecord(); IHqlExpression * outRecord = transform->queryRecord(); HqlExprArray fields; unwindChildren(fields, outRecord); ForEachChild(idx, inRecord) { IHqlExpression * child = inRecord->queryChild(idx); if (child->hasProperty(insertedAtom)) { IHqlExpression * newTarget = createField(child->queryName(), child->getType(), LINK(child), insertedAttr.getLink()); fields.append(*newTarget); assigns.append(*createValue(no_assign, makeVoidType(), newTarget, createSelectExpr(createValue(no_left), LINK(newTarget)))); } } IHqlExpression * newRecord = createRecord(fields); args.replace(*createValue(no_transform, newRecord->getType(), assigns), 1); return transformed->clone(args); } break; case no_join: //only ok if join first case no_rollup: case no_newaggregate: case no_aggregate: fail(); break; case no_usertable: case no_selectfields: { IHqlExpression * grouping = transformed->queryChild(2); if (grouping && (grouping->getOperator() != no_attr)) fail(); IHqlExpression * record = transformed->queryRecord(); HqlExprArray fields; unwindChildren(fields, transformed->queryChild(1)); ForEachChild(idx, record) { IHqlExpression * child = record->queryChild(idx); if (child->hasProperty(insertedAtom)) fields.append(*createField(child->queryName(), child->getType(), LINK(child), insertedAttr.getLink())); } HqlExprArray args; unwindChildren(args, transformed); args.replace(*createRecord(fields), 1); return transformed->clone(args); }
SEXP R_dataframe2dataset(SEXP dtaframe, SEXP path, SEXP shape_columns) { if (!Rf_isFrame(dtaframe)) return showError<false>(L"argument 0 is not a data.frame"), R_NilValue; //same as narray_tools.cpp std::wstring dataset_name; tools::copy_to(path, dataset_name); struct _cleanup { typedef std::vector<cols_base*> c_type; std::vector<std::string> name; c_type c; //std::vector<c_type::const_iterator> shape; c_type shape; ~_cleanup() { for (size_t i = 0; i < c.size(); i++) delete c[i]; for (size_t i = 0; i < shape.size(); i++) delete shape[i]; } }cols; //cols.name = df.attr("names"); tools::getNames(dtaframe, cols.name); if (cols.name.empty()) return showError<false>(L"data.frame has 0 column"), R_NilValue; if (tools::size(dtaframe) != cols.name.size()) return showError<false>(L"unknown"), R_NilValue; CComPtr<IGPUtilities> ipDEUtil; if (ipDEUtil.CoCreateInstance(CLSID_GPUtilities) != S_OK) return showError<true>(L"IDEUtilitiesImpl - CoCreateInstance has failed"), R_NilValue; HRESULT hr; //cols.c.resize(cols.name.size(), NULL); bool isShape = false; if (shape_columns != R_NilValue) { std::vector<std::string> shapes; tools::copy_to(shape_columns, shapes); if (shapes.size() < 2 || shapes.size() > 4) return showError<false>(L"shape expecting 2 strings"), NULL; isShape = true; for (size_t i = 0; i < shapes.size(); i++) { std::vector<std::string>::iterator it = std::find(cols.name.begin(), cols.name.end(), shapes[i]); if (it == cols.name.end()) return showError<false>(L"cannot find shape in data.frame"), NULL; size_t pos = std::distance(cols.name.begin(), it); cols.shape.push_back(new cols_wrap<double>(VECTOR_ELT(dtaframe, pos))); //cols.shape.[i] = cols.c.begin() + pos; it->clear(); } } CComPtr<IName> ipName; if (isShape) hr = ipDEUtil->CreateFeatureClassName(CComBSTR(dataset_name.c_str()), &ipName); else hr = ipDEUtil->CreateTableName(CComBSTR(dataset_name.c_str()), &ipName); CComQIPtr<IDatasetName> ipDatasetName(ipName); CComPtr<IWorkspaceName> ipWksName; CComQIPtr<IWorkspace> ipWks; if (hr == S_OK) hr = ipDatasetName->get_WorkspaceName(&ipWksName); if (hr == S_OK) { CComPtr<IUnknown> ipUnk; hr = CComQIPtr<IName>(ipWksName)->Open(&ipUnk); ipWks = ipUnk; } if (hr != S_OK) return showError<true>(L"invalid table name"), R_NilValue; CComQIPtr<IFeatureWorkspace> ipFWKS(ipWks); ATLASSERT(ipFWKS); if (!ipFWKS) return showError<true>(L"not a FeatureWorkspace"), R_NilValue; CComBSTR bstrTableName; ipDatasetName->get_Name(&bstrTableName); /* CComQIPtr<IWorkspaceSchemaImpl> ipWSchema(ipWks); if (ipWSchema) { VARIANT_BOOL b = VARIANT_FALSE; ipWSchema->TableExists(bstrTableName, &b); if (b != VARIANT_FALSE) return ::Rf_error("table Exists"), NULL; }*/ CComPtr<IFieldsEdit> ipFields; hr = ipFields.CoCreateInstance(CLSID_Fields); if (hr != S_OK) return showError<true>(L"CoCreateInstance"), R_NilValue; //if (!createField(NULL, esriFieldTypeOID, ipFields)) // return NULL; if (isShape) { long pos = createField(NULL, esriFieldTypeGeometry, ipFields); CComPtr<IGeometryDef> ipGeoDef; CComPtr<IField> ipField; ipFields->get_Field(pos, &ipField); ipField->get_GeometryDef(&ipGeoDef); CComQIPtr<IGeometryDefEdit> ipGeoDefEd(ipGeoDef); ipGeoDefEd->put_GeometryType(esriGeometryPoint); CComQIPtr<ISpatialReference> ipSR(g_lastUsedSR); if (!ipSR) { ipSR.CoCreateInstance(CLSID_UnknownCoordinateSystem); CComQIPtr<ISpatialReferenceResolution> ipSRR(ipSR); if (ipSRR) FIX_DEFAULT_SR(ipSRR); } ipGeoDefEd->putref_SpatialReference(ipSR); } for (size_t i = 0; i < cols.name.size(); i++) { if (cols.name[i].empty()) continue; const char* str = cols.name[i].c_str(); cols_base* item = NULL; SEXP it = VECTOR_ELT(dtaframe, i); switch (TYPEOF(it)) { case NILSXP: case SYMSXP: case RAWSXP: case LISTSXP: case CLOSXP: case ENVSXP: case PROMSXP: case LANGSXP: case SPECIALSXP: case BUILTINSXP: case CPLXSXP: case DOTSXP: case ANYSXP: case VECSXP: case EXPRSXP: case BCODESXP: case EXTPTRSXP: case WEAKREFSXP: case S4SXP: default: return showError<false>(L"unsupported datat.field column type"), NULL; case INTSXP: item = new cols_wrap<int>(it); item->pos = createField(str, esriFieldTypeInteger, ipFields); break; case REALSXP: item = new cols_wrap<double>(it); item->pos = createField(str, esriFieldTypeDouble, ipFields); break; case STRSXP: case CHARSXP: item = new cols_wrap<std::string>(it); item->pos = createField(str, esriFieldTypeString, ipFields); break; case LGLSXP: item = new cols_wrap<bool>(it); item->pos = createField(str, esriFieldTypeInteger, ipFields); break; } ATLASSERT(item); cols.c.push_back(item); item->name_ref = &cols.name[i]; } CComPtr<IFieldChecker> ipFieldChecker; ipFieldChecker.CoCreateInstance(CLSID_FieldChecker); if (ipFieldChecker) { ipFieldChecker->putref_ValidateWorkspace(ipWks); long error = 0; //fix fields names CComPtr<IFields> ipFixedFields; CComPtr<IEnumFieldError> ipEError; hr = ipFieldChecker->Validate(ipFields, &ipEError, &ipFixedFields); if (hr != S_OK) return showError<true>(L"validate fields failed"), NULL; if (ipFixedFields) { ipFields = ipFixedFields; for (size_t c = 0; c < cols.c.size(); c++) { CComPtr<IField> ipFixedField; ipFixedFields->get_Field(cols.c[c]->pos, &ipFixedField); _bstr_t name; ipFixedField->get_Name(name.GetAddress()); cols.c[c]->name_ref->assign(name); } } } CComPtr<IUID> ipUID; ipUID.CoCreateInstance(CLSID_UID); CComQIPtr<ITable> ipTableNew; CComBSTR keyword(L""); hr = E_FAIL; if (isShape) { if (ipUID) { OLECHAR buf[256]; ::StringFromGUID2(CLSID_Feature, buf, 256); ipUID->put_Value(CComVariant(buf)); } CComPtr<IFeatureClass> ipFClass; hr = ipFWKS->CreateFeatureClass(bstrTableName, ipFields, ipUID, 0, esriFTSimple, CComBSTR(L"Shape"), keyword, &ipFClass); ipTableNew = ipFClass; } else { if (ipUID) { OLECHAR buf[256]; ::StringFromGUID2(CLSID_Row, buf, 256); ipUID->put_Value(CComVariant(buf)); } hr = ipFWKS->CreateTable(bstrTableName, ipFields, ipUID, 0, keyword, &ipTableNew); } if (hr != S_OK) return showError<true>(L"validate fields failed"), R_NilValue; CComVariant oid; CComPtr<ICursor> ipCursor; CComPtr<IRowBuffer> ipRowBuffer; hr = ipTableNew->Insert(VARIANT_TRUE, &ipCursor); if (hr != S_OK) return showError<true>(L"Insert cursor failed"), R_NilValue; hr = ipTableNew->CreateRowBuffer(&ipRowBuffer); if (hr != S_OK) return showError<true>(L"Insert cursor failed"), R_NilValue; //re-map fields for (size_t c = 0; c < cols.c.size(); c++) ipCursor->FindField(CComBSTR(cols.c[c]->name_ref->c_str()), &(cols.c[c]->pos)); R_len_t n = tools::size(VECTOR_ELT(dtaframe, 0)); for (R_len_t i = 0; i < n; i++) { //ATLTRACE("\n"); for (size_t c = 0; c < cols.c.size(); c++) { if (cols.c[c]->pos < 0) continue; CComVariant val; cols.c[c]->get(i, val); hr = ipRowBuffer->put_Value(cols.c[c]->pos, val); if (hr != S_OK) return showError<true>(L"insert row value failed"), R_NilValue; //ATLTRACE(" [%i]=%f",cols[c]->pos, (float)val.dblVal); } VARIANT oid; if (isShape) { CComQIPtr<IPoint> ipPoint; ipPoint.CoCreateInstance(CLSID_Point); CComVariant valX, valY; cols.shape[0]->get(i, valX); cols.shape[1]->get(i, valY); ipPoint->PutCoords(valX.dblVal, valY.dblVal); CComQIPtr<IFeatureBuffer> ipFBuffer(ipRowBuffer); ATLASSERT(ipFBuffer); hr = ipFBuffer->putref_Shape(ipPoint); if (hr != S_OK) return showError<true>(L"insert shape failed"), R_NilValue; } hr = ipCursor->InsertRow(ipRowBuffer, &oid); if (hr != S_OK) return showError<true>(L"insert row failed"), R_NilValue; } return R_NilValue; }
SEXP R_export2dataset(SEXP path, SEXP dataframe, SEXP shape, SEXP shape_info) { std::wstring dataset_name; tools::copy_to(path, dataset_name); struct _cleanup { typedef std::vector<cols_base*> c_type; std::vector<std::wstring> name; c_type c; //std::vector<c_type::const_iterator> shape; c_type shape; ~_cleanup() { for (size_t i = 0; i < c.size(); i++) delete c[i]; for (size_t i = 0; i < shape.size(); i++) delete shape[i]; } }cols; shape_extractor extractor; bool isShape = extractor.init(shape, shape_info) == S_OK; //SEXP sinfo = Rf_getAttrib(shape, Rf_mkChar("shape_info")); //cols.name = df.attr("names"); tools::getNames(dataframe, cols.name); //tools::vectorGeneric shape_info(sinfo); //std::string gt_type; //tools::copy_to(shape_info.at("type"), gt_type); esriGeometryType gt = extractor.type();//str2geometryType(gt_type.c_str()); R_xlen_t n = 0; ATLTRACE("dataframe type:%s", Rf_type2char(TYPEOF(dataframe))); if (Rf_isVectorList(dataframe)) { size_t k = tools::size(dataframe); cols.name.resize(k); for (size_t i = 0; i < k; i++) { n = std::max(n, tools::size(VECTOR_ELT(dataframe, (R_xlen_t)i))); if (cols.name[i].empty()) cols.name[i] = L"data"; } } else { n = tools::size(dataframe); ATLASSERT(cols.name.empty()); } if (isShape == false && n == 0) return showError<false>(L"nothing to save"), R_NilValue; if (isShape && n != extractor.size() ) return showError<false>(L"length of shape != data.frame"), R_NilValue; CComPtr<IGPUtilities> ipDEUtil; if (ipDEUtil.CoCreateInstance(CLSID_GPUtilities) != S_OK) return showError<true>(L"IDEUtilitiesImpl - CoCreateInstance has failed"), R_NilValue; HRESULT hr = 0; CComPtr<IName> ipName; if (isShape) hr = ipDEUtil->CreateFeatureClassName(CComBSTR(dataset_name.c_str()), &ipName); else hr = ipDEUtil->CreateTableName(CComBSTR(dataset_name.c_str()), &ipName); CComQIPtr<IDatasetName> ipDatasetName(ipName); CComPtr<IWorkspaceName> ipWksName; CComQIPtr<IWorkspace> ipWks; if (hr == S_OK) hr = ipDatasetName->get_WorkspaceName(&ipWksName); if (hr == S_OK) { CComPtr<IUnknown> ipUnk; hr = CComQIPtr<IName>(ipWksName)->Open(&ipUnk); ipWks = ipUnk; } if (hr != S_OK) return showError<true>(L"invalid table name"), R_NilValue; CComQIPtr<IFeatureWorkspace> ipFWKS(ipWks); ATLASSERT(ipFWKS); if (!ipFWKS) return showError<true>(L"not a FeatureWorkspace"), R_NilValue; CComBSTR bstrTableName; ipDatasetName->get_Name(&bstrTableName); CComPtr<IFieldsEdit> ipFields; hr = ipFields.CoCreateInstance(CLSID_Fields); if (hr != S_OK) return showError<true>(L"CoCreateInstance"), R_NilValue; createField(NULL, esriFieldTypeOID, ipFields); CComPtr<ISpatialReference> ipSR; if (isShape) { long pos = createField(NULL, esriFieldTypeGeometry, ipFields); CComPtr<IGeometryDef> ipGeoDef; CComPtr<IField> ipField; ipFields->get_Field(pos, &ipField); ipField->get_GeometryDef(&ipGeoDef); CComQIPtr<IGeometryDefEdit> ipGeoDefEd(ipGeoDef); ipGeoDefEd->put_GeometryType(gt); ipGeoDefEd->putref_SpatialReference(extractor.sr()); } if (cols.name.empty()) { cols.name.push_back(L"data"); cols_base* item = setup_field(ipFields, dataframe, cols.name[0].c_str()); if (!item) return showError<false>(L"unsupported datat.field column type"), NULL; cols.c.push_back(item); item->name_ref = &cols.name[0]; } else for (size_t i = 0; i < cols.name.size(); i++) { if (cols.name[i].empty()) continue; const wchar_t* str = cols.name[i].c_str(); SEXP it = VECTOR_ELT(dataframe, (R_len_t)i); cols_base* item = setup_field(ipFields, it, str); if (!item) return showError<false>(L"unsupported datat.field column type"), NULL; cols.c.push_back(item); item->name_ref = &cols.name[i]; } CComPtr<IFieldChecker> ipFieldChecker; ipFieldChecker.CoCreateInstance(CLSID_FieldChecker); if (ipFieldChecker) { ipFieldChecker->putref_ValidateWorkspace(ipWks); long error = 0; //fix fields names CComPtr<IFields> ipFixedFields; CComPtr<IEnumFieldError> ipEError; hr = ipFieldChecker->Validate(ipFields, &ipEError, &ipFixedFields); if (hr != S_OK) return showError<true>(L"validate fields failed"), NULL; if (ipFixedFields) { ipFields = ipFixedFields; for (size_t c = 0; c < cols.c.size(); c++) { CComPtr<IField> ipFixedField; ipFixedFields->get_Field(cols.c[c]->pos, &ipFixedField); _bstr_t name; ipFixedField->get_Name(name.GetAddress()); cols.c[c]->name_ref->assign(name); } } } CComPtr<IUID> ipUID; ipUID.CoCreateInstance(CLSID_UID); if (ipUID) { OLECHAR buf[256]; ::StringFromGUID2(isShape ? CLSID_Feature : CLSID_Row, buf, 256); ipUID->put_Value(CComVariant(buf)); } CComQIPtr<ITable> ipTableNew; CComBSTR keyword(L""); hr = E_FAIL; if (isShape) { CComPtr<IFeatureClass> ipFClass; hr = ipFWKS->CreateFeatureClass(bstrTableName, ipFields, ipUID, 0, esriFTSimple, CComBSTR(L"Shape"), keyword, &ipFClass); ipTableNew = ipFClass; } else { hr = ipFWKS->CreateTable(bstrTableName, ipFields, ipUID, 0, keyword, &ipTableNew); } if (hr != S_OK) { std::wstring err_txt(isShape ? L"Create FeatureClass :" : L"Create Table :"); err_txt += bstrTableName; err_txt += L" has failed"; return showError<true>(err_txt.c_str()), R_NilValue; } CComVariant oid; CComPtr<ICursor> ipCursor; CComPtr<IRowBuffer> ipRowBuffer; hr = ipTableNew->Insert(VARIANT_TRUE, &ipCursor); if (hr != S_OK) return showError<true>(L"Insert cursor failed"), R_NilValue; hr = ipTableNew->CreateRowBuffer(&ipRowBuffer); if (hr != S_OK) return showError<true>(L"Insert cursor failed"), R_NilValue; //re-map fields CComPtr<IFields> ipRealFields; ipCursor->get_Fields(&ipRealFields); for (size_t c = 0; c < cols.c.size(); c++) { ipRealFields->FindField(CComBSTR(cols.c[c]->name_ref->c_str()), &(cols.c[c]->pos)); CComPtr<IField> ipField; ipRealFields->get_Field(cols.c[c]->pos, &ipField); VARIANT_BOOL b = VARIANT_FALSE; ipField->get_IsNullable(&b); if (b == VARIANT_FALSE) { esriFieldType ft = esriFieldTypeInteger; ipField->get_Type(&ft); switch(ft) { case esriFieldTypeInteger: cols.c[c]->vNULL = 0;//std::numeric_limits<int>::min(); break; case esriFieldTypeDouble: cols.c[c]->vNULL = 0.0;//-std::numeric_limits<double>::max(); break; case esriFieldTypeString: cols.c[c]->vNULL = L""; } } } CComQIPtr<IFeatureBuffer> ipFBuffer(ipRowBuffer); for (R_len_t i = 0; i < n; i++) { //ATLTRACE("\n"); for (size_t c = 0; c < cols.c.size(); c++) { if (cols.c[c]->pos < 0) continue; CComVariant val; cols.c[c]->get(i, val); if (val.vt == VT_NULL) hr = ipRowBuffer->put_Value(cols.c[c]->pos, cols.c[c]->vNULL); else hr = ipRowBuffer->put_Value(cols.c[c]->pos, val); if (FAILED(hr)) return showError<true>(L"insert row value failed"), R_NilValue; } VARIANT oid; if (isShape) { ATLASSERT(ipFBuffer); CComQIPtr<IGeometry> ipNewShape; hr = extractor.at(i, &ipNewShape); if (hr != S_OK) return R_NilValue; hr = ipFBuffer->putref_Shape(ipNewShape); if (FAILED(hr)) return showError<true>(L"insert shape failed"), R_NilValue; } hr = ipCursor->InsertRow(ipRowBuffer, &oid); if (hr != S_OK) return showError<true>(L"insert row failed"), R_NilValue; } return R_NilValue; }
void Node::addEventOut(const char * name, int fieldType) { addEventOut(name, createField(fieldType)); }
void Node::addField(const char * name, int fieldType) { addField(name, createField(fieldType)); }
void CertificateDialog::updateCertificate() { const QSslCertificate certificate(m_certificates.value(m_ui->chainItemView->currentIndex().data(Qt::UserRole).toInt())); m_ui->detailsItemView->getSourceModel()->clear(); createField(VersionField); createField(SerialNumberField); createField(SignatureAlgorithmField); createField(IssuerField); QStandardItem *validityItem(createField(ValidityField)); validityItem->setFlags(Qt::ItemIsEnabled); createField(ValidityNotBeforeField, validityItem); createField(ValidityNotAfterField, validityItem); createField(SubjectField); QStandardItem *publicKeyItem(createField(PublicKeyField)); publicKeyItem->setFlags(Qt::ItemIsEnabled); createField(PublicKeyAlgorithmField, publicKeyItem); createField(PublicKeyValueField, publicKeyItem); QStandardItem *extensionsItem(createField(ExtensionsField)); extensionsItem->setFlags(Qt::ItemIsEnabled); extensionsItem->setEnabled(certificate.extensions().count() > 0); for (int i = 0; i < certificate.extensions().count(); ++i) { QString title(certificate.extensions().at(i).name()); if (title == QLatin1String("authorityKeyIdentifier")) { title = tr("Authority Key Identifier"); } else if (title == QLatin1String("subjectKeyIdentifier")) { title = tr("Subject Key Identifier"); } else if (title == QLatin1String("keyUsage")) { title = tr("Key Usage"); } else if (title == QLatin1String("certificatePolicies")) { title = tr("Certificate Policies"); } else if (title == QLatin1String("policyMappings")) { title = tr("Policy Mappings"); } else if (title == QLatin1String("subjectAltName")) { title = tr("Subject Alternative Name"); } else if (title == QLatin1String("issuerAltName")) { title = tr("Issuer Alternative Name"); } else if (title == QLatin1String("subjectDirectoryAttributes")) { title = tr("Subject Directory Attributes"); } else if (title == QLatin1String("basicConstraints")) { title = tr("Basic Constraints"); } else if (title == QLatin1String("nameConstraints")) { title = tr("Name Constraints"); } else if (title == QLatin1String("policyConstraints")) { title = tr("Policy Constraints"); } else if (title == QLatin1String("extendedKeyUsage")) { title = tr("Extended Key Usage"); } else if (title == QLatin1String("crlDistributionPoints")) { title = tr("CRL Distribution Points"); } else if (title == QLatin1String("inhibitAnyPolicy")) { title = tr("Inhibit Any Policy"); } else if (title == QLatin1String("freshestCRL")) { title = tr("Delta CRL Distribution Point"); } else if (title == QLatin1String("authorityInfoAccess")) { title = tr("Authority Information Access"); } else if (title == QLatin1String("subjectInfoAccess")) { title = tr("Subject Information Access"); } QMap<int, QVariant> data; data[Qt::DisplayRole] = title; data[Qt::UserRole + 1] = i; createField(ExtensionField, extensionsItem, data); } QStandardItem *digestItem(createField(DigestField)); createField(DigestSha256Field, digestItem); createField(DigestSha1Field, digestItem); m_ui->detailsItemView->expandAll(); m_ui->valueTextEdit->clear(); }