bool DefinitionParser::createMultiFrameSprite (QDomNode& frame, const Content::Class clazz) { QDomNode parent = frame.parentNode(); QDomNamedNodeMap attributes = parent.attributes(); const QString childName = clazz == Content::MOVIECLIP ? ::NODE_FRAME : ::NODE_OBJECT; const QString className = attributes.namedItem(ATTR_CLASS).nodeValue(); const QString basePath = attributes.namedItem(ATTR_PATH).nodeValue(); const QString absBasePath = _targetDir.absoluteFilePath(basePath); struct SpriteAsset* sprite = NULL; if (!QFile::exists(absBasePath)) { info("base path \'" + absBasePath + "\' does not exist"); return false; } while (!frame.isNull()) { QDomElement e = frame.toElement(); QDomNamedNodeMap attr = frame.attributes(); checkAttributes(frame); frame = frame.nextSibling(); if (e.isNull()) { continue; } const QString tn = e.tagName(); if (tn != childName) { warnInvalidTag(tn, frame.parentNode().nodeName()); continue; } const QString relpath = attr.namedItem(ATTR_PATH).nodeValue(); if (attr.isEmpty() || relpath.isEmpty()) { warnMissingAttr(ATTR_PATH, tn); continue; } const QString path = _targetDir.absoluteFilePath(basePath + relpath); if (!checkPathExists(path)) { continue; } struct AssetBit asset; asset.name = attr.namedItem(ATTR_NAME).nodeValue(); asset.path = _tempDir.relativeFilePath(path); copyAttributes(&asset, attr); if (!sprite) { sprite = new SpriteAsset(); } sprite->assets.push_back(asset); } if (sprite) { sprite->clazz = clazz; sprite->name = className; copyAttributes(sprite, attributes); _assets[className] = sprite; } return true; }
SEXP make_unique (SEXP index_, SEXP eps_) { int P = 0, i; int len = length(index_); double eps = asReal(eps_); if (TYPEOF(index_) == INTSXP) { PROTECT(index_ = coerceVector(index_, REALSXP)); P++; } SEXP newindex_ = PROTECT(allocVector(REALSXP, len)); P++; copyAttributes(index_, newindex_); double *newindex_real = REAL(newindex_); memcpy(REAL(newindex_), REAL(index_), len * sizeof(double)); double last_index = newindex_real[0]; int warn_once = 1; for(i=1; i<len; i++) { if(newindex_real[i] <= newindex_real[i-1]) { if(warn_once && last_index != newindex_real[i]) { warn_once = 0; warning("index value is unique but will be replaced; it is less than the cumulative epsilon for the preceding duplicate index values"); } newindex_real[i] = newindex_real[i-1] + eps; } } UNPROTECT(P); return newindex_; }
QString Sequence::getAlterDefinition(BaseObject *object) { Sequence *seq=dynamic_cast<Sequence *>(object); if(!seq) throw Exception(ERR_OPR_NOT_ALOC_OBJECT,__PRETTY_FUNCTION__,__FILE__,__LINE__); try { Table *table=nullptr; attribs_map attribs; attributes[ParsersAttributes::ALTER_CMDS]=BaseObject::getAlterDefinition(object); if((this->owner_col && !seq->owner_col) || (!this->owner_col && seq->owner_col) || (this->owner_col && seq->owner_col && this->owner_col->getSignature()!=seq->owner_col->getSignature())) { if(seq->owner_col) { attribs[ParsersAttributes::OWNER_COLUMN]=seq->owner_col->getSignature(); table=dynamic_cast<Table *>(seq->owner_col->getParentTable()); if(table) { attribs[ParsersAttributes::TABLE]=table->getName(true); attribs[ParsersAttributes::COLUMN]=seq->owner_col->getName(true); } } else attribs[ParsersAttributes::OWNER_COLUMN]=ParsersAttributes::UNSET; } if(this->increment!=seq->increment) attribs[ParsersAttributes::INCREMENT]=seq->increment; if(this->min_value!=seq->min_value) attribs[ParsersAttributes::MIN_VALUE]=seq->min_value; if(this->max_value!=seq->max_value) attribs[ParsersAttributes::MAX_VALUE]=seq->max_value; if(this->start!=seq->start) attribs[ParsersAttributes::START]=seq->start; if(this->cache!=seq->cache) attribs[ParsersAttributes::CACHE]=seq->cache; if(this->cycle!=seq->cycle) attribs[ParsersAttributes::CYCLE]=(seq->cycle ? ParsersAttributes::_TRUE_ : ParsersAttributes::UNSET); copyAttributes(attribs); return(BaseObject::getAlterDefinition(this->getSchemaName(), attributes, false, true)); } catch(Exception &e) { throw Exception(e.getErrorMessage(),e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__,&e); } }
bool DefinitionParser::createSingleFrameAsset (QDomNode& node, const Content::Class clazz, const QString& tag) { QDomNamedNodeMap attr = node.attributes(); const QString name = attr.namedItem(ATTR_CLASS).nodeValue(); const QString pathattr = attr.namedItem(ATTR_PATH).nodeValue(); if (pathattr.isEmpty()) { warnMissingAttr(ATTR_PATH, tag); return false; } const QString path = _targetDir.absoluteFilePath(pathattr); if (!checkPathExists(path)) { return false; } if (name.isEmpty()) { warnMissingAttr(ATTR_CLASS, tag); return false; } if (clazz == Content::SPRITE || clazz == Content::MOVIECLIP) { struct AssetBit asset; asset.path = _tempDir.relativeFilePath(path); copyAttributes(&asset, attr); struct SpriteAsset* sprite = new SpriteAsset(); sprite->assets.push_back(asset); sprite->clazz = clazz; sprite->name = name; _assets[name] = sprite; } else { struct Asset* common = new Asset(); common->path = path; common->name = name; _assets[name] = common; } return true; }
list* addRowToTable(list* row, list* table){ list* tableDown=table->down; if(tableDown==NULL){ tableDown= (list*) malloc(sizeof(list)); table->down= tableDown; } list* searchNode=searchRight(row->nodeName, tableDown); if(searchNode==NULL){ list* newNode=createListNode(row->nodeName); copyAttributes(newNode,row->attrList); addRight(newNode, tableDown); list*rowColumns= row->down; if(rowColumns==NULL || rowColumns->right==NULL){ yyerror("ERROR\n"); } rowColumns= rowColumns->right; while(rowColumns !=NULL){ addColumnToRow(rowColumns, newNode); rowColumns= rowColumns->right; } }else{ yyerror("ERROR\n"); } }
bool SetBrushFaceAttributesTool::performCopy(const InputState& inputState, const bool applyToBrush) { if (!applies(inputState)) return false; MapDocumentSPtr document = lock(m_document); const Model::BrushFaceList& selectedFaces = document->selectedBrushFaces(); if (selectedFaces.size() != 1) return false; const Model::Hit& hit = inputState.pickResult().query().pickable().type(Model::Brush::BrushHit).occluded().first(); if (!hit.isMatch()) return false; Model::BrushFace* source = selectedFaces.front(); Model::BrushFace* targetFace = Model::hitToFace(hit); Model::Brush* targetBrush = targetFace->brush(); const Model::BrushFaceList targetList = applyToBrush ? targetBrush->faces() : Model::BrushFaceList(1, targetFace); const Transaction transaction(document); document->deselectAll(); document->select(targetList); if (copyAttributes(inputState)) document->setFaceAttributes(source->attribs()); else document->setTexture(source->texture()); document->deselectAll(); document->select(source); return true; }
SEXP make_unique (SEXP index, SEXP eps_) { SEXP newindex; int P=0, len, i; len=length(index); double eps = asReal(eps_); double *index_real, *newindex_real; if( TYPEOF(index) == INTSXP) { PROTECT(index = coerceVector(index,REALSXP)); P++; } PROTECT(newindex = allocVector(REALSXP, length(index))); P++; copyAttributes(index, newindex); index_real = REAL(index); newindex_real = REAL(newindex); newindex_real[0] = index_real[0]; for(i=1; i<len; i++) { if(index_real[i-1] == index_real[i]) newindex_real[i] = newindex_real[i-1] + eps; else newindex_real[i] = index_real[i]; } UNPROTECT(P); return(newindex); }
SEXP make_index_unique (SEXP x_, SEXP eps_) { SEXP result; PROTECT(result = coredata_xts(x_)); copyAttributes(x_, result); /* copy all attrib except index, and dim-related */ setAttrib(result, xts_IndexSymbol, make_unique(getAttrib(x_, xts_IndexSymbol), eps_)); UNPROTECT(1); return(result); }
GMSFerryItem::GMSFerryItem(GMSFerryItem* ferry) : OldFerryItem(), GMSItem(GMSItem::GDF) { initMembers(MAX_UINT32, false); m_node0 = NULL; m_node1 = NULL; copyAttributes(ferry); }
/*------- * ParseAttributes * * Description: Parse attribute string moving values into the aAttr array * Input : lpszAttributes - Pointer to attribute string * Output : None (global aAttr normally updated) *------- */ void INTFUNC ParseAttributes(LPCSTR lpszAttributes, LPSETUPDLG lpsetupdlg) { LPCSTR lpsz; LPCSTR lpszStart; char aszKey[MAXKEYLEN]; int cbKey; char value[MAXPGPATH]; CC_conninfo_init(&(lpsetupdlg->ci)); for (lpsz = lpszAttributes; *lpsz; lpsz++) { /* * Extract key name (e.g., DSN), it must be terminated by an * equals */ lpszStart = lpsz; for (;; lpsz++) { if (!*lpsz) return; /* No key was found */ else if (*lpsz == '=') break; /* Valid key found */ } /* Determine the key's index in the key table (-1 if not found) */ cbKey = lpsz - lpszStart; if (cbKey < sizeof(aszKey)) { _fmemcpy(aszKey, lpszStart, cbKey); aszKey[cbKey] = '\0'; } /* Locate end of key value */ lpszStart = ++lpsz; for (; *lpsz; lpsz++) ; /* lpsetupdlg->aAttr[iElement].fSupplied = TRUE; */ _fmemcpy(value, lpszStart, MIN(lpsz - lpszStart + 1, MAXPGPATH)); mylog("aszKey='%s', value='%s'\n", nullcheck(aszKey), nullcheck(value)); /* Copy the appropriate value to the conninfo */ if (!copyAttributes(&lpsetupdlg->ci, aszKey, value)) copyCommonAttributes(&lpsetupdlg->ci, aszKey, value); } return; }
list* addTableToColumn(list* table, list* column){ if(table!=NULL){ list* newNode= createListNode(table->nodeName); copyAttributes(newNode, table->attrList); column->down= newNode; if(table->down ==NULL || table->down->right==NULL) yyerror("ERROR\n"); list* tableRows= table->down->right; while(tableRows!=NULL){ addRowToTable(tableRows, newNode); tableRows= tableRows->right; } } }
InventoryItem::InventoryItem( Item* item, size_t inventoryPosX, size_t inventoryPosY, Player* player, InventoryItem* copyFrom ) : item( item ), player( player ), currentStackSize( 1 ), inventoryPosX( inventoryPosX ), inventoryPosY( inventoryPosY ) { /* Copy properties from the original inventoryItem (if we've suggested so). */ if ( copyFrom != NULL ) { copyAttributes( copyFrom ); } tooltip = new itemTooltip(item, this, player); }
QString Column::getAlterDefinition(BaseObject *object) { Column *col=dynamic_cast<Column *>(object); if(!col) throw Exception(ERR_OPR_NOT_ALOC_OBJECT,__PRETTY_FUNCTION__,__FILE__,__LINE__); try { attribs_map attribs; QString def_val; BaseObject::setBasicAttributes(true); if(getParentTable()) attribs[ParsersAttributes::TABLE]=getParentTable()->getName(true); if(!this->type.isEquivalentTo(col->type) || (this->type.isEquivalentTo(col->type) && ((this->type.hasVariableLength() && (this->type.getLength()!=col->type.getLength())) || (this->type.acceptsPrecision() && (this->type.getPrecision()!=col->type.getPrecision()))))) attribs[ParsersAttributes::TYPE]=col->type.getCodeDefinition(SchemaParser::SQL_DEFINITION); if(col->sequence) def_val=QString("nextval('%1'::regclass)").arg(col->sequence->getSignature()); else def_val=col->default_value; if(this->default_value!=def_val) attribs[ParsersAttributes::DEFAULT_VALUE]=(def_val.isEmpty() ? ParsersAttributes::UNSET : def_val); if(this->not_null!=col->not_null) attribs[ParsersAttributes::NOT_NULL]=(!col->not_null ? ParsersAttributes::UNSET : ParsersAttributes::_TRUE_); copyAttributes(attribs); return(BaseObject::getAlterDefinition(this->getSchemaName(), attributes, false, true)); } catch(Exception &e) { throw Exception(e.getErrorMessage(),e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__,&e); } }
QString Function::getAlterDefinition(BaseObject *object) { try { Function *func=dynamic_cast<Function *>(object); attribs_map attribs; attributes[ParsersAttributes::ALTER_CMDS]=BaseObject::getAlterDefinition(object); if(this->execution_cost!=func->execution_cost) attribs[ParsersAttributes::EXECUTION_COST]=QString::number(func->execution_cost); if(this->returns_setof && func->returns_setof && this->row_amount!=func->row_amount) { attribs[ParsersAttributes::RETURNS_SETOF]=ParsersAttributes::_TRUE_; attribs[ParsersAttributes::ROW_AMOUNT]=QString::number(row_amount); } if(this->function_type!=func->function_type) attribs[ParsersAttributes::FUNCTION_TYPE]=~func->function_type; if(this->is_leakproof!=func->is_leakproof) attribs[ParsersAttributes::LEAKPROOF]=(func->is_leakproof ? ParsersAttributes::_TRUE_ : ParsersAttributes::UNSET); if(this->security_type!=func->security_type) attribs[ParsersAttributes::SECURITY_TYPE]=~func->security_type; if((this->behavior_type!=func->behavior_type) && ((this->behavior_type==BehaviorType::called_on_null_input) || ((this->behavior_type==BehaviorType::strict || this->behavior_type==BehaviorType::returns_null_on_null_input) && func->function_type==BehaviorType::called_on_null_input))) attribs[ParsersAttributes::BEHAVIOR_TYPE]=~func->behavior_type; copyAttributes(attribs); return(BaseObject::getAlterDefinition(this->getSchemaName(), attributes, false, true)); } catch(Exception &e) { throw Exception(e.getErrorMessage(),e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__,&e); } }
QString Role::getAlterDefinition(BaseObject *object, bool ignore_name_diff) { Role *role=dynamic_cast<Role *>(object); if(!role) throw Exception(ERR_OPR_NOT_ALOC_OBJECT,__PRETTY_FUNCTION__,__FILE__,__LINE__); try { attribs_map attribs; QString op_attribs[]={ ParsersAttributes::SUPERUSER, ParsersAttributes::CREATEDB, ParsersAttributes::CREATEROLE, ParsersAttributes::INHERIT, ParsersAttributes::LOGIN, ParsersAttributes::ENCRYPTED, ParsersAttributes::REPLICATION }; attributes[ParsersAttributes::ALTER_CMDS]=BaseObject::getAlterDefinition(object, ignore_name_diff); if(this->password!=role->password) attribs[ParsersAttributes::PASSWORD]=role->password; if(this->validity!=role->validity) attribs[ParsersAttributes::VALIDITY]=role->validity; for(unsigned i=0; i <= OP_REPLICATION; i++) { if((attribs.count(ParsersAttributes::PASSWORD) && i==OP_ENCRYPTED) || this->options[i]!=role->options[i]) attribs[op_attribs[i]]=(role->options[i] ? ParsersAttributes::_TRUE_ : ParsersAttributes::UNSET); } copyAttributes(attribs); return(BaseObject::getAlterDefinition(this->getSchemaName(), attributes, false, true)); } catch(Exception &e) { throw Exception(e.getErrorMessage(),e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__,&e); } }
list* addColumnToRow(list* column, list* row){ list* rowDown= row->down; if(rowDown==NULL){ rowDown= (list*)malloc(sizeof(list)); row->down= rowDown; } list* searchNode= searchRight(column->nodeName, rowDown); if(searchNode==NULL){ list* newNode= createListNode(column->nodeName); copyAttributes(newNode, column->attrList); if(column->text!=NULL && column->down!=NULL){ yyerror("ERROR\n"); } else if(column->text!=NULL) newNode->text= strdup(column->text); addRight(newNode, rowDown); if(column->down!=NULL) addTableToColumn(column->down, newNode); }else yyerror("ERROR\n"); }
SEXP rbind_append (SEXP x, SEXP y) { /* Provide fast row binding of xts objects if the left-hand object (binding target) has a last index value less than the right-hand object (object to bind). This is an optimization to allow for real-time updating of objects without having to do much more than a memcpy of the two in coordinated fashion */ /*Rprintf("rbind_append called\n");*/ SEXP result; int nrs_x, nrs_y, ncs_x, ncs_y, nr; int i; ncs_x = ncols(x); ncs_y = ncols(y); nrs_x = nrows(x); nrs_y = nrows(y); if(ncs_x != ncs_y) error("objects must have the same number of columns"); /* FIXME */ PROTECT(result = allocVector(TYPEOF(x), (nrs_x + nrs_y) * ncs_x)); nr = nrs_x + nrs_y; switch(TYPEOF(x)) { case REALSXP: for(i=0; i< ncs_x; i++) { memcpy(&(REAL(result)[i*nr]), &(REAL(x)[i*nrs_x]), nrs_x*sizeof(double)); memcpy(&(REAL(result)[i*nr + nrs_x]), &(REAL(y)[i*nrs_y]), nrs_y*sizeof(double)); } break; case INTSXP: for(i=0; i< ncs_x; i++) { memcpy(&(INTEGER(result)[i*nr]), &(INTEGER(x)[i*nrs_x]), nrs_x*sizeof(int)); memcpy(&(INTEGER(result)[i*nr + nrs_x]), &(INTEGER(y)[i*nrs_y]), nrs_y*sizeof(int)); } break; case LGLSXP: for(i=0; i< ncs_x; i++) { memcpy(&(LOGICAL(result)[i*nr]), &(LOGICAL(x)[i*nrs_x]), nrs_x*sizeof(int)); memcpy(&(LOGICAL(result)[i*nr + nrs_x]), &(LOGICAL(y)[i*nrs_y]), nrs_y*sizeof(int)); } break; case CPLXSXP: for(i=0; i< ncs_x; i++) { memcpy(&(COMPLEX(result)[i*nr]), &(COMPLEX(x)[i*nrs_x]), nrs_x*sizeof(Rcomplex)); memcpy(&(COMPLEX(result)[i*nr + nrs_x]), &(COMPLEX(y)[i*nrs_y]), nrs_y*sizeof(Rcomplex)); } break; case RAWSXP: for(i=0; i< ncs_x; i++) { memcpy(&(RAW(result)[i*nr]), &(RAW(x)[i*nrs_x]), nrs_x*sizeof(Rbyte)); memcpy(&(RAW(result)[i*nr + nrs_x]), &(RAW(y)[i*nrs_y]), nrs_y*sizeof(Rbyte)); } break; case STRSXP: /* this requires an explicit loop like rbind.c and needs to be left with rbind.c */ break; default: error("unsupported type"); } copyAttributes(x, result); SEXP index, xindex, yindex; xindex = getAttrib(x,install("index")); yindex = getAttrib(y,install("index")); int INDEXTYPE = TYPEOF(xindex); if(INDEXTYPE != NILSXP) { PROTECT(index = allocVector(INDEXTYPE, nr)); if(INDEXTYPE==REALSXP) { memcpy(REAL(index), REAL(xindex), nrs_x * sizeof(double)); memcpy(&(REAL(index)[nrs_x]), REAL(yindex), nrs_y * sizeof(double)); } else if(INDEXTYPE==INTSXP) { memcpy(INTEGER(index), INTEGER(xindex), nrs_x * sizeof(int)); memcpy(&(INTEGER(index)[nrs_x]), INTEGER(yindex), nrs_y * sizeof(int)); } copyMostAttrib(xindex, index); setAttrib(result, install("index"), index); UNPROTECT(1); } SEXP dim; PROTECT(dim = allocVector(INTSXP, 2)); INTEGER(dim)[0] = nr; INTEGER(dim)[1] = ncs_x; /* should be the same */ setAttrib(result, R_DimSymbol, dim); UNPROTECT(1); setAttrib(result, R_DimNamesSymbol, getAttrib(x, R_DimNamesSymbol)); /* SEXP dimnames, currentnames, newnames; PROTECT(dimnames = allocVector(VECSXP, 2)); PROTECT(newnames = allocVector(STRSXP, length(j))); currentnames = getAttrib(x, R_DimNamesSymbol); if(!isNull(currentnames)) { SET_VECTOR_ELT(dimnames, 0, R_NilValue); for(i=0; i<ncs_x; i++) { SET_STRING_ELT(newnames, i, STRING_ELT(VECTOR_ELT(currentnames,1), i)); } SET_VECTOR_ELT(dimnames, 1, newnames); setAttrib(result, R_DimNamesSymbol, dimnames); } UNPROTECT(2); */ UNPROTECT(1); return result; }
std::unique_ptr<Node> inflate(const void* data, size_t dataLen, SourceLogger* logger) { std::unique_ptr<Node> root; std::stack<Node*> nodeStack; android::ResXMLTree tree; if (tree.setTo(data, dataLen) != android::NO_ERROR) { return {}; } android::ResXMLParser::event_code_t code; while ((code = tree.next()) != android::ResXMLParser::BAD_DOCUMENT && code != android::ResXMLParser::END_DOCUMENT) { std::unique_ptr<Node> newNode; switch (code) { case android::ResXMLParser::START_NAMESPACE: { std::unique_ptr<Namespace> node = util::make_unique<Namespace>(); size_t len; const char16_t* str16 = tree.getNamespacePrefix(&len); if (str16) { node->namespacePrefix.assign(str16, len); } str16 = tree.getNamespaceUri(&len); if (str16) { node->namespaceUri.assign(str16, len); } newNode = std::move(node); break; } case android::ResXMLParser::START_TAG: { std::unique_ptr<Element> node = util::make_unique<Element>(); size_t len; const char16_t* str16 = tree.getElementNamespace(&len); if (str16) { node->namespaceUri.assign(str16, len); } str16 = tree.getElementName(&len); if (str16) { node->name.assign(str16, len); } copyAttributes(node.get(), &tree); newNode = std::move(node); break; } case android::ResXMLParser::TEXT: { std::unique_ptr<Text> node = util::make_unique<Text>(); size_t len; const char16_t* str16 = tree.getText(&len); if (str16) { node->text.assign(str16, len); } newNode = std::move(node); break; } case android::ResXMLParser::END_NAMESPACE: case android::ResXMLParser::END_TAG: assert(!nodeStack.empty()); nodeStack.pop(); break; default: assert(false); break; } if (newNode) { newNode->lineNumber = tree.getLineNumber(); Node* thisNode = newNode.get(); if (!root) { assert(nodeStack.empty()); root = std::move(newNode); } else { assert(!nodeStack.empty()); nodeStack.top()->addChild(std::move(newNode)); } if (thisNode->type != NodeType::kText) { nodeStack.push(thisNode); } } } return root; }
SEXP _do_subset_xts (SEXP x, SEXP sr, SEXP sc, SEXP drop) { SEXP result; int i, j, nr, nc, nrs, ncs; int P=0; SEXP Dim = getAttrib(x, R_DimSymbol); nrs = nrows(x);ncs = ncols(x); nr = length(sr); nc = length(sc); SEXP oindex, nindex; oindex = getAttrib(x, install("index")); PROTECT(nindex = allocVector(TYPEOF(oindex), nr)); P++; PROTECT(result = allocVector(TYPEOF(x), nr*nc)); P++; j = 0; double *real_nindex=NULL, *real_oindex, *real_result=NULL, *real_x=NULL; int *int_nindex=NULL, *int_oindex, *int_result=NULL, *int_x=NULL; int *int_sr=NULL, *int_sc=NULL; int_sr = INTEGER(sr); int_sc = INTEGER(sc); copyAttributes(x, result); if(TYPEOF(x)==LGLSXP) { int_x = LOGICAL(x); int_result = LOGICAL(result); if(TYPEOF(nindex)==INTSXP) { int_nindex = INTEGER(nindex); int_oindex = INTEGER(oindex); for(i=0; i<nr; i++) { if(int_sr[i] == NA_INTEGER) error("'i' contains NA"); if(int_sr[i] > nrs || int_sc[j] > ncs) error("'i' or 'j' out of range"); int_nindex[i] = int_oindex[int_sr[i]-1]; if(int_sc[j] == NA_INTEGER) int_result[i+j*nr] = NA_INTEGER; else int_result[i+j*nr] = int_x[int_sr[i]-1 + ((int_sc[j]-1) * nrs)]; } } else if(TYPEOF(nindex)==REALSXP) { real_nindex = REAL(nindex); real_oindex = REAL(oindex); for(i=0; i<nr; i++) { real_nindex[i] = real_oindex[int_sr[i]-1]; if(int_sc[j] == NA_INTEGER) int_result[i+j*nr] = NA_INTEGER; else int_result[i+j*nr] = int_x[int_sr[i]-1 + ((int_sc[j]-1) * nrs)]; } } copyAttributes(oindex, nindex); setAttrib(result, install("index"), nindex); for(j=1; j<nc; j++) { for(i=0; i<nr; i++) { if(int_sc[j] == NA_INTEGER) int_result[i+j*nr] = NA_INTEGER; else int_result[i+j*nr] = int_x[int_sr[i]-1 + ((int_sc[j]-1) * nrs)]; } } } else /* branch into INTSXP and REALSXP, as these are most common/important types for time series data */ if(TYPEOF(x)==INTSXP) { int_x = INTEGER(x); int_result = INTEGER(result); if(TYPEOF(nindex)==INTSXP) { int_nindex = INTEGER(nindex); int_oindex = INTEGER(oindex); for(i=0; i<nr; i++) { if(int_sr[i] == NA_INTEGER) error("'i' contains NA"); if(int_sr[i] > nrs || int_sc[j] > ncs) error("'i' or 'j' out of range"); int_nindex[i] = int_oindex[int_sr[i]-1]; if(int_sc[j] == NA_INTEGER) int_result[i+j*nr] = NA_INTEGER; else int_result[i+j*nr] = int_x[int_sr[i]-1 + ((int_sc[j]-1) * nrs)]; } } else if(TYPEOF(nindex)==REALSXP) { real_nindex = REAL(nindex); real_oindex = REAL(oindex); for(i=0; i<nr; i++) { if(int_sr[i] == NA_INTEGER) error("'i' contains NA"); if(int_sr[i] > nrs || int_sc[j] > ncs) error("'i' or 'j' out of range"); real_nindex[i] = real_oindex[int_sr[i]-1]; if(int_sc[j] == NA_INTEGER) int_result[i+j*nr] = NA_INTEGER; else int_result[i+j*nr] = int_x[int_sr[i]-1 + ((int_sc[j]-1) * nrs)]; } } copyAttributes(oindex, nindex); setAttrib(result, install("index"), nindex); /* loop through remaining columns */ for(j=1; j<nc; j++) { for(i=0; i<nr; i++) { if(int_sc[j] == NA_INTEGER) int_result[i+j*nr] = NA_INTEGER; else int_result[i+j*nr] = int_x[int_sr[i]-1 + ((int_sc[j]-1) * nrs)]; } } } else if(TYPEOF(x)==REALSXP) { real_x = REAL(x); real_result = REAL(result); if(TYPEOF(nindex)==INTSXP) { int_nindex = INTEGER(nindex); int_oindex = INTEGER(oindex); for(i=0; i<nr; i++) { if(int_sr[i] == NA_INTEGER) error("'i' contains NA"); if(int_sr[i] > nrs || int_sc[j] > ncs) error("'i' or 'j' out of range"); int_nindex[i] = int_oindex[int_sr[i]-1]; if(int_sc[j] == NA_INTEGER) real_result[i+j*nr] = NA_REAL; else real_result[i+j*nr] = real_x[int_sr[i]-1 + ((int_sc[j]-1) * nrs)]; } } else if(TYPEOF(nindex)==REALSXP) { real_nindex = REAL(nindex); real_oindex = REAL(oindex); for(i=0; i<nr; i++) { if(int_sr[i] == NA_INTEGER) error("'i' contains NA"); if(int_sr[i] > nrs || int_sc[j] > ncs) error("'i' or 'j' out of range"); real_nindex[i] = real_oindex[int_sr[i]-1]; if(int_sc[j] == NA_INTEGER) real_result[i+j*nr] = NA_REAL; else real_result[i+j*nr] = real_x[int_sr[i]-1 + ((int_sc[j]-1) * nrs)]; } } copyAttributes(oindex, nindex); setAttrib(result, install("index"), nindex); for(j=1; j<nc; j++) { for(i=0; i<nr; i++) { if(int_sc[j] == NA_INTEGER) real_result[i+j*nr] = NA_REAL; else real_result[i+j*nr] = real_x[int_sr[i]-1 + ((int_sc[j]-1) * nrs)]; } } } else if(TYPEOF(x)==CPLXSXP) { /* real_x = REAL(x); real_result = REAL(result); */ if(TYPEOF(nindex)==INTSXP) { int_nindex = INTEGER(nindex); int_oindex = INTEGER(oindex); for(i=0; i<nr; i++) { if(int_sr[i] == NA_INTEGER) error("'i' contains NA"); if(int_sr[i] > nrs || int_sc[j] > ncs) error("'i' or 'j' out of range"); int_nindex[i] = int_oindex[int_sr[i]-1]; if(int_sc[j] == NA_INTEGER) { COMPLEX(result)[i+j*nr].r = NA_REAL; COMPLEX(result)[i+j*nr].i = NA_REAL; } else COMPLEX(result)[i+j*nr] = COMPLEX(x)[int_sr[i]-1 + ((int_sc[j]-1) * nrs)]; } } else if(TYPEOF(nindex)==REALSXP) { real_nindex = REAL(nindex); real_oindex = REAL(oindex); for(i=0; i<nr; i++) { if(int_sr[i] == NA_INTEGER) error("'i' contains NA"); if(int_sr[i] > nrs || int_sc[j] > ncs) error("'i' or 'j' out of range"); real_nindex[i] = real_oindex[int_sr[i]-1]; if(int_sc[j] == NA_INTEGER) { COMPLEX(result)[i+j*nr].r = NA_REAL; COMPLEX(result)[i+j*nr].i = NA_REAL; } else COMPLEX(result)[i+j*nr] = COMPLEX(x)[int_sr[i]-1 + ((int_sc[j]-1) * nrs)]; } } copyAttributes(oindex, nindex); setAttrib(result, install("index"), nindex); for(j=1; j<nc; j++) { for(i=0; i<nr; i++) { if(int_sc[j] == NA_INTEGER) { COMPLEX(result)[i+j*nr].r = NA_REAL; COMPLEX(result)[i+j*nr].i = NA_REAL; } else COMPLEX(result)[i+j*nr] = COMPLEX(x)[int_sr[i]-1 + ((int_sc[j]-1) * nrs)]; } } } else if(TYPEOF(x)==STRSXP) { if(TYPEOF(nindex)==INTSXP) { int_nindex = INTEGER(nindex); int_oindex = INTEGER(oindex); for(i=0; i<nr; i++) { if(int_sr[i] == NA_INTEGER) error("'i' contains NA"); if(int_sr[i] > nrs || int_sc[j] > ncs) error("'i' or 'j' out of range"); int_nindex[i] = int_oindex[int_sr[i]-1]; if(int_sc[j] == NA_INTEGER) SET_STRING_ELT(result, i+j*nr, NA_STRING); else SET_STRING_ELT(result, i+j*nr, STRING_ELT(x, int_sr[i]-1 + ((int_sc[j]-1) * nrs))); } } else if(TYPEOF(nindex)==REALSXP) { real_nindex = REAL(nindex); real_oindex = REAL(oindex); for(i=0; i<nr; i++) { if(int_sr[i] == NA_INTEGER) error("'i' contains NA"); if(int_sr[i] > nrs || int_sc[j] > ncs) error("'i' or 'j' out of range"); real_nindex[i] = real_oindex[int_sr[i]-1]; if(int_sc[j] == NA_INTEGER) SET_STRING_ELT(result, i+j*nr, NA_STRING); else SET_STRING_ELT(result, i+j*nr, STRING_ELT(x, int_sr[i]-1 + ((int_sc[j]-1) * nrs))); } } copyAttributes(oindex, nindex); setAttrib(result, install("index"), nindex); for(j=1; j<nc; j++) { for(i=0; i<nr; i++) { if(int_sc[j] == NA_INTEGER) SET_STRING_ELT(result, i+j*nr, NA_STRING); else SET_STRING_ELT(result, i+j*nr, STRING_ELT(x, int_sr[i]-1 + ((int_sc[j]-1) * nrs))); } } } else if(TYPEOF(x)==RAWSXP) { /* real_x = REAL(x); real_result = REAL(result); */ if(TYPEOF(nindex)==INTSXP) { int_nindex = INTEGER(nindex); int_oindex = INTEGER(oindex); for(i=0; i<nr; i++) { if(int_sr[i] == NA_INTEGER) error("'i' contains NA"); if(int_sr[i] > nrs || int_sc[j] > ncs) error("'i' or 'j' out of range"); int_nindex[i] = int_oindex[int_sr[i]-1]; if(int_sc[j] == NA_INTEGER) RAW(result)[i+j*nr] = 0; else RAW(result)[i+j*nr] = RAW(x)[int_sr[i]-1 + ((int_sc[j]-1) * nrs)]; } } else if(TYPEOF(nindex)==REALSXP) { real_nindex = REAL(nindex); real_oindex = REAL(oindex); for(i=0; i<nr; i++) { if(int_sr[i] == NA_INTEGER) error("'i' contains NA"); if(int_sr[i] > nrs || int_sc[j] > ncs) error("'i' or 'j' out of range"); real_nindex[i] = real_oindex[int_sr[i]-1]; if(int_sc[j] == NA_INTEGER) RAW(result)[i+j*nr] = 0; else RAW(result)[i+j*nr] = RAW(x)[int_sr[i]-1 + ((int_sc[j]-1) * nrs)]; } } copyAttributes(oindex, nindex); setAttrib(result, install("index"), nindex); for(j=1; j<nc; j++) { for(i=0; i<nr; i++) { if(int_sc[j] == NA_INTEGER) RAW(result)[i+j*nr] = 0; else RAW(result)[i+j*nr] = RAW(x)[int_sr[i]-1 + ((int_sc[j]-1) * nrs)]; } } } if(!isNull(Dim) && nr >= 0 && nc >= 0) { SEXP dim; PROTECT(dim = allocVector(INTSXP,2));P++; INTEGER(dim)[0] = nr; INTEGER(dim)[1] = nc; setAttrib(result, R_DimSymbol, dim); if (nr >= 0 && nc >= 0) { SEXP dimnames, dimnamesnames, newdimnames; dimnames = getAttrib(x, R_DimNamesSymbol); dimnamesnames = getAttrib(dimnames, R_NamesSymbol); if (!isNull(dimnames)) { PROTECT(newdimnames = allocVector(VECSXP, 2)); if (TYPEOF(dimnames) == VECSXP) { SET_VECTOR_ELT(newdimnames, 0, ExtractSubset(VECTOR_ELT(dimnames, 0), allocVector(STRSXP, nr), sr)); SET_VECTOR_ELT(newdimnames, 1, ExtractSubset(VECTOR_ELT(dimnames, 1), allocVector(STRSXP, nc), sc)); } else { SET_VECTOR_ELT(newdimnames, 0, ExtractSubset(CAR(dimnames), allocVector(STRSXP, nr), sr)); SET_VECTOR_ELT(newdimnames, 1, ExtractSubset(CADR(dimnames), allocVector(STRSXP, nc), sc)); } setAttrib(newdimnames, R_NamesSymbol, dimnamesnames); setAttrib(result, R_DimNamesSymbol, newdimnames); UNPROTECT(1); } } } setAttrib(result, R_ClassSymbol, getAttrib(x, R_ClassSymbol)); if(nc == 1 && LOGICAL(drop)[0]) setAttrib(result, R_DimSymbol, R_NilValue); UNPROTECT(P); return result; }
SEXP extract_col (SEXP x, SEXP j, SEXP drop, SEXP first_, SEXP last_) { SEXP result, index, new_index; int nrs, nrsx, i, ii, jj, first, last; nrsx = nrows(x); first = asInteger(first_)-1; last = asInteger(last_)-1; /* nrs = offset_end - offset_start - 1; */ nrs = last - first + 1; PROTECT(result = allocVector(TYPEOF(x), nrs * length(j))); switch(TYPEOF(x)) { case REALSXP: for(i=0; i<length(j); i++) { /* Rprintf("j + i*nrs + first=%i\n", (int)(INTEGER(j)[i]-1 + i*nrs + first)); Rprintf("i=%i, j=%i, nrs=%i, first=%i\n", i, INTEGER(j)[i]-1, nrs, first); */ if(INTEGER(j)[i] == NA_INTEGER) { for(ii=0; ii < nrs; ii++) { REAL(result)[(i*nrs) + ii] = NA_REAL; } } else { memcpy(&(REAL(result)[i*nrs]), &(REAL(x)[(INTEGER(j)[i]-1)*nrsx + first]), nrs*sizeof(double)); } } break; case INTSXP: for(i=0; i<length(j); i++) { if(INTEGER(j)[i] == NA_INTEGER) { for(ii=0; ii < nrs; ii++) { INTEGER(result)[(i*nrs) + ii] = NA_INTEGER; } } else { memcpy(&(INTEGER(result)[i*nrs]), &(INTEGER(x)[(INTEGER(j)[i]-1)*nrsx + first]), nrs*sizeof(int)); } } break; case LGLSXP: for(i=0; i<length(j); i++) { if(INTEGER(j)[i] == NA_INTEGER) { for(ii=0; ii < nrs; ii++) { LOGICAL(result)[(i*nrs) + ii] = NA_LOGICAL; } } else { memcpy(&(LOGICAL(result)[i*nrs]), &(LOGICAL(x)[(INTEGER(j)[i]-1)*nrsx + first]), nrs*sizeof(int)); } } break; case CPLXSXP: for(i=0; i<length(j); i++) { if(INTEGER(j)[i] == NA_INTEGER) { for(ii=0; ii < nrs; ii++) { COMPLEX(result)[(i*nrs) + ii].r = NA_REAL; COMPLEX(result)[(i*nrs) + ii].i = NA_REAL; } } else { memcpy(&(COMPLEX(result)[i*nrs]), &(COMPLEX(x)[(INTEGER(j)[i]-1)*nrsx + first]), nrs*sizeof(Rcomplex)); } } break; case RAWSXP: for(i=0; i<length(j); i++) { if(INTEGER(j)[i] == NA_INTEGER) { for(ii=0; ii < nrs; ii++) { RAW(result)[(i*nrs) + ii] = 0; } } else { memcpy(&(RAW(result)[i*nrs]), &(RAW(x)[(INTEGER(j)[i]-1)*nrsx + first]), nrs*sizeof(Rbyte)); } } break; case STRSXP: for(jj=0; jj<length(j); jj++) { if(INTEGER(j)[jj] == NA_INTEGER) { for(i=0; i< nrs; i++) SET_STRING_ELT(result, i+jj*nrs, NA_STRING); } else { for(i=0; i< nrs; i++) SET_STRING_ELT(result, i+jj*nrs, STRING_ELT(x, i+(INTEGER(j)[jj]-1)*nrsx+first)); } } break; default: error("unsupported type"); } if(nrs != nrows(x)) { copyAttributes(x, result); /* subset index */ index = getAttrib(x, install("index")); PROTECT(new_index = allocVector(TYPEOF(index), nrs)); if(TYPEOF(index) == REALSXP) { memcpy(REAL(new_index), &(REAL(index)[first]), nrs*sizeof(double)); } else { /* INTSXP */ memcpy(INTEGER(new_index), &(INTEGER(index)[first]), nrs*sizeof(int)); } copyMostAttrib(index, new_index); setAttrib(result, install("index"), new_index); UNPROTECT(1); } else { copyMostAttrib(x, result); /* need an xts/zoo equal that skips 'index' */ } if(!asLogical(drop)) { /* keep dimension and dimnames */ SEXP dim; PROTECT(dim = allocVector(INTSXP, 2)); INTEGER(dim)[0] = nrs; INTEGER(dim)[1] = length(j); setAttrib(result, R_DimSymbol, dim); UNPROTECT(1); SEXP dimnames, currentnames, newnames; PROTECT(dimnames = allocVector(VECSXP, 2)); PROTECT(newnames = allocVector(STRSXP, length(j))); currentnames = getAttrib(x, R_DimNamesSymbol); if(!isNull(currentnames)) { SET_VECTOR_ELT(dimnames, 0, VECTOR_ELT(currentnames,0)); if(!isNull(VECTOR_ELT(currentnames,1))) { /* if colnames isn't NULL set */ for(i=0; i<length(j); i++) { SET_STRING_ELT(newnames, i, STRING_ELT(VECTOR_ELT(currentnames,1), INTEGER(j)[i]-1)); } SET_VECTOR_ELT(dimnames, 1, newnames); } else { /* else set to NULL */ SET_VECTOR_ELT(dimnames, 1, R_NilValue); } setAttrib(result, R_DimNamesSymbol, dimnames); } UNPROTECT(2); } UNPROTECT(1); return result; }
HtmlElement * HtmlImageElement::clone() const { HtmlElement * theClone(new HtmlImageElement(m_tagName)); copyAttributes(theClone); return theClone; }
QString Type::getAlterDefinition(BaseObject *object) { Type *type=dynamic_cast<Type *>(object); if(!type) throw Exception(ERR_OPR_NOT_ALOC_OBJECT,__PRETTY_FUNCTION__,__FILE__,__LINE__); try { attribs_map attribs; QString alter_def, prev_val; int attrib_idx=-1; alter_def=BaseObject::getAlterDefinition(object); if(this->config==type->config) { if(config==ENUMERATION_TYPE) { for(QString enum_val : type->enumerations) { if(std::find(this->enumerations.begin(), this->enumerations.end(), enum_val)==this->enumerations.end()) { attribs[ParsersAttributes::BEFORE]=QString(); if(prev_val.isEmpty()) { attribs[ParsersAttributes::BEFORE]=ParsersAttributes::_TRUE_; prev_val=this->enumerations[0]; } attribs[ParsersAttributes::VALUE]=enum_val; attribs[ParsersAttributes::EXISTING_VALUE]=prev_val; copyAttributes(attribs); alter_def+=BaseObject::getAlterDefinition(this->getSchemaName(), attributes, true, true); attribs.clear(); } prev_val=enum_val; } } else if(config==COMPOSITE_TYPE) { //Removing type attributes for(TypeAttribute attrib : this->type_attribs) { if(type->getAttributeIndex(attrib.getName()) < 0) { attribs[ParsersAttributes::DROP]=ParsersAttributes::_TRUE_; attribs[ParsersAttributes::ATTRIBUTE]=attrib.getName(true); copyAttributes(attribs); alter_def+=BaseObject::getAlterDefinition(this->getSchemaName(), attributes, true, true); attribs.clear(); attributes[ParsersAttributes::DROP]=QString(); } } for(TypeAttribute attrib : type->type_attribs) { attrib_idx=this->getAttributeIndex(attrib.getName()); //Creating type attributes if(attrib_idx < 0) { attribs[ParsersAttributes::ATTRIBUTE]=attrib.getName(true); attribs[ParsersAttributes::TYPE]=attrib.getType().getCodeDefinition(SchemaParser::SQL_DEFINITION); attribs[ParsersAttributes::COLLATION]=QString(); if(attrib.getCollation()) attribs[ParsersAttributes::COLLATION]=attrib.getCollation()->getName(true); copyAttributes(attribs); alter_def+=BaseObject::getAlterDefinition(this->getSchemaName(), attributes, true, true); } //Changing type attributes else { attribs[ParsersAttributes::CHANGE]=ParsersAttributes::_TRUE_; if(!type_attribs[attrib_idx].getType().isEquivalentTo(attrib.getType())) { attribs[ParsersAttributes::ATTRIBUTE]=attrib.getName(true); attribs[ParsersAttributes::TYPE]=attrib.getType().getCodeDefinition(SchemaParser::SQL_DEFINITION); } copyAttributes(attribs); alter_def+=BaseObject::getAlterDefinition(this->getSchemaName(), attributes, true, true); attributes[ParsersAttributes::CHANGE]=QString(); } attribs.clear(); } } } return(alter_def); } catch(Exception &e) { throw Exception(e.getErrorMessage(),e.getErrorType(),__PRETTY_FUNCTION__,__FILE__,__LINE__,&e); } }
SEXP do_subset_xts(SEXP x, SEXP sr, SEXP sc, SEXP drop) //SEXP s, SEXP call, int drop) { SEXP attr, result, dim; int nr, nc, nrs, ncs; int i, j, ii, jj, ij, iijj; int mode; int *int_x=NULL, *int_result=NULL, *int_newindex=NULL, *int_index=NULL; double *real_x=NULL, *real_result=NULL, *real_newindex=NULL, *real_index=NULL; nr = nrows(x); nc = ncols(x); if( length(x)==0 ) return x; dim = getAttrib(x, R_DimSymbol); nrs = LENGTH(sr); ncs = LENGTH(sc); int *int_sr=NULL, *int_sc=NULL; int_sr = INTEGER(sr); int_sc = INTEGER(sc); mode = TYPEOF(x); result = allocVector(mode, nrs*ncs); PROTECT(result); if( mode==INTSXP ) { int_x = INTEGER(x); int_result = INTEGER(result); } else if( mode==REALSXP ) { real_x = REAL(x); real_result = REAL(result); } /* code to handle index of xts object efficiently */ SEXP index, newindex; int indx; index = getAttrib(x, install("index")); PROTECT(index); if(TYPEOF(index) == INTSXP) { newindex = allocVector(INTSXP, LENGTH(sr)); PROTECT(newindex); int_newindex = INTEGER(newindex); int_index = INTEGER(index); for(indx = 0; indx < nrs; indx++) { int_newindex[indx] = int_index[ (int_sr[indx])-1]; } copyAttributes(index, newindex); setAttrib(result, install("index"), newindex); UNPROTECT(1); } if(TYPEOF(index) == REALSXP) { newindex = allocVector(REALSXP, LENGTH(sr)); PROTECT(newindex); real_newindex = REAL(newindex); real_index = REAL(index); for(indx = 0; indx < nrs; indx++) { real_newindex[indx] = real_index[ (int_sr[indx])-1 ]; } copyAttributes(index, newindex); setAttrib(result, install("index"), newindex); UNPROTECT(1); } for (i = 0; i < nrs; i++) { ii = int_sr[i]; if (ii != NA_INTEGER) { if (ii < 1 || ii > nr) error("i is out of range\n"); ii--; } /* Begin column loop */ for (j = 0; j < ncs; j++) { //jj = INTEGER(sc)[j]; jj = int_sc[j]; if (jj != NA_INTEGER) { if (jj < 1 || jj > nc) error("j is out of range\n"); jj--; } ij = i + j * nrs; if (ii == NA_INTEGER || jj == NA_INTEGER) { switch ( mode ) { case REALSXP: real_result[ij] = NA_REAL; break; case LGLSXP: case INTSXP: int_result[ij] = NA_INTEGER; break; case CPLXSXP: COMPLEX(result)[ij].r = NA_REAL; COMPLEX(result)[ij].i = NA_REAL; break; case STRSXP: SET_STRING_ELT(result, ij, NA_STRING); break; case VECSXP: SET_VECTOR_ELT(result, ij, R_NilValue); break; case RAWSXP: RAW(result)[ij] = (Rbyte) 0; break; default: error("xts subscripting not handled for this type"); break; } } else { iijj = ii + jj * nr; switch ( mode ) { case REALSXP: real_result[ij] = real_x[iijj]; break; case LGLSXP: LOGICAL(result)[ij] = LOGICAL(x)[iijj]; break; case INTSXP: int_result[ij] = int_x[iijj]; break; case CPLXSXP: COMPLEX(result)[ij] = COMPLEX(x)[iijj]; break; case STRSXP: SET_STRING_ELT(result, ij, STRING_ELT(x, iijj)); break; case VECSXP: SET_VECTOR_ELT(result, ij, VECTOR_ELT(x, iijj)); break; case RAWSXP: RAW(result)[ij] = RAW(x)[iijj]; break; default: error("matrix subscripting not handled for this type"); break; } } } /* end of column loop */ } /* end of row loop */ if(nrs >= 0 && ncs >= 0 && !isNull(dim)) { PROTECT(attr = allocVector(INTSXP, 2)); INTEGER(attr)[0] = nrs; INTEGER(attr)[1] = ncs; setAttrib(result, R_DimSymbol, attr); UNPROTECT(1); } /* The matrix elements have been transferred. Now we need to */ /* transfer the attributes. Most importantly, we need to subset */ /* the dimnames of the returned value. */ if (nrs >= 0 && ncs >= 0 && !isNull(dim)) { SEXP dimnames, dimnamesnames, newdimnames; dimnames = getAttrib(x, R_DimNamesSymbol); dimnamesnames = getAttrib(dimnames, R_NamesSymbol); if (!isNull(dimnames)) { PROTECT(newdimnames = allocVector(VECSXP, 2)); if (TYPEOF(dimnames) == VECSXP) { SET_VECTOR_ELT(newdimnames, 0, xtsExtractSubset(VECTOR_ELT(dimnames, 0), allocVector(STRSXP, nrs), sr)); SET_VECTOR_ELT(newdimnames, 1, xtsExtractSubset(VECTOR_ELT(dimnames, 1), allocVector(STRSXP, ncs), sc)); } else { SET_VECTOR_ELT(newdimnames, 0, xtsExtractSubset(CAR(dimnames), allocVector(STRSXP, nrs), sr)); SET_VECTOR_ELT(newdimnames, 1, xtsExtractSubset(CADR(dimnames), allocVector(STRSXP, ncs), sc)); } setAttrib(newdimnames, R_NamesSymbol, dimnamesnames); setAttrib(result, R_DimNamesSymbol, newdimnames); UNPROTECT(1); } } copyAttributes(x, result); if(ncs == 1 && LOGICAL(drop)[0]) setAttrib(result, R_DimSymbol, R_NilValue); UNPROTECT(2); return result; }
static int copyPkiUserAttributes( INOUT CERT_INFO *certInfoPtr, INOUT ATTRIBUTE_PTR *pkiUserAttributes ) { ATTRIBUTE_PTR *requestAttrPtr, *pkiUserAttrPtr; int value, status; assert( isWritePtr( certInfoPtr, sizeof( CERT_INFO ) ) ); assert( isWritePtr( pkiUserAttributes, sizeof( ATTRIBUTE_LIST ) ) ); REQUIRES( certInfoPtr->type == CRYPT_CERTTYPE_CERTREQUEST || \ certInfoPtr->type == CRYPT_CERTTYPE_REQUEST_CERT ); /* If there are altNames present in both the PKI user data and the request, make sure that they match */ requestAttrPtr = findAttribute( certInfoPtr->attributes, CRYPT_CERTINFO_SUBJECTALTNAME, FALSE ); pkiUserAttrPtr = findAttribute( pkiUserAttributes, CRYPT_CERTINFO_SUBJECTALTNAME, FALSE ); if( requestAttrPtr != NULL && pkiUserAttrPtr != NULL ) { /* Both the certificate request and the PKI user have altNames, make sure that they're identical */ if( !compareAttribute( requestAttrPtr, pkiUserAttrPtr ) ) { setErrorInfo( certInfoPtr, CRYPT_CERTINFO_SUBJECTALTNAME, CRYPT_ERRTYPE_ISSUERCONSTRAINT ); return( CRYPT_ERROR_INVALID ); } /* The two altNames are identical, delete the one in the request in order to allow the one from the PKI user data to be copied across when we call copyAttributes() */ status = deleteAttribute( &certInfoPtr->attributes, &certInfoPtr->attributeCursor, requestAttrPtr, certInfoPtr->currentSelection.dnPtr ); if( cryptStatusError( status ) ) return( status ); } /* There's one rather ugly special-case situation that we have to handle which is when the user has submitted a PnP PKI request for a generic signing certificate but their PKI user information indicates that they're intended to be a CA user. The processing flow for this is: Read request data from an external source into certificate request object, creating a state=high object; Add PKI user information to state=high request; When augmenting the request with the PKI user information the incoming request will contain a keyUsage of digitalSignature while the PKI user information will contain a keyUsage of keyCertSign and/or crlSign. We can't fix this up at the PnP processing level because the request object will be in the high state once it's instantiated and no changes to the attributes can be made (the PKI user information is a special case that can be added to an object in the high state but which modifies attributes in it as if it were still in the low state). To avoid the attribute conflict, if we find this situation in the request/pkiUser combination we delete the keyUsage in the request to allow it to be replaced by the pkiUser keyUsage. Hardcoding in this special case isn't very elegant but it's the only way to make the PnP PKI issue work without requiring that the user explicitly specify that they want to be a CA in the request's keyUsage, which makes it rather non-PnP and would also lead to slightly strange requests since basicConstraints can't be specified in requests while the CA keyUsage can */ status = getAttributeFieldValue( certInfoPtr->attributes, CRYPT_CERTINFO_KEYUSAGE, CRYPT_ATTRIBUTE_NONE, &value ); if( cryptStatusOK( status ) && value == CRYPT_KEYUSAGE_DIGITALSIGNATURE ) { status = getAttributeFieldValue( pkiUserAttributes, CRYPT_CERTINFO_KEYUSAGE, CRYPT_ATTRIBUTE_NONE, &value ); if( cryptStatusOK( status ) && ( value & KEYUSAGE_CA ) ) { /* The certificate contains a digitalSignature keyUsage and the PKI user information contains a CA usage, delete the certificate's keyUsage to make way for the PKI user's CA keyUsage */ status = deleteCompleteAttribute( &certInfoPtr->attributes, &certInfoPtr->attributeCursor, CRYPT_CERTINFO_KEYUSAGE, certInfoPtr->currentSelection.dnPtr ); if( cryptStatusError( status ) ) return( status ); } } /* Copy the attributes from the PKI user information into the certificate */ status = copyAttributes( &certInfoPtr->attributes, pkiUserAttributes, &certInfoPtr->errorLocus, &certInfoPtr->errorType ); if( cryptStatusError( status ) ) return( status ); /* Perform any special-case adjustments on attributes that may be required after they've been copied from the PKI user to the certificate request */ return( adjustPkiUserAttributes( certInfoPtr ) ); }