当前位置: 首页>>代码示例>>C++>>正文


C++ Counter类代码示例

本文整理汇总了C++中Counter的典型用法代码示例。如果您正苦于以下问题:C++ Counter类的具体用法?C++ Counter怎么用?C++ Counter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Counter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: AggregateStat

Stat* ProcStats::replStat(Stat* s, const char* name, const char* desc) {
    if (!name) name = s->name();
    if (!desc) desc = s->desc();
    if (AggregateStat* as = dynamic_cast<AggregateStat*>(s)) {
        AggregateStat* res = new AggregateStat(as->isRegular());
        res->init(name, desc);
        for (uint32_t i = 0; i < as->size(); i++) {
            res->append(replStat(as->get(i)));
        }
        return res;
    } else if (dynamic_cast<ScalarStat*>(s)) {
        Counter* res = new ProcessCounter(this);
        res->init(name, desc);
        return res;
    } else if (VectorStat* vs = dynamic_cast<VectorStat*>(s)) {
        VectorCounter* res = new ProcessVectorCounter(this);
        assert(!vs->hasCounterNames());  // FIXME: Implement counter name copying
        res->init(name, desc, vs->size());
        return res;
    } else {
        panic("Unrecognized stat type");
        return nullptr;
    }
}
开发者ID:8l,项目名称:zsim,代码行数:24,代码来源:proc_stats.cpp

示例2: filter

void TimestampMergeFilter::filter(){
	Counter counter;
	counter.registerCallback([&](uint64_t countPerSec){
		string msg = to_string(countPerSec) + " line/s";
		if(m_inputQueue->empty()) msg += "\tstarving!";
		if(m_outputQueue->full()) msg += "\tblocked!";
		m_msgQueue->enqueue(Message(TIMESTAMP_MERGE_FILTER, msg));
	});
	counter.start();

	try{
		while(true){
			Observation obs = m_inputQueue->dequeue();
			if(m_buffer.empty()){
				m_buffer.push_front(obs);
			} else{
				if(*obs.date == *m_buffer.front().date && *obs.time == *m_buffer.front().time){
					m_buffer.push_front(obs);
				} else{
					m_outputQueue->enqueue(getMergedObs());
					m_buffer.clear();
					counter.tick();
					m_buffer.push_front(obs);
				}
			}
		}
	} catch(ObsQueue::QueueEndException&){
		if(!m_buffer.empty()){
			m_outputQueue->enqueue(getMergedObs());
			counter.stop();
			m_buffer.clear();
		}
		m_msgQueue->enqueue(Message(TIMESTAMP_MERGE_FILTER, "Finished !"));
		m_outputQueue->setQueueEnd();
	}
}
开发者ID:thomas-picariello,项目名称:BidAskSpread,代码行数:36,代码来源:TimestampMergeFilter.cpp

示例3: setAnchorPoint

bool MainLayer::init()
{
	/*-- 设置整体层属性 --*/
	this->setTouchMode(kCCTouchesOneByOne);
	this->setTouchEnabled(true);
	this->scheduleUpdate();
	CCSize s = CCDirector::sharedDirector()->getWinSize();
	this->ignoreAnchorPointForPosition(true);
	setAnchorPoint(ccp(0.5f, 0.5f));
	this->setContentSize(s);
	setPosition(ccp(s.width / 2, s.height / 2));

	CCSize vsize = CCDirector::sharedDirector()->getVisibleSize();
	float width = vsize.width / 2;
	float height = vsize.height / 2;
	Counter *counter = Counter::sharedCounter();
	counter->clearScore();
	if (counter->isSound()
			&& !SimpleAudioEngine::sharedEngine()->isBackgroundMusicPlaying())
	{
		SimpleAudioEngine::sharedEngine()->playBackgroundMusic("bgm.mp3", true);
	}
	/*-- door --*/
	CCAnimation *doorAnimation =
			CCAnimationCache::sharedAnimationCache()->animationByName("door");
	//左侧
	CCSprite *leftDoor = CCSprite::createWithSpriteFrameName("door_1.png");
	leftDoor->setPosition(ccp(-200, -50));
	leftDoor->setAnchorPoint(ccp(0.5, 0.5));
	this->addChild(leftDoor);
	leftDoor->runAction(
			CCRepeatForever::create(CCAnimate::create(doorAnimation)));

	//右侧
	CCSprite *rightDoor = CCSprite::createWithSpriteFrameName("door_1.png");
	rightDoor->setPosition(ccp(200, -50));
	rightDoor->setAnchorPoint(ccp(0.5, 0.5));
	this->addChild(rightDoor);
	rightDoor->runAction(
			CCRepeatForever::create(CCAnimate::create(doorAnimation)));

	/*-- 分数 --*/
	CCLabelTTF *titletxt = CCLabelTTF::create(counter->getStringByKey("score"),
			counter->getStringByKey("font"), 46);
	titletxt->setColor(ccc3(98, 104, 191));
	titletxt->setAnchorPoint(ccp(0.5, 0.5));
	titletxt->setPosition(ccp(0, height - 130));
	this->addChild(titletxt);
	CCNode *scoreLabel = counter->create_label();
	scoreLabel->setPosition(ccp(0, height - 200));
	scoreLabel->setAnchorPoint(ccp(0.5, 1));
	this->addChild(scoreLabel, 3, TAG_SCORE);
	/*-- role --*/
	return true;
}
开发者ID:beforeeight,项目名称:bump,代码行数:55,代码来源:MainLayer.cpp

