static c_bool copyInstanceHandle( v_dataReaderInstance instance, c_voidp arg) { c_bool result = TRUE; struct copyInstanceHandle *a = (struct copyInstanceHandle *)arg; DDS::InstanceHandle_t ghandle; os_uint32 length; if (a->index ==0) { length = c_count(v_dataReaderInstanceGetNotEmptyInstanceSet(instance)); if (length > a->seq->maximum()) { a->seq->length(length); /* potentially reallocate */ } } ghandle = u_instanceHandleNew((v_public)instance); if (a->index < a->seq->maximum()) { (*a->seq)[a->index++] = ghandle; } else { /* error index out of bounds */ } return result; }
void GetCounts(std::vector<ABCDCount>& counts, std::vector<TTree*>& trees, const std::vector<double>& weights){ counts.resize(trees.size()); for(unsigned int i(0); i<trees.size(); ++i){ if(trees.at(i)->GetEntries()>0){ std::vector<double> a_count(4), b_count(4), c_count(4), d_count(4); trees.at(i)->SetBranchAddress("AWeighted_sbin1", &a_count.at(0)); trees.at(i)->SetBranchAddress("AWeighted_sbin2", &a_count.at(1)); trees.at(i)->SetBranchAddress("AWeighted_sbin3", &a_count.at(2)); trees.at(i)->SetBranchAddress("AWeighted_sbin4", &a_count.at(3)); trees.at(i)->SetBranchAddress("BWeighted_sbin1", &b_count.at(0)); trees.at(i)->SetBranchAddress("BWeighted_sbin2", &b_count.at(1)); trees.at(i)->SetBranchAddress("BWeighted_sbin3", &b_count.at(2)); trees.at(i)->SetBranchAddress("BWeighted_sbin4", &b_count.at(3)); trees.at(i)->SetBranchAddress("C2bWeighted_sbin1", &c_count.at(0)); trees.at(i)->SetBranchAddress("C2bWeighted_sbin2", &c_count.at(1)); trees.at(i)->SetBranchAddress("C2bWeighted_sbin3", &c_count.at(2)); trees.at(i)->SetBranchAddress("C2bWeighted_sbin4", &c_count.at(3)); trees.at(i)->SetBranchAddress("D2bWeighted_sbin1", &d_count.at(0)); trees.at(i)->SetBranchAddress("D2bWeighted_sbin2", &d_count.at(1)); trees.at(i)->SetBranchAddress("D2bWeighted_sbin3", &d_count.at(2)); trees.at(i)->SetBranchAddress("D2bWeighted_sbin4", &d_count.at(3)); trees.at(i)->GetEntry(0); counts.at(i).SetCounts(a_count, b_count, c_count, d_count); counts.at(i).SetWeight(weights.at(i)); } } }
typename property_traits<ComponentsMap>::value_type kosaraju_strong_components(Graph& G, ComponentsMap c, FinishTime finish_time, ColorMap color) { function_requires< MutableGraphConcept<Graph> >(); // ... typedef typename graph_traits<Graph>::vertex_descriptor Vertex; typedef typename property_traits<ColorMap>::value_type ColorValue; typedef color_traits<ColorValue> Color; typename property_traits<FinishTime>::value_type time = 0; depth_first_search (G, make_dfs_visitor(stamp_times(finish_time, time, on_finish_vertex())), color); Graph G_T(num_vertices(G)); transpose_graph(G, G_T); typedef typename property_traits<ComponentsMap>::value_type count_type; count_type c_count(0); detail::components_recorder<ComponentsMap> vis(c, c_count); // initialize G_T typename graph_traits<Graph>::vertex_iterator ui, ui_end; for (tie(ui, ui_end) = vertices(G_T); ui != ui_end; ++ui) put(color, *ui, Color::white()); typedef typename property_traits<FinishTime>::value_type D; typedef indirect_cmp< FinishTime, std::less<D> > Compare; Compare fl(finish_time); std::priority_queue<Vertex, std::vector<Vertex>, Compare > Q(fl); typename graph_traits<Graph>::vertex_iterator i, j, iend, jend; tie(i, iend) = vertices(G_T); tie(j, jend) = vertices(G); for ( ; i != iend; ++i, ++j) { put(finish_time, *i, get(finish_time, *j)); Q.push(*i); } while ( !Q.empty() ) { Vertex u = Q.top(); Q.pop(); if (get(color, u) == Color::white()) { depth_first_visit(G_T, u, vis, color); ++c_count; } } return c_count; }
inline typename property_traits<Components>::value_type connected_components(Graph& g, DFSVisitor v, Components c, Color color, undirected_tag) { typedef typename property_traits<Components>::value_type count_type; count_type c_count(-1); // we want first component to be '0', and the increment happens first typedef components_recorder<Components, DFSVisitor> ComponentRecorder; ComponentRecorder vis(c, c_count, v); depth_first_search(g, vis, color); return c_count + 1; }
inline typename property_traits<Components>::value_type connected_components(Graph& G, DFSVisitor v, Components c, DiscoverTime d, FinishTime f, Color color, directed_tag) { typedef typename graph_traits<Graph>::vertex_descriptor Vertex; typename property_traits<Color>::value_type cc = get(color, Vertex()); int time = 0; depth_first_search(G, record_times(d, f, time, v), color); Graph G_T(num_vertices(G)); transpose_graph(G, G_T); typedef typename property_traits<Components>::value_type count_type; count_type c_count(0); components_recorder<Components, dfs_visitor<> > vis(c, c_count, dfs_visitor<>()); // initialize G_T typename graph_traits<Graph>::vertex_iterator ui, ui_end; for (tie(ui, ui_end) = vertices(G_T); ui != ui_end; ++ui) put(color, *ui, white(cc)); typedef typename property_traits<FinishTime>::value_type D; typedef indirect_cmp< FinishTime, std::less<D> > Compare; Compare fl(f); priority_queue<Vertex, std::vector<Vertex>, Compare > Q(fl); typename graph_traits<Graph>::vertex_iterator i, j, iend, jend; tie(i, iend) = vertices(G_T); tie(j, jend) = vertices(G); for ( ; i != iend; ++i, ++j) { put(f, *i, get(f, *j)); Q.push(*i); } while ( !Q.empty() ) { Vertex u = Q.top(); Q.pop(); if (get(color, u) == white(cc)) { depth_first_visit(G_T, u, vis, color); ++c_count; } } return c_count; }
inline typename property_traits<ComponentsMap>::value_type connected_components(const Graph& g, ComponentsMap c, ColorMap color, DFSVisitor v) { function_requires< VertexListGraphConcept<Graph> >(); typedef typename graph_traits<Graph>::vertex_descriptor Vertex; function_requires< ReadWritePropertyMapConcept<ColorMap, Vertex> >(); function_requires< WritablePropertyMapConcept<ComponentsMap, Vertex> >(); function_requires< DFSVisitorConcept<DFSVisitor, Graph> >(); // ... typedef typename property_traits<ComponentsMap>::value_type comp_type; // c_count initialized to "nil" (with nil represented by max()) comp_type c_count(std::numeric_limits<comp_type>::max()); detail::components_recorder<ComponentsMap, DFSVisitor> vis(c, c_count, v); depth_first_search(g, vis, color); return c_count + 1; }
/* Do not use C_TYPECHECK on qos parameter, since it might be allocated on heap! */ kernel = v_objectKernel(p); c_lockWrite(&p->lock); result = v_participantQosSet(p->qos, qos, &cm); if ((result == V_RESULT_OK) && (cm != 0)) { builtinMsg = v_builtinCreateParticipantInfo(kernel->builtin,p); c_lockUnlock(&p->lock); v_writeBuiltinTopic(kernel, V_PARTICIPANTINFO_ID, builtinMsg); c_free(builtinMsg); } else { c_lockUnlock(&p->lock); } return result; } v_leaseManager v_participantGetLeaseManager( v_participant p) { assert(C_TYPECHECK(p,v_participant)); return c_keep(p->leaseManager); } #define RESEND_SECS (0U) #define RESEND_NANOSECS (2000000U) /* 2 ms */ void v_participantResendManagerMain( v_participant p) { c_iter writerProxies; v_proxy wp; v_writer w; v_handleResult r; c_time waitTime = { RESEND_SECS, RESEND_NANOSECS }; assert(C_TYPECHECK(p,v_participant)); c_mutexLock(&p->resendMutex); while (!p->resendQuit) { if (c_count(p->resendWriters) == 0) { c_condWait(&p->resendCond, &p->resendMutex); } else { c_condTimedWait(&p->resendCond, &p->resendMutex, waitTime); } if (!p->resendQuit) { writerProxies = c_select(p->resendWriters, 0); c_mutexUnlock(&p->resendMutex); wp = v_proxy(c_iterTakeFirst(writerProxies)); while (wp != NULL) { r = v_handleClaim(wp->source,(v_object *)&w); if (r == V_HANDLE_OK) { assert(C_TYPECHECK(w,v_writer)); v_writerResend(w); v_handleRelease(wp->source); } c_free(wp); wp = v_proxy(c_iterTakeFirst(writerProxies)); } c_iterFree(writerProxies); c_mutexLock(&p->resendMutex); } /* already quiting */ } c_mutexUnlock(&p->resendMutex); }
static c_array copyReaderGIDsFromPublications( v_deliveryGuard _this) { /* copy system Ids from _this->publications */ C_STRUCT(copySystemIdsArg) arg; c_long size; if (_this->publications) { size = c_count(_this->publications); } else { size = 0; } if (size > 0) { arg.readerGID = c_arrayNew(_this->gidType,size); arg.index = 0; c_walk(_this->publications, copySystemIds, &arg); } else { arg.readerGID = NULL; } return arg.readerGID; }
c_bool v_partitionAdminSet( v_partitionAdmin da, v_partitionPolicy partitionExpr, c_iter *addedPartitions, c_iter *removedPartitions) { c_iter dexpressions; /* iterator of partition expressions */ c_char *dexpr; /* partition expression */ v_partitionInterest di; struct resolvePartitionsArg resolveArg; struct updatePartitionsArg updateArg; assert(C_TYPECHECK(da, v_partitionAdmin)); assert(removedPartitions != NULL); assert(addedPartitions != NULL); *removedPartitions = NULL; *addedPartitions = NULL; resolveArg.kernel = v_objectKernel(da); c_mutexLock(&da->mutex); /* * The absolute partition names will be added at the end of * the algorithm. * The partition expressions in the parameter of partitionExpr, * replace the existing in da->partitionInterests. */ c_free(da->partitionInterests); da->partitionInterests = c_tableNew(v_kernelType(resolveArg.kernel, K_DOMAININTEREST), "expression"); assert(c_count(da->partitionInterests) == 0); dexpressions = v_partitionPolicySplit(partitionExpr); if (dexpressions == NULL) { /* switch to default */ *addedPartitions = c_iterInsert(*addedPartitions, v_partitionNew(resolveArg.kernel, "", NULL)); } else { dexpr = (c_char *)c_iterTakeFirst(dexpressions); while (dexpr != NULL) { if (v_partitionExpressionIsAbsolute(dexpr)) { *addedPartitions = c_iterInsert(*addedPartitions, v_partitionNew(resolveArg.kernel, dexpr, NULL)); /* ref transferred to addedPartitions */ } else { di = v_partitionInterestNew(resolveArg.kernel, (const c_char *)dexpr); c_tableInsert(da->partitionInterests, di); c_free(di); } os_free(dexpr); dexpr = (c_char *)c_iterTakeFirst(dexpressions); } c_iterFree(dexpressions); } /* * The given expressions are now divided across * 'addedpartitions' and 'da->partitionInterests'. * Now first add partitions to 'addedpartitions' that fit the * expressions in 'da->partitionInterests'. */ resolveArg.partitions = addedPartitions; c_tableWalk(da->partitionInterests, resolvePartitions, (c_voidp)&resolveArg); /* * Now 'addedpartitions' contains all partitions to be added * by the publisher/subscriber. * 'da->partitions' contains the old set of partitions. * We must check whether those partitions must remain in * the set or must be removed. * For every partition in 'da->partitions' do * if partition in 'addedpartitions' then remove from 'addedpartitions' * else add to 'removedpartitions' * For every partition in 'removedpartitions' remove from 'da->partitions'. */ updateArg.addPartitions = addedPartitions; updateArg.removePartitions = removedPartitions; c_tableWalk(da->partitions, updatePartitions, (c_voidp)&updateArg); c_iterWalk(*removedPartitions, removePartition, (c_voidp)da->partitions); /* * The da->partitions now contains partitions that still comply to new * partitionPolicy. So all partitions in added partitions, must be added * to da->partitions, so it reflects all connected partitions. */ c_iterWalk(*addedPartitions, addPartition, (c_voidp)da->partitions); c_mutexUnlock(&da->mutex); return TRUE; }
static void printCollection( c_collectionType type, toolActionData actionData) { c_long size, i, offset, esize; c_object o; c_voidp p; c_object arrayElement; c_type subtype; c_bool isRef; o = c_iterObject(actionData->stack, 0); switch (type->kind) { case C_ARRAY: case C_SEQUENCE: /* Walk over all entries */ switch (type->kind) { case C_ARRAY: if (type->maxSize == 0) { size = c_arraySize((c_array)o); } else { size = type->maxSize; } break; case C_SEQUENCE: size = c_arraySize((c_array)o); break; default: size = 0; assert(FALSE); break; } if (c_typeIsRef(type->subType)) { esize = sizeof(c_voidp); isRef = TRUE; } else { esize = type->subType->size; isRef = FALSE; } p = o; offset = 0; for (i=0; i<size; i++) { iprintf("Element (%d) Offset (%d)\n",i,offset); arrayElement = isRef ? *((c_object *)p) : (c_object) p; if (arrayElement != NULL) { OBJECT_PUSH(actionData, arrayElement); if (isRef) { subtype = c_getType(arrayElement); printType(subtype, actionData); } else { iprintf(" "); printType(type->subType, actionData); } printf("\n"); OBJECT_POP(actionData); } else { iprintf(" <0x0>\n"); } p = C_DISPLACE(p, esize); offset += esize; } break; case C_STRING: printf(" \"%s\"",(c_char *)o); break; case C_SET: case C_LIST: case C_BAG: case C_DICTIONARY: case C_QUERY: { if (o != NULL) { /* Walk over the elements */ c_walk(o, (c_action)printCollectionAction, actionData); if (c_count(o) == 0) { iprintf("<EMPTY>"); } } else { iprintf("<NULL>"); } } break; case C_SCOPE: c_scopeWalk(o, printCollectionAction, actionData); break; default: printf("Specified type <0x"PA_ADDRFMT"> is not a valid collection type\n", (os_address)type); break; } }