Esempio n. 1
0
            void FilterTargets(std::list<Unit*>& targetList)
            {
                // get 2 targets except 2 nearest
                targetList.sort(Trinity::ObjectDistanceOrderPred(GetCaster()));

                // .resize() runs pop_back();
                if (targetList.size() > 4)
                    targetList.resize(4);

                while (targetList.size() > 2)
                    targetList.pop_front();
            }
Esempio n. 2
0
Error SNMPGetPacket::Unmarshal(std::list<Byte> &from) {
	set_type(static_cast<SNMPDataType>(from.front()));
	from.pop_front();

	//Byte length = from.front();
	from.pop_front();

	Error err{};

	if ((err = version_.Unmarshal(from)) != Error::None) {
		return err;
	}
	if ((err = community_string_.Unmarshal(from)) != Error::None) {
		return err;
	}
	if ((err = pdu_.Unmarshal(from)) != Error::None) {
		return err;
	}

	return Error::None;
}
Esempio n. 3
0
Error SNMPObjectIdentifier::Unmarshal(std::list<Byte> &from) {
	set_type(static_cast<SNMPDataType>(from.front()));
	from.pop_front();

	Byte length = from.front();
	from.pop_front();

	Byte first = from.front();
	from.pop_front();

	value_.push_back(first / static_cast<Byte>(40));
	value_.push_back(first % static_cast<Byte>(40));

	// retrieve remaining bytes
	for (int i = 1; i < length; i++) {
		value_.push_back(from.front());
		from.pop_front();
	}

	return Error::None;
}
 bool ProcessTokens(std::list<std::string> &tokens) {
   assert(0 == name_.compare(tokens.front()) && "option name is mismatched");
   if (1 == tokens.size()) {
     tokens.pop_front();
     is_set_ = true;
     return true;
   } else if (2 == tokens.size()) {
     tokens.pop_front();
     if (tokens.front() == "1") {
       is_set_ = true;
       tokens.pop_front();
       return true;
     } else if (tokens.front() == "0") {
       is_set_ = false;
       tokens.pop_front();
       return true;
     }
   }
   error() << "error: invalid option: '" << name_ << "'" << std::endl;
   return false;
 }
Esempio n. 5
0
    bool
    OptionParser::processElement(std::list<std::string>& args)
    {
      std::string arg = args.front();
      args.pop_front();

      // Check for positional arguments.
      if (m_option_map.find(arg) == m_option_map.end())
      {
        if (arg[0] == '-')
        {
          m_error = String::str(DTR("unknown option '%s'"), arg.c_str());
          return false;
        }

        m_arguments.push_back(arg);
      }
      // Check for options.
      else
      {
        if (m_option_map[arg]->argument_label != "")
        {
          if (args.empty())
          {
            m_error = String::str(DTR("missing argument for option '%s'"), arg.c_str());
            return false;
          }

          std::string opt_arg = args.front();
          args.pop_front();
          m_option_map[arg]->argument = opt_arg;
        }
        else
        {
          m_option_map[arg]->argument = "true";
        }
      }

      return true;
    }
Esempio n. 6
0
void reverseSecond( std::list<double> &d) {
  if(d.size() >= 1)
    {
      double temp1=d.front();
      double temp2=d.back();
      d.pop_front();
      d.pop_back();
      reverseSecond(d);
      d.push_front(temp2);
      d.push_back(temp1);
    }

}
        optional<OnlineFileRequest*> pop() {
            if (queue.empty()) {
                return optional<OnlineFileRequest*>();
            }

            if (queue.begin() == firstLowPriorityRequest) {
                firstLowPriorityRequest++;
            }

            OnlineFileRequest* next = queue.front();
            queue.pop_front();
            return optional<OnlineFileRequest*>(next);
        }