示例4: setupCounter

void KMod::setupCounter(Counter &counter) {
	char base[128];
	char text[128];
	snprintf(base, sizeof(base), "/dev/gator/events/%s", counter.getType());

	snprintf(text, sizeof(text), "%s/enabled", base);
	int enabled = true;
	if (DriverSource::writeReadDriver(text, &enabled) || !enabled) {
		counter.setEnabled(false);
		return;
	}

	int value = 0;
	snprintf(text, sizeof(text), "%s/key", base);
	DriverSource::readIntDriver(text, &value);
	counter.setKey(value);

	snprintf(text, sizeof(text), "%s/cores", base);
	if (DriverSource::readIntDriver(text, &value) == 0) {
		counter.setCores(value);
	}

	snprintf(text, sizeof(text), "%s/event", base);
	DriverSource::writeDriver(text, counter.getEvent());
	snprintf(text, sizeof(text), "%s/count", base);
	if (access(text, F_OK) == 0) {
		int count = counter.getCount();
		if (DriverSource::writeReadDriver(text, &count) && counter.getCount() > 0) {
			logg->logError(__FILE__, __LINE__, "Cannot enable EBS for %s:%i with a count of %d\n", counter.getType(), counter.getEvent(), counter.getCount());
			handleException();
		}
		counter.setCount(count);
	} else if (counter.getCount() > 0) {
		ConfigurationXML::remove();
		logg->logError(__FILE__, __LINE__, "Event Based Sampling is only supported with kernel versions 3.0.0 and higher with CONFIG_PERF_EVENTS=y, and CONFIG_HW_PERF_EVENTS=y. The invalid configuration.xml has been removed.\n");
		handleException();
	}
}
开发者ID:mreyna1216,项目名称:gator,代码行数:38,代码来源:KMod.cpp

示例5: main

int main()
{
	Counter counter;
	for(int i=0; i<10; i++)
		counter.hit();
	sleep(2);
	for(int i=0; i<5; i++)
		counter.hit();
	sleep(3);
	cout<<counter.getCount()<<endl;
	for(int i=0; i<10; i++)
		counter.hit();
	sleep(6);
	cout<<counter.getCount()<<endl;
	sleep(3);
	cout<<counter.getCount()<<endl;
	
	return 0;
}
开发者ID:caogl,项目名称:Algorithms_practice,代码行数:19,代码来源:main.cpp

示例6: playWithCounter

void playWithCounter(Counter& ctr)
{
	ctr++;
	print (ctr);
	ctr++;
	print (ctr);
	ctr++;
	print (ctr);
	ctr++;
	print (ctr);

	ctr--;
	print (ctr);
	ctr--;
	print (ctr);
	ctr--;
	print (ctr);

	ctr.reset();
	print (ctr);
	ctr--;
	print (ctr);
}
开发者ID:duhone,项目名称:college,代码行数:23,代码来源:assign3.cpp

示例7: switch

