本文整理汇总了C++中Collector类的典型用法代码示例。如果您正苦于以下问题:C++ Collector类的具体用法?C++ Collector怎么用?C++ Collector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Collector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: whiteSpaces
int whiteSpaces () {
Collector c;
c.write (" \t \n <?xml \t \n version=\"1.0\" ?> \t \n <opener > \t \n <element/> </opener>");
tcheck (c.state() == XMLStreamDecoder::XS_Closed, "Was valid!");
tcheck (c.received.size() == 1 && c.received[0].name() == "element", "");
return 0;
}
示例2: run_collector
/**
* Function that inits and runs the collector
* @param config_file Destination of the collectors configuration file
*/
int run_collector(const std::string& configFile)
{
Collector collector;
/* read the configuration */
try {
collector.readConfig(configFile);
}catch (exceptions::ConfigError e) {
msg(MSG_FATAL, "Couldn't configure collector: %s", e.what());
return error_states::CONFIG_ERROR;
}
/* start the detection modules */
try {
collector.startModules();
}catch (exceptions::DetectionModuleError e) {
msg(MSG_FATAL, "Couldn't start detection modules: %s", e.what());
return error_states::DETECTION_MODULE_ERROR;
}
/* wait for detection modules to do their initialisation work */
msg(MSG_INFO, "Waiting for detection modules to init their stuff....");
sleep(2);
msg(MSG_INFO, "Starting up collector...");
try {
collector.run();
} catch (std::exception e) {
msg(MSG_FATAL, "Error while running the collector: %s", e.what());
return error_states::RUN_ERROR;
}
msg(MSG_DEBUG, "Leaving run_collector()");
return 0;
}
示例3: GetAllTranslationOptions
translation_table_t PhraseTable::GetAllTranslationOptions(const vector<wid_t> &sentence, context_t *context) {
translation_table_t ttable;
for (size_t start = 0; start < sentence.size(); ++start) {
Collector *collector = self->index->NewCollector(context);
vector<wid_t> phrase;
vector<wid_t> phraseDelta;
for (size_t end = start; end < sentence.size(); ++end) {
wid_t word = sentence[end];
phrase.push_back(word);
phraseDelta.push_back(word);
if (ttable.find(phrase) == ttable.end()) {
vector<sample_t> samples;
collector->Extend(phraseDelta, self->numberOfSamples, samples);
phraseDelta.clear();
if (samples.empty())
break;
vector<TranslationOption> options;
MakeTranslationOptions(self->index, self->aligner, phrase, samples, options);
ttable[phrase] = options;
}
}
delete collector;
}
return ttable;
}
示例4: strangeProtocol
int strangeProtocol () {
Collector c;
c.write ("brevlmlm");
tcheck (c.state() == XMLStreamDecoder::XS_Error, "");
Collector c2;
c2.write ("<?xml version=\"1.0\"?> renterntknt4kntkntkln");
tcheck (c2.state() == XMLStreamDecoder::XS_Error, "");
return 0;
}
示例5: TEST
TEST(Collector, CanRegister)
{
Collector c;
auto t = std::make_shared<Timer>();
auto uc = std::make_shared<UnsignedCounter>();
c.register_metric(t);
c.register_metric(uc);
std::cout << c.report();
}
示例6: reduce
bool PageRankReducer::reduce(const void* key, KeyValueIterator& values, Collector& collector) const
{
//<url, pagerank, linkoutlist> as reducer intput
//<url, newpagerank, linkoutlist> as reducer output
//the formula of pagerank:
//pr(a) - (1-d) = d * (pr(b)/l(b) + pr(c)/l(c) + ...)
//d is the damping factor
PageRankValue value;
int count = 0;
const double damping = 0.85;
while(values.hasMore()){
PageRankValue* pValue = (PageRankValue*)(values.next());
value.pagerank += damping * pValue->pagerank;
if(pValue->linkoutURLs.size() > 0){
for(int i = 0; i < pValue->linkoutURLs.size(); i ++){
value.linkoutURLs.push_back(pValue->linkoutURLs[i]);
}
}
count ++;
}
collector.collect(key, &value);
return true;
}
示例7: makeRules
ulen TopLang::makeRules(Collector<RuleRec> &collector,const CondLangBase::RuleDesc &rule)
{
ulen ret=0;
DynArray<ElementRecExt> temp(DoCast(rule.args.len),rule.args.ptr);
{
ulen index=0;
for(auto &rec : temp ) rec.element_index=index++;
}
auto args=Range(temp);
do
{
if( TestCond(Range_const(args),rule.cond) )
{
collector.append_fill(makeRuleName(rule.name,Range_const(args)),rule.index,Range_const(args));
ret++;
}
}
while( Next(args) );
return ret;
}
示例8: find_connecting
CollectorArray::iterator find_connecting( CollectorArray::iterator& target, CollectorArray& input )
{
CollectorArray::iterator ret = input.end();
Collector* pp = *target;
if ( pp->checkClosed() ) {
return ret;
}
if (overlap( pp->_points.back(), pp->_points.front() ) ) {
// poly2tri only accept polyline with non repeating points
pp->_points.pop_back();
pp->_closed = true;
return ret;
}
// Look for another unclosed path of the same style,
// which could join our begin or end point.
for (CollectorArray::iterator it = input.begin(); it != input.end(); ++it) {
Collector* po = (*it);
if ( pp == po )
continue;
if ( po->checkClosed() )
continue;
// Can we join?
PointDataArray::iterator pStart = pp->_points.begin();
PointDataArray::iterator oStart = po->_points.begin();
if (overlap( *oStart, pp->_points.back() ) ) {
// Yes, po can be appended to pp.
pp->_points.insert( pp->_points.end(), ++oStart, po->_points.end());
po->_right_style = Path::kINVALID;
MergeRectangle(pp->_bound, po->_bound);
ret = it; // remove this iterator and restart
return ret;
} else if (overlap( *pStart, po->_points.back() ) ) {
// Yes, pp can be appended to po.
po->_points.insert( po->_points.end(), ++pStart, pp->_points.end());
pp->_right_style = Path::kINVALID;
MergeRectangle(po->_bound, pp->_bound);
ret = target; // remove this iterator and restart
return ret;
}
}
return ret;
}
示例9: startApp
extern "C" int startApp(thread_arg_t* arg) {
int argc = arg->argc;
char** argv = arg->argv;
create_vm_t func = arg->func;
free(arg);
#ifndef MULTIPLE_GC
Collector::inject_my_thread(&argc);
VirtualMachine* VM = func();
VM->runApplication(argc, argv);
Collector::remove_my_thread();
Collector::collect();
#else
Collector* GC = Collector::allocate();
GC->inject_my_thread(&argc);
func(argc, argv);
GC->remove_my_thread();
GC->collect();
#endif
return 0;
}
示例10: RunTest
void RunTest(SuffixArray &index, const context_t *context,
const unordered_map<vector<wid_t>, size_t, phrase_hash> &ngrams, vector<speed_perf_t> &speedData) {
size_t queryCount = 0;
for (auto entry = ngrams.begin(); entry != ngrams.end(); ++entry) {
Collector *collector = index.NewCollector(context, true);
for (size_t i = 0; i < entry->first.size(); ++i) {
double begin = GetTime();
vector<sample_t> samples;
collector->Extend(entry->first[i], 1000, samples);
speedData[i].seconds += GetElapsedTime(begin);
speedData[i].requests++;
queryCount++;
if (queryCount % 10000 == 0)
cout << "." << flush;
}
delete collector;
}
}
示例11: map
bool WordFrequencyMapper::map(const void* key, const void* value, Collector& collector) const
{
//<char*, char*> as mapper intput
//<char*, int> as mapper output
int outValue = 1;
int outputCnt = 0;
int bodyLen = strlen(*(char**)value);
//do parsing
m_parser->init_page(*(char**)value);
m_parser->convert_charset("skip");
m_parser->delete_tags();
m_parser->cut_words(1);
m_parser->end_page();
//processing with the keywords list
char *p = m_parser->get_keywords();
//cout << p << endl;
p=strtok(p," ");
while(p){
switch(*p){
case DELI_WEIGHT:
case DELI_LOC:
case DELI_PARA:
//skip these tokens
break;
case '\0':
cout << "+";
default:{
char** pData = &p;
collector.collect( pData, &outValue);
outputCnt ++;
}
}
p=strtok(NULL," ");
}
//cout << *(char**)key << " : " << bodyLen << " : " << outputCnt << endl;
return true;
}
示例12: OnMouse
void OnMouse(int event, int x, int y, int flags, void *userdata) {
Collector *c = (Collector *)userdata;
c->OnClick(event, x, y, flags, NULL);
}
示例13: map
TopLang::TopLang(const CondLang &clang)
{
Collector<RuleRec> collector;
DynArray<ulen> map(DoRaw(clang.getSyntCount()));
// atoms
{
auto range=clang.getAtoms();
auto atoms=createAtoms(range.len);
for(; +atoms ;++atoms,++range)
{
atoms->index=range->index;
atoms->name=pool.dup(range->name);
atoms->map_index=range->index;
}
}
// synts
{
auto range=clang.getSynts();
ulen len=0;
for(auto &synt : range ) len=LenAdd(len, Max<ulen>(synt.kinds.len,1) );
auto synts=createSynts(len);
ulen index=0;
ulen map_index=0;
for(; +range ;++range,++map_index)
if( +range->kinds )
{
map[map_index]=index;
StrLen name=range->name;
bool is_lang=range->is_lang;
ulen desc_map_index=range->index;
for(auto &kind : range->kinds )
{
synts->rules.len=makeRules(collector,*range,kind.index);
synts->index=index++;
synts->name=pool.cat(name,StrLen(".",1),kind.name);
synts->is_lang=is_lang;
synts->map_index=desc_map_index;
synts->kind_index=kind.index;
++synts;
}
}
else
{
map[map_index]=index;
synts->rules.len=makeRules(collector,*range);
synts->index=index++;
synts->name=pool.dup(range->name);
synts->is_lang=range->is_lang;
synts->map_index=range->index;
++synts;
}
}
// rules
{
auto range=collector.flat();
auto rules=createRules(range.len);
auto atoms=getAtoms();
auto synts=getSynts();
ulen index=0;
for(; +rules ;++rules,++range)
{
rules->index=index++;
rules->name=range->name;
rules->map_index=range->map_index;
auto arange=Range_const(range->args);
auto args=createElements(*rules,arange.len);
for(; +args ;++args,++arange)
{
arange->element.apply( [=] (const CondLangBase::AtomDesc *atom) { args->ptr=&(atoms[atom->index]); } ,
[=,&map] (const CondLangBase::SyntDesc *synt) { args->ptr=&(synts[map[synt->index]+arange->kind_index]); } );
//.........这里部分代码省略.........
示例14: while
void CircuitsWidget::deserialize(QString fileName) {
std::string fn = fileName.toUtf8().constData();
// n.b. Use this to convert QString in std::string on Windows!
//std::string fn = qs.toLocal8Bit().constData();
string line;
ifstream file;
file.open(fn.c_str());
// test
while(getline(file,line)){
if(line.compare("#") == 0){
getline(file,line); // reading type
int t = atoi(line.c_str());
getline(file,line); // reading id
int id = atoi(line.c_str());
getline(file,line); // reading x position
int x = atoi(line.c_str());
getline(file,line); // reading y position
int y = atoi(line.c_str());
getline(file,line); // reading width
int w = atoi(line.c_str());
getline(file,line); // reading height
int h = atoi(line.c_str());
getline(file,line); // reading value
string sval = line;
int val = atoi(line.c_str());
switch(t) {
case(8):{
//muler
Muler *m = new Muler(this);
drawComponent(m);
m->setId(id);
m->move(x,y);
m->resize(w,h);
m->setValue(val);
break;
}
case(7):{
//diver
Diver *d = new Diver(this);
drawComponent(d);
d->setId(id);
d->move(x,y);
d->resize(w,h);
d->setValue(val);
// NOTE: this is a particular case, please see under in "restoring connections"
break;
}
case(6):{
//noter
Noter *n = new Noter(this);
drawComponent(n);
n->setId(id);
n->move(x,y);
n->resize(w,h);
n->setValue(val);
break;
}
case(5):{
//orer
Orer *o = new Orer(this);
drawComponent(o);
o->setId(id);
o->move(x,y);
o->resize(w,h);
o->setValue(val);
break;
}
case(4):{
// ander
Ander *a = new Ander(this);
drawComponent(a);
a->setId(id);
a->move(x,y);
a->resize(w,h);
a->setValue(val);
break;
}
case(3):{
// variable
Variable *v = new Variable(this);
drawComponent(v);
v->setId(id);
v->move(x,y);
v->resize(w,h);
v->setValue(val);
v->var->setPlaceholderText(sval.c_str());
break;
}
case(2):{
// collector
Collector *c = new Collector(this);
drawComponent(c);
c->setId(id);
c->move(x,y);
c->resize(w,h);
c->setValue(val);
break;
}
case(1):{
// adder
//.........这里部分代码省略.........
示例15: on_read
static void
on_read (gpointer data)
{
counter_t *counter = data;
int mask = (N_PAGES * get_page_size() - 1);
int n_bytes = mask + 1;
gboolean skip_samples;
Collector *collector;
uint64_t head, tail;
collector = counter->collector;
tail = counter->tail;
head = counter->mmap_page->data_head;
rmb();
if (head < tail)
{
g_warning ("sysprof fails at ring buffers (head "FMT64", tail "FMT64"\n", head, tail);
tail = head;
}
#if 0
/* Verify that the double mapping works */
x = g_random_int() & mask;
g_assert (*(counter->data + x) == *(counter->data + x + n_bytes));
#endif
skip_samples = in_dead_period (collector);
#if 0
g_print ("n bytes %d\n", head - tail);
#endif
while (head - tail >= sizeof (struct perf_event_header))
{
struct perf_event_header *header;
guint8 buffer[4096];
guint8 *free_me;
free_me = NULL;
/* Note that:
*
* - perf events are a multiple of 64 bits
* - the perf event header is 64 bits
* - the data area is a multiple of 64 bits
*
* which means there will always be space for one header, which means we
* can safely dereference the size field.
*/
header = (struct perf_event_header *)(counter->data + (tail & mask));
if (header->size > head - tail)
{
/* The kernel did not generate a complete event.
* I don't think that can happen, but we may as well
* be paranoid.
*/
break;
}
if (counter->data + (tail & mask) + header->size > counter->data + n_bytes)
{
int n_before, n_after;
guint8 *b;
if (header->size > sizeof (buffer))
free_me = b = g_malloc (header->size);
else
b = buffer;
n_after = (tail & mask) + header->size - n_bytes;
n_before = header->size - n_after;
memcpy (b, counter->data + (tail & mask), n_before);
memcpy (b + n_before, counter->data, n_after);
header = (struct perf_event_header *)b;
}
if (!skip_samples || header->type != PERF_RECORD_SAMPLE)
{
if (header->type == PERF_RECORD_SAMPLE)
collector->n_samples++;
process_event (collector, counter, (counter_event_t *)header);
}
if (free_me)
g_free (free_me);
tail += header->size;
}
counter->tail = tail;
counter->mmap_page->data_tail = tail;
//.........这里部分代码省略.........