Esempio n. 8
0
Event InputHandlerImpl::popEvent()
{
    eqMutex.lock();
    if(eventQueue.empty())
    {
        eqMutex.unlock();
        return Event(); //Default constructed event
    }
    Event result=eventQueue.front();
    eventQueue.pop_front();
    eqMutex.unlock();
    return result;
}
///////////////////////////////////////////////////////////////
//
// CPerfStatSqliteTimingImpl::DoPulse
//
//
//
///////////////////////////////////////////////////////////////
void CPerfStatSqliteTimingImpl::DoPulse()
{
    long long llTime = GetTickCount64_();
    // Remove old stats
    while (m_TimingList.size())
    {
        CTimingInfo& info = m_TimingList.front();
        int          iAgeSeconds = static_cast<int>((llTime - info.timeStamp) / 1000);
        if (iAgeSeconds < 2000 && m_TimingList.size() < 1000)
            break;
        m_TimingList.pop_front();
    }
}
Esempio n. 10
0
void ModeMapTest::CleanUpContexts(std::list<cl_context> &contexts, gmac::opencl::lite::ModeMap &map)
{
    while(contexts.empty() != false) {
        ASSERT_TRUE(map.get(contexts.front()) != NULL);
        gmac::opencl::lite::ModeMap::iterator it;
        it = map.find(contexts.front());
        ASSERT_TRUE(it != map.end());
        map.erase(it);
        ASSERT_TRUE(map.get(contexts.front()) == NULL);
        ASSERT_EQ(CL_SUCCESS, clReleaseContext(contexts.front()));
        contexts.pop_front();
    }
}
Esempio n. 11
0
void GmTicket::SetChatLog(std::list<uint32> time, std::string const& log)
{
    std::stringstream ss(log);
    std::stringstream newss;
    std::string line;
    while (std::getline(ss, line))
    {
        newss << secsToTimeString(time.front()) << ": " << line << "\n";
        time.pop_front();
    }

    _chatLog = newss.str();
}
Esempio n. 12
0
void mempool::_create(size_t al, char* v, char* en, 
            std::list<size_t> sizes, std::list<size_t> vsizes, std::list<char* >& ptrl) 
    {
        if(sizes.empty()){
            return;
        }
        if(v >= en){
            throw std::bad_alloc();
        }
        while(uintptr_t(v) % al){
            v++;
            if(v >= en){
                throw std::bad_alloc();
            }
        }
        size_t cur_size = sizes.front()*vsizes.front();
        sizes.pop_front();
        vsizes.pop_front();
        ptrl.push_back((char*)v);
        v+= cur_size;
        _create(al, v, en, sizes, vsizes, ptrl);
    }
Esempio n. 13
0
void merge_sort<T>::merge(std::list<T>& input1, std::list<T>& input2, size_t merge_depth, std::list<T>& out1, std::list<T>& out2)
{
    size_t merged1 = 0, merged2 = 0;
    std::list<T> *current = &out1;
    while (input1.size() > 0 && input2.size() > 0)
    {
        if (input1.front() <= input2.front())
        {
            current->push_back(input1.front());
            input1.pop_front();
            merged1++;
        }
        else
        {
            current->push_back(input2.front());
            input2.pop_front();
            merged2++;
        }

        if (merged1 == merge_depth)
        {
            while(input2.size() > 0 && merged2 < merge_depth)
            {
                current->push_back(input2.front());
                input2.pop_front();
                merged2++;
            }
        }

        if (merged2 == merge_depth)
        {
            while(input1.size() > 0 && merged1 < merge_depth)
            {
                current->push_back(input1.front());
                input1.pop_front();
                merged1++;
            }
        }

        if (merged1 == merge_depth || merged2 == merge_depth)
        {
            merged1 = merged2 = 0;
            if (current == &out1)
                current = &out2;
            else
                current = &out1;
        }
    }
    while (input1.size() > 0)
    {
        current->push_back(input1.front());
        input1.pop_front();
    }
    while (input2.size() > 0)
    {
        current->push_back(input2.front());
        input2.pop_front();
    }
}
Esempio n. 14
0
		void first_done(int status, hostent *ent) {
			if( status == ARES_SUCCESS ) {
				DebugTracePrintf(("Request result returned:%p -> %s:%d.%d.%d.%d",this,ent->h_name,ent->h_addr[0],ent->h_addr[1],ent->h_addr[2],ent->h_addr[3]));
			} else {
				DebugTracePrintf(("Request result error returned:%p",this));
			}
			if( _queue.begin() == _queue.end() )
				return;
			QueueEntry *f = *_queue.begin();
			_queue.pop_front();
			f->cb(f->arg,status,0,ent);
			delete f;
		}
Esempio n. 15
0
            void FilterTargets(std::list<WorldObject*>& targets)
            {
                targets.sort(Trinity::ObjectDistanceOrderPred(GetCaster()));

                // Selects 5 nearest dummies, including the caster
                // .resize() runs pop_back();
                if (targets.size() > 5)
                    targets.resize(5);

                // Selects 2 farthest ones to cast a spell
                while (targets.size() > 2)
                    targets.pop_front();
            }