JSValue* JSCounter::getValueProperty(ExecState* exec, int token) const
{
    switch (token) {
    case IdentifierAttrNum: {
        Counter* imp = static_cast<Counter*>(impl());

        return jsString(imp->identifier());
    }
    case ListStyleAttrNum: {
        Counter* imp = static_cast<Counter*>(impl());

        return jsString(imp->listStyle());
    }
    case SeparatorAttrNum: {
        Counter* imp = static_cast<Counter*>(impl());

        return jsString(imp->separator());
    }
    case ConstructorAttrNum:
        return getConstructor(exec);
    }
    return 0;
}
开发者ID:Crawping,项目名称:davinci,代码行数:23,代码来源:JSCounter.cpp

示例8: print

void print(const Counter& ctr)
{
	cout << ctr.getCounterValue() << endl;
}
开发者ID:duhone,项目名称:college,代码行数:4,代码来源:assign3.cpp

示例9: Counter

void TestEventCounter::testIncreaseWeightedCounter() {
	Counter counter = Counter(dimension1, dimension2, dimension3);
	counter.increase(0, 0, 0, 2.4);
	ASSERT_EQUAL_DELTA(2.4, counter.getWeightedEntries(0, 0, 0), 0.1);
}
开发者ID:BristolTopGroup,项目名称:AnalysisSoftware,代码行数:5,代码来源:TestEventCounter.cpp

示例10: main

int main()
{
    Counter MomCounter;
    char choice;

    cout<<setw(4)<<setfill('0') << endl <<MomCounter.GetCount() << endl << endl;

    cin>>choice;

    choice=toupper(choice);


    while(choice!='X')
    {
        switch(choice)
        {

            case 'F':
                if(MomCounter.GetCount()+1<=MomCounter.GetMax())
                {
                MomCounter.Incr1();
                }
                else
                {
                    cout << "\n|OVERFLOW|\n";
                }

                break;

            case 'D':
                if(MomCounter.GetCount()+10<=MomCounter.GetMax())
                {
                    MomCounter.Incr10();
                }
                else
                {
                    cout << "\n|OVERFLOW|\n";
                }
                break;

            case 'S':
                if(MomCounter.GetCount()+100<=MomCounter.GetMax())
                {
                    MomCounter.Incr100();
                }
                else
                {
                    cout << "\n|OVERFLOW|\n";
                }
                break;

            case 'A':
                if(MomCounter.GetCount()+1000<=MomCounter.GetMax())
                {
                    MomCounter.Incr1000();
                }
                else
                {
                    cout << "\n|OVERFLOW|\n";
                }
                break;


            case 'R':
                MomCounter.Reset();
                break;


        }
        cout<<setw(4)<<setfill('0') << endl <<MomCounter.GetCount() << endl;
        cout<<"\n:" ;
        cin>>choice;


        choice = toupper(choice);
    }

    
    return 0;
}
开发者ID:jonathanpchan,项目名称:SchoolWork,代码行数:80,代码来源:main.cpp

示例11: main

int main() {
    Counter i;
    std::cout << "The value of i is " << i.GetItsVal() << std::endl;
    return 0;
}
开发者ID:MiltonStanley,项目名称:CPP_In_21_Days,代码行数:5,代码来源:10_6.cpp

示例12: generateIOComponentModules


