ErrorCode RangeSetIterator::get_next_by_type(const EntityHandle *&ptr, int count, std::vector<EntityHandle> &arr, bool &atend) { unsigned int num_ret = 0; bool max_type = (entType == MBMAXTYPE); size_t idx = 0; // initialize to first relevant handle while ((int)idx < count && (iterPos > ptr[idx+1] || (!max_type && !iterPos && CREATE_HANDLE(entType, ID_FROM_HANDLE(iterPos)) > ptr[idx+1]))) idx += 2; if ((int)idx == count || TYPE_FROM_HANDLE(ptr[idx]) > entType) { atend = true; return MB_SUCCESS; } if (!iterPos && max_type) iterPos = ptr[idx]; else if (!iterPos && TYPE_FROM_HANDLE(ptr[idx]) <= entType && TYPE_FROM_HANDLE(ptr[idx+1]) >= entType) { iterPos = std::max(CREATE_HANDLE(entType,1), ptr[idx]); } // idx points to start of subrange, iterPos in that subrange do { EntityHandle next = ptr[idx+1]; if (TYPE_FROM_HANDLE(next) != entType && !max_type) next = LAST_HANDLE(entType); unsigned int this_ret = chunkSize-num_ret; unsigned int to_end = next - iterPos + 1; if (to_end < this_ret) this_ret = to_end; std::copy(MeshSet::hdl_iter(iterPos), MeshSet::hdl_iter(iterPos + this_ret), std::back_inserter(arr)); if (this_ret == to_end) { idx += 2; iterPos = ((int)idx < count ? ptr[idx] : 0); } else iterPos += this_ret; num_ret += this_ret; } while ((int)idx < count && num_ret < chunkSize && iterPos && (max_type || TYPE_FROM_HANDLE(iterPos) == entType)); if (!iterPos || (!max_type && TYPE_FROM_HANDLE(iterPos) != entType)) atend = true; return MB_SUCCESS; }
RedCryptoReaderHandle * scytale_reader_new( const char * derivator, get_hmac_key_prototype* hmac_fn, get_trace_key_prototype* trace_fn, int old_scheme, int one_shot) { SCOPED_TRACE; return CREATE_HANDLE(RedCryptoReaderHandle( InCryptoTransport::EncryptionMode::Auto, hmac_fn, trace_fn, old_scheme, one_shot, derivator )); }
RedCryptoKeyHandle * scytale_key_new(const char * masterkeyhex) { SCOPED_TRACE; constexpr auto key_len = sizeof(HashHexArray) - 1; if (!masterkeyhex || strlen(masterkeyhex) != key_len){ return nullptr; } for (char c : make_array_view(masterkeyhex, key_len)){ if (not ((c >= '0' and c <= '9') or (c >= 'A' and c <= 'F') or (c >= 'a' and c <= 'f'))){ return nullptr; } } return CREATE_HANDLE(RedCryptoKeyHandle(masterkeyhex)); }
RedCryptoWriterHandle * scytale_writer_new_with_test_random( int with_encryption, int with_checksum, const char * derivator, get_hmac_key_prototype * hmac_fn, get_trace_key_prototype * trace_fn, int old_scheme, int one_shot) { SCOPED_TRACE; return CREATE_HANDLE(RedCryptoWriterHandle( RedCryptoWriterHandle::LCG, with_encryption, with_checksum, hmac_fn, trace_fn, old_scheme, one_shot, derivator )); }
ErrorCode RangeSetIterator::get_next_by_dimension(const EntityHandle *&ptr, int count, std::vector<EntityHandle> &arr, bool &atend) { // iterating by dimension - type should be maxtype if (entType != MBMAXTYPE) { MB_SET_ERR(MB_FAILURE, "Both dimension and type should not be set on an iterator"); } unsigned int num_ret = 0; size_t idx = 0; // initialize to first relevant handle while ((int)idx < count && (iterPos > ptr[idx+1] || (!iterPos && entDimension > CN::Dimension(TYPE_FROM_HANDLE(ptr[idx+1]))))) idx += 2; if ((int)idx == count || CN::Dimension(TYPE_FROM_HANDLE(ptr[idx])) > entDimension) { atend = true; return MB_SUCCESS; } if (!iterPos) iterPos = ptr[idx]; else if (CN::Dimension(TYPE_FROM_HANDLE(ptr[idx])) < entDimension) iterPos = CREATE_HANDLE(CN::TypeDimensionMap[entDimension].first,1); // idx points to start of subrange, iterPos in that subrange do { EntityHandle next = ptr[idx+1]; if (CN::Dimension(TYPE_FROM_HANDLE(next)) != entDimension) next = LAST_HANDLE(CN::TypeDimensionMap[entDimension].second); unsigned int this_ret = chunkSize-num_ret; unsigned int to_end = next - iterPos + 1; if (to_end < this_ret) this_ret = to_end; std::copy(MeshSet::hdl_iter(iterPos), MeshSet::hdl_iter(iterPos + this_ret), std::back_inserter(arr)); if (this_ret == to_end) { idx += 2; iterPos = ((int)idx < count ? ptr[idx] : 0); } else iterPos += this_ret; num_ret += this_ret; } while ((int)idx < count && num_ret < chunkSize && iterPos && CN::Dimension(TYPE_FROM_HANDLE(iterPos)) == entDimension); if (!iterPos || CN::Dimension(TYPE_FROM_HANDLE(iterPos)) != entDimension) atend = true; return MB_SUCCESS; }
ErrorCode BitTag::get_entities_with_bits( EntityType type, Range& entities, unsigned char bits ) const { std::pair<EntityType,EntityType> r = type_range(type); const int per_page = ents_per_page(); for (EntityType t = r.first; t != r.second; ++t) { for (size_t i = 0; i < pageList[t].size(); ++i) { if (pageList[t][i]) { EntityID id = i * per_page; EntityHandle h = CREATE_HANDLE( t, id ); int off = !i; // never zero ID pageList[t][i]->search( bits, off, per_page-off, storedBitsPerEntity, entities, h+off ); } } } return MB_SUCCESS; }
template <class Container> inline void BitTag::get_tagged( EntityType type, Container& entities ) const { std::pair<EntityType,EntityType> r = type_range(type); typename Container::iterator hint = entities.begin(); const int per_page = ents_per_page(); for (EntityType t = r.first; t != r.second; ++t) { for (size_t i = 0; i < pageList[t].size(); ++i) { if (pageList[t][i]) { EntityID id = i * per_page; EntityHandle h = CREATE_HANDLE( t, id ); EntityHandle last = h + per_page - 1; // never zero ID if (!id) ++h; hint = entities.insert( hint, h, last ); } } } }
CNXT_SMC_STATUS cnxt_smc_open ( CNXT_SMC_HANDLE *pHandle, CNXT_SMC_CAPS *pCaps, CNXT_SMC_PFNNOTIFY pNotifyFn, void *pUserData ) { CNXT_SMC_INST *pInst; CNXT_SMC_UNIT_INST *pUnitInst; u_int32 uUnit; IS_DRIVER_INITED(SMC,pDriverInst->bInit); IS_NOT_NULL_POINTER(SMC, pHandle); IS_NOT_NULL_POINTER(SMC, pCaps); if (sem_get(pDriverInst->DriverSem, KAL_WAIT_FOREVER) != RC_OK) { return CNXT_SMC_INTERNAL_ERROR; } /* figure out unit number based on info in pCaps */ uUnit = cnxt_smc_unit_num(pCaps); if (uUnit >= CNXT_SMC_NUM_UNITS) { return CNXT_SMC_BAD_UNIT; } /* check bExclusive */ pUnitInst = &(pDriverInst->pUnitInst[uUnit]); if ((pUnitInst->pFirstInst != NULL) && (pUnitInst->bExclusive || pCaps->bExclusive)) { sem_put(pDriverInst->DriverSem); /* must be last line of routine! */ return CNXT_SMC_NOT_AVAILABLE; } /* * There is a possibility that the pCaps needs to be checked further. * Add that here. */ /* create an instance */ if ( !CREATE_HANDLE(&(pDriverInst->pInstList), &pInst) ) { *pHandle = NULL; sem_put(pDriverInst->DriverSem); /* must be last line of routine! */ return CNXT_SMC_RESOURCE_ERROR; } /* add the instance into the list */ pInst->uUnitNumber = uUnit; if (ADD_HANDLE (&(pUnitInst->pFirstInst), pInst) == FALSE) { DESTROY_HANDLE(&(pDriverInst->pInstList), pInst); sem_put(pDriverInst->DriverSem); /* must be last line of routine! */ return CNXT_SMC_INTERNAL_ERROR; } pInst->Preface.pSelf = (CNXT_HANDLE_PREFACE*)pInst; pInst->pNotifyFn = pNotifyFn; /* Use this fcn to notify appl of events */ pInst->pUserData = pUserData; /* Store data the inst needs */ /* * Put Driver Specific code here. */ /* set driver bExclusive field */ pUnitInst->bExclusive = pCaps->bExclusive; *pHandle = (CNXT_SMC_HANDLE)pInst; sem_put(pDriverInst->DriverSem); /* must be last line of routine! */ return CNXT_SMC_OK; } /* end cnxt_smc_open() */
RedCryptoMetaReaderHandle * scytale_meta_reader_new(RedCryptoReaderHandle * reader) { SCOPED_TRACE; CHECK_HANDLE_R(reader, nullptr); return CREATE_HANDLE(RedCryptoMetaReaderHandle(*reader)); }
ErrorCode WriteGMV::local_write_mesh(const char *file_name, const EntityHandle output_set, const int user_dimension, const bool mesh, const bool poly_mesh) { std::ofstream ofile; ErrorCode result; if (mesh) { // need to insert ".gmv" std::string tmp_name(file_name); tmp_name += ".gmv"; ofile.open(tmp_name.c_str()); } else if (poly_mesh) { // need to insert ".poly.gmv" std::string tmp_name(file_name); tmp_name += ".poly.gmv"; ofile.open(tmp_name.c_str()); } ofile << "gmvinput ascii" << std::endl; // get elements to be output Range dum_range, elements, all_verts; EntityType otype; if (poly_mesh) { result = mbImpl->get_entities_by_type(output_set, MBPOLYGON, elements, true); if (MB_SUCCESS != result) return result; } else { for (otype = CN::TypeDimensionMap[user_dimension].first; otype <= CN::TypeDimensionMap[user_dimension].second; otype++) { if (otype == MBPOLYGON || otype == MBPOLYHEDRON) continue; dum_range.clear(); result = mbImpl->get_entities_by_type(output_set, otype, dum_range, true); if (MB_SUCCESS != result) return result; std::copy(dum_range.begin(), dum_range.end(), range_inserter(elements)); } } // gather the vertices in these elements result = mbImpl->get_adjacencies(elements, 0, false, all_verts, Interface::UNION); if (MB_SUCCESS != result) return result; int num_verts = all_verts.size(); // allocate coordinate arrays and put pointers to them in a list double *xcoord = new double[num_verts]; double *ycoord = new double[num_verts]; double *zcoord = new double[num_verts]; std::vector<double*> coord_arrays; coord_arrays.push_back(xcoord); coord_arrays.push_back(ycoord); coord_arrays.push_back(zcoord); // fill them in, writing id tags at the same time result = mWriteIface->get_node_coords(3, num_verts, all_verts, mGlobalIdTag, 1, coord_arrays); if (MB_SUCCESS != result) return result; int i, j; //======================================== // WRITE COORDINATE DATA TO FILE HERE ofile << "nodev " << num_verts << std::endl; for (i = 0; i < num_verts; i++) ofile << xcoord[i] << " " << ycoord[i] << " " << zcoord[i] << std::endl; //======================================== delete [] xcoord; delete [] ycoord; delete [] zcoord; // iterate over types in selected dimension std::vector<int> connect; std::vector<EntityHandle> connecth; if (mesh) { Range sub_range; ofile << "cells " << elements.size() << std::endl; for (otype = CN::TypeDimensionMap[user_dimension].first; otype <= CN::TypeDimensionMap[user_dimension].second; otype++) { if (otype == MBPOLYGON || otype == MBPOLYHEDRON) continue; // get the first element of this type in the range, and one past the last Range::iterator lower = Range::lower_bound(elements.begin(), elements.end(), CREATE_HANDLE(otype, MB_START_ID, i)); Range::iterator upper = Range::lower_bound(elements.begin(), elements.end(), CREATE_HANDLE(otype+1, MB_START_ID, i)); if (lower == upper) continue; // copy these elements into a subrange sub_range.clear(); std::copy(lower, upper, range_inserter(sub_range)); // make sure the connectivity array is big enough int verts_per = CN::VerticesPerEntity(otype); if (connect.size() < verts_per*sub_range.size()) connect.reserve(verts_per*sub_range.size()); // get the connectivity result = mWriteIface->get_element_connect(sub_range.size(), verts_per, mGlobalIdTag, sub_range, mGlobalIdTag, 1, &connect[0]); if (MB_SUCCESS != result) return result; //======================================== // WRITE CONNECTIVITY DATA TO FILE HERE for (i = 0; i < (int) sub_range.size(); i++) { ofile << gmvTypeNames[otype] << " " << verts_per << std::endl; for (j = i*verts_per; j < (int) (i+1)*verts_per; j++) ofile << connect[j] << " "; ofile << std::endl; } //======================================== } } else if (poly_mesh) { // write polygons/hedra, if any Range polygons, polyhedra; result = mbImpl->get_entities_by_type(output_set, MBPOLYGON, polygons, true); if (MB_SUCCESS != result) return result; result = mbImpl->get_entities_by_type(output_set, MBPOLYHEDRON, polyhedra, true); if (MB_SUCCESS != result) return result; if (polygons.size() == 0) return result; // mark polyhedra with global ids result = mWriteIface->assign_ids(polyhedra, mGlobalIdTag, 1); if (MB_SUCCESS != result) return result; ofile << "faces " << polygons.size() << " " << polyhedra.size() << std::endl; for (Range::iterator rit = polygons.begin(); rit != polygons.end(); rit++) { // get the vertices connecth.clear(); result = mbImpl->get_connectivity(&(*rit), 1, connecth, true); if (MB_SUCCESS != result) return result; if (0 == connecth.size()) continue; // get the polyhedra, if any if (user_dimension == 3) { polyhedra.clear(); result = mbImpl->get_adjacencies(Range(*rit, *rit), 3, false, polyhedra); if (MB_SUCCESS != result) return result; // put them in the connect array connecth.push_back((polyhedra.size() > 0 ? *polyhedra.begin() : 0)); connecth.push_back((polyhedra.size() > 1 ? *polyhedra.rbegin() : 0)); } // replace handles with ids connect.reserve(connecth.size()); // pre-set polyhedra ids in case there aren't any connect[connecth.size()] = 0; connect[connecth.size()+1] = 0; result = mbImpl->tag_get_data(mGlobalIdTag, &connecth[0], connecth.size()-2+polyhedra.size(), &connect[0]); if (MB_SUCCESS != result) return result; // write the data ofile << connecth.size()-2; for (i = 0; i < (int)connecth.size(); i++) ofile << " " << connect[i]; ofile << std::endl; } } ofile << std::endl << "endgmv" << std::endl; ofile.close(); return MB_SUCCESS; }
ErrorCode WriteVtk::gather_mesh(const EntityHandle* set_list, int num_sets, Range& nodes, Range& elems) { ErrorCode rval; int e; if (!set_list || !num_sets) { Range a; rval = mbImpl->get_entities_by_handle(0, a); if (MB_SUCCESS != rval) return rval; Range::const_iterator node_i, elem_i, set_i; node_i = a.lower_bound(a.begin(), a.end(), CREATE_HANDLE( MBVERTEX, 0, e)); elem_i = a.lower_bound( node_i, a.end(), CREATE_HANDLE( MBEDGE, 0, e)); set_i = a.lower_bound( elem_i, a.end(), CREATE_HANDLE(MBENTITYSET, 0, e)); nodes.merge(node_i, elem_i); elems.merge(elem_i, set_i); // Filter out unsupported element types EntityType et = MBEDGE; for (et++; et < MBENTITYSET; et++) { if (VtkUtil::get_vtk_type(et, CN::VerticesPerEntity(et))) continue; Range::iterator eit = elems.lower_bound(elems.begin(), elems.end(), CREATE_HANDLE(et, 0, e)), ep1it = elems.lower_bound(elems.begin(), elems.end(), CREATE_HANDLE(et + 1, 0, e)); elems.erase(eit, ep1it); } } else { std::set<EntityHandle> visited; std::vector<EntityHandle> sets; sets.reserve(num_sets); std::copy(set_list, set_list + num_sets, std::back_inserter(sets)); while (!sets.empty()) { // Get next set EntityHandle set = sets.back(); sets.pop_back(); // Skip sets we've already done if (!visited.insert(set).second) continue; Range a; rval = mbImpl->get_entities_by_handle(set, a); if (MB_SUCCESS != rval) return rval; Range::const_iterator node_i, elem_i, set_i; node_i = a.lower_bound(a.begin(), a.end(), CREATE_HANDLE( MBVERTEX, 0, e)); elem_i = a.lower_bound( node_i, a.end(), CREATE_HANDLE( MBEDGE, 0, e)); set_i = a.lower_bound( elem_i, a.end(), CREATE_HANDLE(MBENTITYSET, 0, e)); nodes.merge(node_i, elem_i); elems.merge(elem_i, set_i); std::copy(set_i, a.end(), std::back_inserter(sets)); a.clear(); rval = mbImpl->get_child_meshsets(set, a); std::copy(a.begin(), a.end(), std::back_inserter(sets)); } for (Range::const_iterator ei = elems.begin(); ei != elems.end(); ++ei) { std::vector<EntityHandle> connect; rval = mbImpl->get_connectivity(&(*ei), 1, connect); if (MB_SUCCESS != rval) return rval; for (unsigned int i = 0; i < connect.size(); ++i) nodes.insert(connect[i]); } } if (nodes.empty()) { MB_SET_ERR(MB_ENTITY_NOT_FOUND, "Nothing to write"); } return MB_SUCCESS; }