float calc_avg(float new_angle, std::list<float> &list){
        float sum = 0;
        //angle_error_vector.push_back(new_angle_error);
        list.push_back(new_angle);
        if(list.size() > 10){
                list.pop_front();
        }

        for(std::list<float>::iterator it = list.begin(); it != list.end(); ++it) {
                sum+=*it;
        }
        return sum/(signed)list.size();
}
Esempio n. 17
0
/**
* This function is called
**/
void traceInst(INS ins, VOID*)
{
    ADDRINT address = INS_Address(ins);

    std::string mod_name = getModule( address );
    RegList regs;

    for ( UINT32 i = 0; i < INS_OperandCount(ins); i++ )
    {
        if ( INS_OperandIsReg(ins, i) )
        {
            REG x = INS_OperandReg(ins, i);
            if ( x != REG_INVALID() )
                regs.push_back( x );
        }
    }

    if (isUnknownAddress(address))
    {
        // The address is an address that does not belong to any loaded module.
        // This is potential shellcode. For these instructions a callback
        // function is inserted that dumps information to the trace file when
        // the instruction is actually executed.

        INS_InsertCall(ins, IPOINT_BEFORE, AFUNPTR(dump_shellcode),
                       IARG_PTR, new std::string(dumpInstruction(ins)),
                       IARG_PTR, &regs,
                       IARG_CONTEXT, IARG_END
            );
    }
    else
    {
        if ( !modlist.empty() && (modlist.find(mod_name) == modlist.end()) ) // not concerned
            return;

        // The address is a legit address, meaning it is probably not part of
        // any shellcode. In this case we just log the instruction to dump it
        // later to show when control flow was transfered from legit code to
        // shellcode.

        legitInstructions.push_back(dumpInstruction(ins));

        if (legitInstructions.size() > KnobMaxLegitInsLogSize.Value())
        {
            // Log only up to KnobMaxLegitInsLogSize.Value() instructions or the whole
            // program before the shellcode will be dumped.

            legitInstructions.pop_front();
        }
    }
}
Esempio n. 18
0
std::string findInDir(std::string parent, std::list<std::string> remainingPath, const char DIR_SEP)
{
	Directory d(parent);
	std::string name = remainingPath.front();
	remainingPath.pop_front();
	//Strip out any excess blank entries (otherwise paths like "./directory//file" would break)
	while (name == "")
	{
		if (remainingPath.empty())
			return parent;
		name = remainingPath.front();
		remainingPath.pop_front();
	}
	struct dirent entry , *result = NULL;
	while (true)
	{
		int err = readdir_r(d.d, &entry, &result);
		if (err)
		{
			std::cerr << "Readdir() failed with \"" << err << "\"\n";
			return "";
		}
		if (!result)
		{
			break;
		}
		std::string entName(entry.d_name);
		if (Strings::CompareCaseInsensitive(name, entName) == 0)
		{
			std::string entPath = parent + DIR_SEP + entName;
			if (remainingPath.empty())
				return entPath;
			else
				return findInDir(entPath, remainingPath, DIR_SEP);
		}
	}
	return "";
}
Esempio n. 19
0
CmResult COFP10PacketOutMsg::
AddActionList(std::list<COFP10Action *> &list)
{
    while (!list.empty())
    {
        COFP10Action *action = list.front();
        CM_ASSERT_RETURN(action != nullptr, CM_ERROR_NULL_POINTER);
        list.pop_front();
        m_action_list.push_back(action);
        m_tMember.actions_len += action->GetStreamLen();
    }

    return CM_OK;
}
Esempio n. 20
0
char *command_generator(const char *text, int state)
{
    static std::list<std::string> completion_options;
    static int len;

    if (!current_command)
        return NULL;

    if (!state)
    {
        // New word to complete then set up the options to match

        // Cache the len for efficiency
        len = strlen(text);

        // Try the sub-commands of the current command
        completion_options = current_command->get_sub_command_names();
        if (!completion_options.size())
        {
            // If there are no sub-commands then try the arguments
            std::vector<cli_argument*> args;
            std::set<std::string> arg_options;

            // There can be multiple arguments at a given index as there
            // can be multiple command formats
            current_command->get_args(complettion_arg_index, args);
            for (std::vector<cli_argument*>::iterator iter = args.begin();
                 iter != args.end();
                 ++iter)
            {
                (*iter)->get_completion_options(arg_options);
            }
            completion_options.insert(completion_options.end(),
                    arg_options.begin(), arg_options.end());
        }
    }

    // Return the next name which matches from the command list
    while (completion_options.size())
    {
        std::string sub_command = completion_options.front();
        completion_options.pop_front();

        if (strncmp(sub_command.c_str(), text, len) == 0)
            return (strdup(sub_command.c_str()));
    }

    // There are no matches
    return NULL;
}
Esempio n. 21
0
void addlog(const char* pszFormat, ...)
{
	char tempsqlbuf[1024] = { 0 };
	va_list argptr;
	va_start(argptr, pszFormat);
	int n = _vsnprintf(tempsqlbuf, sizeof(tempsqlbuf) - 1, pszFormat, argptr);
	va_end(argptr);
	
	asio::detail::win_mutex::scoped_lock lock(logmtx);
	while (loglst.size() > 128)
		loglst.pop_front();
	loglst.push_back(tempsqlbuf);
	logchanged = true;
}
Esempio n. 22
0
            void EnterCombat(Unit* attacker)
            {
                _EnterCombat();
                DoZoneInCombat(me, 200.0f);

                uint8 nextPlateforme = randomPlateforme.front();
                randomPlateforme.pop_front();

                me->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE|UNIT_FLAG_NOT_SELECTABLE);
                me->GetMotionMaster()->MoveJump(zorlockPosition[nextPlateforme].GetPositionX(), zorlockPosition[nextPlateforme].GetPositionY(), 409.89f, 20.0f, 20.0f, nextPlateforme + 1);

                // zorlockPosition[3] == Middle
                me->CastSpell(zorlockPosition[3].GetPositionX(), zorlockPosition[3].GetPositionY(), zorlockPosition[3].GetPositionZ(), SPELL_PHEROMONES_OF_ZEAL_FLOOR, true);
            }