//.........这里部分代码省略.........
					}
					else
					{
						AnalogueOutput *o = new AnalogueOutput(addr);
						output_list.push_back(o);
						IOComponent::devices[m->getName().c_str()] = o;
						o->setName(m->getName().c_str());
						m->io_interface = o;
						o->addDependent(m);
						o->addOwner(m);
						o->setupProperties(m);
					}
				}
				else
				{
					//sstr << m->getName() << "_IN_" << entry_position << std::flush;
					//const char *name_str = sstr.str().c_str();
#if 1
					std::cerr << "Adding new input device " << m->getName()
						<< " position: " << entry_position
						<< " name: " << module->entry_details[offset_idx].name
						<< " sm_idx: " << std::hex << ed->sm_index << std::dec
						<< " bit_pos: " << module->bit_positions[offset_idx]
						<< " offset: " << module->offsets[offset_idx]
						<<  " bitlen: " << bitlen << "\n";
#endif
					IOAddress addr( IOComponent::add_io_entry(ed->name.c_str(),
								module_position,
								module->offsets[offset_idx],
								module->bit_positions[offset_idx], offset_idx, bitlen));

					if (bitlen == 1)
					{
						Input *in = new Input(addr);
						IOComponent::devices[m->getName().c_str()] = in;
						in->setName(m->getName().c_str());
						m->io_interface = in;
						in->addDependent(m);
						in->addOwner(m);
					}
					else
					{
						if (m->_type == "COUNTERRATE")
						{
							CounterRate *in = new CounterRate(addr);
							char *nm = strdup(m->getName().c_str());
							IOComponent::devices[nm] = in;
							free(nm);
							in->setName(m->getName().c_str());
							m->io_interface = in;
							in->addDependent(m);
							in->addOwner(m);
							m->setNeedsThrottle(true);
							in->setupProperties(m);
						}
						else if (m->_type == "COUNTER")
						{
							Counter *in = new Counter(addr);
							char *nm = strdup(m->getName().c_str());
							IOComponent::devices[nm] = in;
							free(nm);
							in->setName(m->getName().c_str());
							m->io_interface = in;
							in->addDependent(m);
							in->addOwner(m);
							in->setupProperties(m);
							m->setNeedsThrottle(true);
						}
						else
						{
							AnalogueInput *in = new AnalogueInput(addr);
							char *nm = strdup(m->getName().c_str());
							IOComponent::devices[nm] = in;
							free(nm);
							in->setName(m->getName().c_str());
							m->io_interface = in;
							in->addDependent(m);
							in->addOwner(m);
							in->setupProperties(m);
							m->setNeedsThrottle(true);
						}
					}
				}
#endif
			}
			else
			{
#if 0
				if (m->_type != "POINT" && m->_type != "STATUS_FLAG" && m->_type != "COUNTERRATE"
						&& m->_type != "COUNTER"
						&& m->_type != "ANALOGINPUT" && m->_type != "ANALOGOUTPUT" )
					DBG_MSG << "Skipping " << m->_type << " " << m->getName() << " (not a POINT)\n";
				else
					DBG_MSG << "Skipping " << m->_type << " " << m->getName() << " (no parameters)\n";
#endif
			}
		}
		assert(remaining==0);
	}
}
开发者ID:,项目名称:,代码行数:101,代码来源:

示例13: updateBeacons

      void
      updateBeacons(void)
      {
        m_beacons.clear();
        IMC::MessageList<IMC::LblBeacon>::const_iterator itr = m_lbl_cfg->beacons.begin();
        for (unsigned i = 0; itr != m_lbl_cfg->beacons.end(); ++itr, ++i)
          addBeacon(i, *itr);
        m_beacon = m_beacons.begin();
        m_ping_time.reset();

        if (isActive())
          setEntityState(IMC::EntityState::ESTA_NORMAL, Status::CODE_ACTIVE);
        else
          setEntityState(IMC::EntityState::ESTA_NORMAL, Status::CODE_IDLE);
      }
开发者ID:Aero348,项目名称:dune,代码行数:15,代码来源:Task.cpp

示例14: setBrightness

      void
      setBrightness(LED* led, uint8_t value)
      {
        uint8_t id = led->id;
        uint16_t ticks = ((value * m_dif_dur) / 255) + m_min_dur;

        UCTK::Frame frame;
        frame.setId(PKT_ID_LED_PW);
        frame.setPayloadSize(3);
        frame.set(id, 0);
        frame.set(ticks, 1);

        if (m_ctl->sendFrame(frame))
        {
          led->brightness.value = value;
          m_wdog.reset();
        }
      }
开发者ID:FreddyFox,项目名称:dune,代码行数:18,代码来源:Task.cpp

示例15: RestartNeeded

      void
      onResourceInitialization(void)
      {
        m_uart->writeString("\r");
        Delay::wait(1.0);
        m_uart->flush();

        if (!sendCommand("\r", "\r\n"))
          throw RestartNeeded(DTR("failed to enter command mode"), 5, false);

        if (!sendCommand("SET SAMPLE 1 s\r", ">SET SAMPLE 1 s\r\n"))
          throw RestartNeeded(DTR("failed to set sampling rate"), 5, false);

        if (!sendCommand("MONITOR\r", ">MONITOR\r\n"))
          throw RestartNeeded(DTR("failed to enter monitor mode"), 5, false);

        m_wdog.setTop(m_args.input_timeout);
      }
开发者ID:AndreGCGuerra,项目名称:dune,代码行数:18,代码来源:Task.cpp


注:本文中的Counter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。