Esempio n. 23
0
int fill_to_line(void *data)
{
	if(points.empty() || do_the_job == false)
		return 0;
		
	auto it = points.begin();
	
	auto x = (*it)->x;
	auto y = (*it)->y;
	pixbuf->point(x, y, 255,0,0);	
	
	for(int s_y = 0; s_y < 3; s_y++)
	{
		for(int s_x = 0; s_x < 3; s_x++)
		{	
			if(s_x == 1 && s_y == 1)
				continue;
				
			if(sasiedztwo[s_x][s_y]->get_active())
			{
				int n_x = (x + s_x) - 1;
				int n_y = (y + s_y) - 1;
				
				if(n_x < 0 || n_x >= 100)
					continue;

				if(n_y < 0 || n_y >= 100)
					continue;
					
				if(sprawdzony[n_x][n_y])
					continue;
					
				auto pixel = pixbuf->get_point(n_x, n_y);
				if(pixel[0] == 255 && pixel[1] == 255)
				{
					std::shared_ptr<cords> point(new cords);
					point->x = n_x;
					point->y = n_y;
					points.push_back(point);
				};
					
				sprawdzony[n_x][n_y] = true;
			};
		};
	};

	points.pop_front();

	return 1;
};
Esempio n. 24
0
 void open_next_pipe(stream_type& res) {
   while(!free_pipes_.empty()) {
     const char* path = free_pipes_.front();
     free_pipes_.pop_front();
     res.reset(new pipe_stream(path, *this));
     if(res->good()) {
       busy_pipes_.insert(path);
       return;
     }
     // The pipe failed to open, so it is not marked as busy. This
     // reset will make us forget about this path.
     res.reset();
   }
 }
Esempio n. 25
0
/** This runs in a separate thread */
static int fpathThreadFunc(void *)
{
	wzMutexLock(fpathMutex);

	while (!fpathQuit)
	{
		if (pathJobs.empty())
		{
			ASSERT(!waitingForResult, "Waiting for a result (id %u) that doesn't exist.", waitingForResultId);
			wzMutexUnlock(fpathMutex);
			wzSemaphoreWait(fpathSemaphore);  // Go to sleep until needed.
			wzMutexLock(fpathMutex);
			continue;
		}

		// Copy the first job from the queue. Don't pop yet, since the main thread may want to set .deleted = true.
		PATHJOB job = pathJobs.front();

		wzMutexUnlock(fpathMutex);

		// Execute path-finding for this job using our local temporaries
		PATHRESULT result;
		result.droidID = job.droidID;
		memset(&result.sMove, 0, sizeof(result.sMove));
		result.retval = FPR_FAILED;
		result.originalDest = Vector2i(job.destX, job.destY);

		// we need to lock BEFORE we fiddle with the data, or we get ugly data race conditions.
		wzMutexLock(fpathMutex);
		fpathExecute(&job, &result);

		ASSERT(pathJobs.front().droidID == job.droidID, "Bug");  // The front of pathJobs may have .deleted set to true, but should not otherwise have been modified or deleted.
		if (!pathJobs.front().deleted)
		{
			pathResults.push_back(result);
		}
		pathJobs.pop_front();

		// Unblock the main thread, if it was waiting for this particular result.
		if (waitingForResult && waitingForResultId == job.droidID)
		{
			waitingForResult = false;
			objTrace(waitingForResultId, "These are the droids you are looking for.");
			wzSemaphorePost(waitingForResultSemaphore);
		}
	}
	wzMutexUnlock(fpathMutex);
	return 0;
}
    int ProcessQueue( CommunityHealthWorkerEventCoordinator* pThis, 
                      float currentTime, 
                      int numToDistribute, 
                      std::list<QueueEntry<T>>& rQueue )
    {
        int num_distributed = 0;

        bool done = (rQueue.size() == 0) || (numToDistribute == 0);
        while( !done )
        {
            QueueEntry<T> entry = rQueue.front();

            if( entry.time_of_queue_entry_days == currentTime )
            {
                // ----------------------------------------------------------------------------------
                // --- Entities can enter the queue before and after Update() & UpdateNodes()
                // --- are called for this coordinator.  Hence, we want to make the processing
                // --- consistent and don't want to process entities that entered the queue during
                // --- this time step.  If an entity enters on day T and the waiting period is 5 days,
                // --- then the entity will time out on the day > T+5.  For example, if an entity
                // --- enters on day 2 and the waiting period is 5 days, they could get the
                // --- intervention as late as day 7 (i.e. 5 days of opportunity).  On day 8, they
                // --- should be removed from the queue.
                // ----------------------------------------------------------------------------------
                done = true;
            }
            else if( numToDistribute > 0 )
            {
                if( pThis->Qualifies( entry.p_entity ) )
                {
                    bool distributed = pThis->Distribute( entry.p_entity );
                    if( distributed )
                    {
                        --numToDistribute;
                        num_distributed++;
                    }
                }
                rQueue.pop_front();
            }
            else
            {
                done = true;
            }

            done = done || (rQueue.size() == 0);
        }

        return num_distributed;
    }
Esempio n. 27
0
void SnapshotCommand::setParameters (std::list <std::string> params)
{
  int listSize = params.size ();
  logger->debug() << "set parameters has " << params.size () << " parameters" << std::endl;
  if (listSize > 0)
  {
    stepInterval = atoi (params.front().c_str ());
    params.pop_front();
  }
  if (listSize > 1)
  {
    sendForces = atoi (params.front().c_str()) > 0 ? true : false;
    params.pop_front();
  }
  if (listSize > 2)
  {
    sendVelocity = atoi (params.front().c_str()) > 0 ? true : false;
    params.pop_front ();
  }
  if (listSize > 3)
  {
    sendV2 = atoi (params.front().c_str()) > 0 ? true : false;
    params.pop_front ();
  }
  if (listSize > 4)
  {
    sendV2Max = atoi (params.front().c_str()) > 0 ? true : false;
    params.pop_front ();
  }

  if (listSize > 4)
  {
    logger->debug() << "got Parameters: " << stepInterval << " " << sendForces << " " << sendVelocity << " " << sendV2  << " "
    << sendV2Max <<  std::endl;
  }
}
Esempio n. 28
0
        uint32 GetData(uint32 action)
        {
            // Get first leg dead
            if (action == ACTION_LEG_IS_DEAD)
            {
                if (legs.empty())
                    return 0;

                uint32 guid = legs.front();
                legs.pop_front();
                return guid;
            }

            return 0;
        }
Esempio n. 29
0
	CURL * alloc()
	{
		CURL *curl;
		if (handles.empty()) {
			curl = curl_easy_init();
			if (curl == NULL) {
				errorstream<<"curl_easy_init returned NULL"<<std::endl;
			}
		}
		else {
			curl = handles.front();
			handles.pop_front();
		}
		return curl;
	}
Esempio n. 30
0
void LogRecorder::write(std::list<rosgraph_msgs::Log>& log_msgs)
{
  while ( !log_msgs.empty() )
  {
    if (!log_msgs.front().header.stamp.isZero()) {
      gr_->write(topic_, log_msgs.front(), log_msgs.front().header.stamp);
    }
    else {
      gr_->write(topic_, log_msgs.front());
    }
    {
      log_msgs.pop_front();
    }
  }
}