void Solution::nextPermutation(std::vector<int>& numbers)
{
	auto it = numbers.rbegin();
	for (; it != numbers.rend(); ++it)
	{
		auto head_it = it.base();
		if (head_it == numbers.end())
		{
			continue;
		}

		if (*it < *head_it)
		{
			break;
		}
	}

	if (it == numbers.rend())
	{
		std::reverse(numbers.rbegin(), numbers.rend());
		return;
	}

	const auto find_it = std::upper_bound(numbers.rbegin(), it, *it, std::less<>());
	assert(find_it != numbers.rend());

	std::iter_swap(it, find_it);
	std::reverse(numbers.rbegin(), it);
}
Ejemplo n.º 2
0
      /// \param[in] t_params the list of params to search
      /// \param[in] t_value the value to search for
      /// \returns the JobParam matching the given value. Throws an exception if it is not found
      static bool hasByValue(const std::vector<JobParam> &t_params, const std::string &t_value)
      {
        auto itr = std::find_if(t_params.rbegin(), t_params.rend(), JobParamValueCompare(t_value));

        if (itr != t_params.rend())
        {
          return true;
        }

        return false;
      }
Ejemplo n.º 3
0
std::vector<int> prevPerm(std::vector<int> data)
{
  auto inversionPoint = std::is_sorted_until(data.rbegin(), data.rend(), [&data](const int& a, const int& b) { return a > b; });
  if (inversionPoint == data.rend())
  {
    return {};
  }
  auto mostLowerBound = std::lower_bound(data.rbegin(), inversionPoint, *inversionPoint, cmp);
  std::iter_swap(mostLowerBound, inversionPoint);
  std::reverse(data.rbegin(), inversionPoint);
  return data;
}
Ejemplo n.º 4
0
void HelloWorld::createActionChain(const std::vector<TileData*>& path)
{
    if (path.size() <= 0) return;

    Size mapSize = m_gamemap->getMapSize();
    Size tilesize = m_gamemap->getTileSize();
    int mapheight = mapSize.height * tilesize.height;

    Vector<FiniteTimeAction*> actions;

    std::vector<TileData*>::const_reverse_iterator rIter = path.rbegin();
    rIter++;
    while (rIter != path.rend())
    {
        int destination_x = (*rIter)->position().first * tilesize.width + tilesize.width / 2;
        int destination_y = (*rIter)->position().second * tilesize.height + tilesize.height / 2;
        Vec2 destination(destination_x, mapheight - destination_y);
        MoveTo* action = MoveTo::create(0.5f, destination);
        actions.pushBack(action);

        rIter++;
    }

    if (actions.size() > 0)
    {
        Sequence* action_seq = Sequence::create(actions);
        m_player->runAction(action_seq);
    }
}
Ejemplo n.º 5
0
void SpritesPanelImpl::traverseSprites(const std::vector<d2d::ISprite*>& sprites, 
									   IVisitor& visitor, TraverseType type/* = e_allExisting*/,
									   bool order/* = true*/)
{
	if (order)
	{
		std::vector<ISprite*>::const_iterator itr = sprites.begin();
		for ( ; itr != sprites.end(); ++itr)
		{
			bool hasNext;
			visitor.visit(*itr, hasNext);
			if (!hasNext) break;
		}
	}
	else
	{
		std::vector<ISprite*>::const_reverse_iterator itr = sprites.rbegin();
		for ( ; itr != sprites.rend(); ++itr)
		{
			bool hasNext;
			visitor.visit(*itr, hasNext);
			if (!hasNext) break;
		}
	}
}
Ejemplo n.º 6
0
 bool updateLeavesSpawn() {
     bool fullGridSpawn = (newLeaves.size() == (unsigned)theHeriswapGridSystem.GridSize*theHeriswapGridSystem.GridSize);
     ADSR(haveToAddLeavesInGrid)->active = true;
     for ( std::vector<Feuille>::reverse_iterator it = newLeaves.rbegin(); it != newLeaves.rend(); ++it ) {
         if (it->entity == 0) {
             it->entity = createCell(*it, fullGridSpawn);
         } else {
             HeriswapGridComponent* gc = HERISWAPGRID(it->entity);
             if (fullGridSpawn) {
                 gc->i = gc->j = -1;
             }
             TransformationComponent* tc = TRANSFORM(it->entity);
             //leaves grow up from 0 to fixed size
             glm::vec2 s = HeriswapGame::CellSize(theHeriswapGridSystem.GridSize, gc->type);
             if (ADSR(haveToAddLeavesInGrid)->value == 1){
                 tc->size = glm::vec2(s.x, s.y);
                 gc->i = it->X;
                 gc->j = it->Y;
             } else {
                 tc->size = s * ADSR(haveToAddLeavesInGrid)->value;
             }
         }
     }
     return (ADSR(haveToAddLeavesInGrid)->value == 1);
 }
Ejemplo n.º 7
0
void CountingSort::rcsort(std::vector<unsigned int>& A, std::vector<unsigned int>& B, unsigned int d)
{
	std::vector<unsigned int> C(10);

	for (auto c = C.begin(); c != C.end(); ++c) 
		*c = 0;

	//std::cout << "C: "; print(C);

	for (auto a = A.begin(); a != A.end(); ++a) 
		++C[digit(*a,d)];

	//std::cout << "A: "; print(A);
	//std::cout << "C: "; print(C);

	for (auto c = C.begin() + 1; c != C.end(); ++c) 
		*c += *(c - 1);

	//std::cout << "C: "; print(C);

	for (auto a = A.rbegin(); a != A.rend(); ++a) { 
		B[C[digit(*a,d)] - 1] = *a; 
		--C[digit(*a,d)];
	}

}
Ejemplo n.º 8
0
int testFindDistanceBetween(const std::string & s1, const std::string & s2,
                            const std::vector<std::string> & fileAsAnArray) {
    if (s1.compare(s2) == 0) { return 0; }
    int minDistance = INT_MAX;
    bool found = false;
    for (auto it = fileAsAnArray.begin(); it != fileAsAnArray.end(); ++it) {
        if (it->compare(s1) == 0) {
            found = true;
            auto itBack = std::vector<std::string>::const_reverse_iterator(it);
            --itBack; // When converted, it points to predecessor of it
            auto beginR = itBack;
            assert(beginR->compare(*it) == 0);
            auto itForth = it;
            auto distance = INT_MAX;
            while (itBack != fileAsAnArray.rend()) {
                if (itBack->compare(s2) == 0) {
                    distance = abs(std::distance(itBack, beginR));
                    break;
                }
                ++itBack;
            }
            while (itForth != fileAsAnArray.end()) {
                if (itForth->compare(s2) == 0) {
                    distance = min(distance, abs(std::distance(it, itForth)));
                    break;
                }
                ++itForth;
            }
            minDistance = min(distance, minDistance);
        }
    }
    if (!found) { return -1; }
    return minDistance;
}
Ejemplo n.º 9
0
template <typename PointT> void 
pcl16::EuclideanClusterExtraction<PointT>::extract (std::vector<PointIndices> &clusters)
{
  if (!initCompute () || 
      (input_ != 0   && input_->points.empty ()) ||
      (indices_ != 0 && indices_->empty ()))
  {
    clusters.clear ();
    return;
  }

  // Initialize the spatial locator
  if (!tree_)
  {
    if (input_->isOrganized ())
      tree_.reset (new pcl16::search::OrganizedNeighbor<PointT> ());
    else
      tree_.reset (new pcl16::search::KdTree<PointT> (false));
  }

  // Send the input dataset to the spatial locator
  tree_->setInputCloud (input_, indices_);
  extractEuclideanClusters (*input_, *indices_, tree_, static_cast<float> (cluster_tolerance_), clusters, min_pts_per_cluster_, max_pts_per_cluster_);

  //tree_->setInputCloud (input_);
  //extractEuclideanClusters (*input_, tree_, cluster_tolerance_, clusters, min_pts_per_cluster_, max_pts_per_cluster_);

  // Sort the clusters based on their size (largest one first)
  std::sort (clusters.rbegin (), clusters.rend (), comparePointClusters);

  deinitCompute ();
}
Ejemplo n.º 10
0
extern "C" NS_EXPORT pid_t
WRAP(fork)(void)
{
  pid_t pid;
  for (std::vector<AtForkFuncs>::reverse_iterator it = atfork.rbegin();
       it < atfork.rend(); ++it)
    if (it->prepare)
      it->prepare();

  switch ((pid = __fork())) {
  case 0:
    cpuacct_add(getuid());
    for (std::vector<AtForkFuncs>::iterator it = atfork.begin();
         it < atfork.end(); ++it)
      if (it->child)
        it->child();
    break;
  default:
    for (std::vector<AtForkFuncs>::iterator it = atfork.begin();
         it < atfork.end(); ++it)
      if (it->parent)
        it->parent();
  }
  return pid;
}
Ejemplo n.º 11
0
/*
** Trims empty element in vector and white-space in each string.
**
*/
void CConfigParser::Shrink(std::vector<std::wstring>& vec)
{
	if (!vec.empty())
	{
		std::vector<std::wstring>::reverse_iterator iter = vec.rbegin();
		while (iter != vec.rend())
		{
			std::wstring::size_type pos = (*iter).find_first_not_of(L" \t\r\n");
			if (pos != std::wstring::npos)
			{
				std::wstring::size_type lastPos = (*iter).find_last_not_of(L" \t\r\n");
				if (pos != 0 || lastPos != ((*iter).size() - 1))
				{
					// Trim white-space
					(*iter).assign((*iter), pos, lastPos - pos + 1);
				}
				++iter;
			}
			else
			{
				// Remove empty element
				vec.erase((++iter).base());
			}
		}
	}
}
Ejemplo n.º 12
0
	void CSVExporter::processData(const unsigned char* buffer, size_t bufferSize, float baseTime, const std::vector<ProcedureDescription>& proceduresDescriptions)
	{
		file << "name;pid;num_threads;item_input;input_size;shared_memory" << std::endl;
		for (auto p = proceduresDescriptions.rbegin(); p != proceduresDescriptions.rend(); ++p)
		{
			file << p->name << ';' << p->ProcedureId << ';' << p->NumThreads << ';' << p->ItemInput << ';' << p->inputSize << ';' << p->sharedMemory << '\n';
		}
		file << std::endl;

		file << "t0;t1;pid;mpid;active_threads;overhead_counter;dequeue_time;{enqueue_stats_pid;enqueue_stats_count}" << std::endl;

		for (const unsigned char* data = buffer; data < buffer + bufferSize;)
		{
			int num_enqueue_stats = Instrumentation::unpack_num_enqueue_stats(data);

			file << Instrumentation::unpack_t0(data) << ';'
				<< Instrumentation::unpack_t1(data) << ';'
				<< Instrumentation::unpack_pid(data) << ';'
				<< Instrumentation::unpack_mpid(data) << ';'
				<< Instrumentation::unpack_active_threads(data) << ';'
				<< Instrumentation::unpack_overhead_counter(data) << ';'
				<< Instrumentation::unpack_dequeue_time(data);

			if (num_enqueue_stats > 0)
			{
				for (int i = 0; i < num_enqueue_stats; ++i)
					file << ';'<< Instrumentation::unpack_enqueue_stat_pid(data, i) << ';'<< Instrumentation::unpack_enqueue_stat_count(data, i);
			}
			file << std::endl;

			data = Instrumentation::next_element(data, num_enqueue_stats);
		}

		file << std::endl;
	}
Ejemplo n.º 13
0
bool ParserMixin::convertStringElementsToPackageElements(const ParseContextSPtr& context,
                                                         const std::vector<std::string>& string_elements,
                                                         std::vector<PackageElementSPtr>& package_elements)
{
    std::vector<PackageElementSPtr>::const_reverse_iterator eit = context->mSourceId->externalElements().rbegin();

    std::vector<std::string>::const_reverse_iterator it;
    for (it = string_elements.rbegin(); it != string_elements.rend(); ++it)
    {
        PackageElementSPtr pe;
        if (*it == "*")
        {
            if (eit == context->mSourceId->externalElements().rend())
            {
                context->mMessageCollector->addMessage(errorMessage(context, Message::p_asteriskPackageElement));
                return false;
            }
            pe = *eit;
            ++eit;
        }
        else
        {
            if (*eit && (*eit)->value() == *it)
                ++eit;

            pe = boost::make_shared<PackageElement>();
            pe->set_value(*it);
        }
        package_elements.insert(package_elements.begin(), pe);
    }
    return true;
}
Ejemplo n.º 14
0
size_t CountDistinctValues(std::vector<int> numbers){
    size_t abs_count = numbers.size();
    auto f_it = numbers.begin();
    auto r_it = numbers.rbegin();
    while(f_it != numbers.end() && r_it != numbers.rend()){
        
        //std::cout << "Forward iterator: " << *f_it << std::endl;
        //std::cout << "Reverse iterator: " << *r_it << std::endl;
        
        if((f_it - numbers.begin()) + (r_it - numbers.rbegin()) == numbers.size()-1) break;
        if(*f_it == *(f_it+1)){ // considering duplicates on the left side of an array
            --abs_count;
            ++f_it;
            continue;
        }
        if(*r_it == *(r_it+1)){ // considering duplicates on the right side of an array
            --abs_count;
            ++r_it;
            continue;
        }
        if(abs(*f_it) == abs(*r_it)){
            --abs_count;
            ++f_it;
            ++r_it;
        } else if(abs(*f_it) > abs(*r_it))
            ++f_it;
        else
            ++r_it;
    }
    return abs_count;
}
Ejemplo n.º 15
0
void sdl_event_handler::mouse(const ui_event event, const point& position)
{
	DBG_GUI_E << "Firing: " << event << ".\n";

	if(mouse_focus) {
		mouse_focus->fire(
				event, dynamic_cast<widget&>(*mouse_focus), position);
	} else {

		for(std::vector<dispatcher*>::reverse_iterator ritor
			= dispatchers_.rbegin();
			ritor != dispatchers_.rend();
			++ritor) {

			if((**ritor).get_mouse_behavior() == dispatcher::all) {
				(**ritor)
						.fire(event, dynamic_cast<widget&>(**ritor), position);
				break;
			}
			if((**ritor).get_mouse_behavior() == dispatcher::none) {
				continue;
			}
			if((**ritor).is_at(position)) {
				(**ritor)
						.fire(event, dynamic_cast<widget&>(**ritor), position);
				break;
			}
		}
	}
}
Ejemplo n.º 16
0
LinguisticGraphVertex SyntacticAnalyzerNoChains::unstackUptoChainEnd(
        const SyntacticData* data,
        std::vector< ChainStackTuple >& pile,
        Common::MediaticData::ChainsType type
  ) const
{
/*
  Critical function : commeng logging messages
*/
//  SACLOGINIT;
//  LDEBUG << "unstackUptoChainEnd " << (type==NOMINAL?"nominal":(type==VERBAL?"verbal":"none"));
  CVertexDataPropertyMap dataMap = get( vertex_data, (*data->iterator()->getGraph()) );

  std::vector< ChainStackTuple >::const_reverse_iterator rit, rit_end;
  rit = pile.rbegin(); rit_end = pile.rend();
  for (; rit != rit_end; rit++)
  {
    if ( data->matrices()->canChainEndBy(dataMap[(*rit).get<0>()], type))
      break;
//    LDEBUG << "chain cannot finish by " << (*rit).get<0>();
  }

  if (rit != rit_end)
  {
    LinguisticGraphVertex newChainEnd = (*rit).get<0>();
//    LDEBUG << "Chain end found in pile: " << newChainEnd;
    return (newChainEnd);
  }
  else
  {
//    LDEBUG << "No chain end found in pile !";
    return data->iterator()->firstVertex();
  }
}
Ejemplo n.º 17
0
static bool cw_sorted(const point_i &center,
                      const std::vector<point_i> &points) {
  if (points.empty())
    return true;

  const point_i start = points.front() - center;
  const point_i rev_start = points.back() - center;

  auto cw_less = [=](const point_i &lhs, const point_i &rhs) {
    return djp::cw_less(center, start, lhs, rhs);
  };
  auto ccw_less = [=](const point_i &lhs, const point_i &rhs) {
    return djp::ccw_less(center, rev_start, lhs, rhs);
  };

  const bool result = std::is_sorted(points.begin(), points.end(), cw_less);
  // Points in same angle should be considered equal i.e no one is less than
  // other.
  const bool rev_result =
      std::is_sorted(points.rbegin(), points.rend(), ccw_less);

  EXPECT_EQ(result, rev_result);

  return result;
}
Ejemplo n.º 18
0
void GeometryShaderApp::mouseDown( MouseEvent event )
{
	// check if any of the points is clicked (distance < radius)
	std::vector<Vec2f>::reverse_iterator itr;
	for(itr=mPoints.rbegin();itr!=mPoints.rend();++itr) {
		float d = Vec2f( event.getPos() ).distance( *itr );
		if(d < mRadius) {
			// start dragging
			mDragPos = event.getPos();
			mDragFrom = *itr;
			mDragVecPtr = &(*itr);
			bIsDragging = true;

			//
			return;
		}
	}

	// not dragging, create new point
	mPoints.push_back( Vec2f( event.getPos() ) );

	// ...and drag it right away
	mDragPos = event.getPos();
	mDragFrom = mPoints.back();
	mDragVecPtr = &(mPoints.back());
	bIsDragging = true;

	// invalidate mesh
	mVboMesh = gl::VboMesh();
}
Ejemplo n.º 19
0
void TcpClientApp::update()
{
	mFrameRate = getFrameRate();
	
	// Toggle full screen.
	if ( mFullScreen != isFullScreen() ) {
		setFullScreen( mFullScreen );
		mFullScreen = isFullScreen();
	}

	// Render text.
	if ( !mText.empty() ) {
		TextBox tbox = TextBox().alignment( TextBox::LEFT ).font( mFont ).size( Vec2i( getWindowWidth() - 250, TextBox::GROW ) ).text( "" );
		for ( vector<string>::const_reverse_iterator iter = mText.rbegin(); iter != mText.rend(); ++iter ) {
			tbox.appendText( "> " + *iter + "\n" );
		}
		tbox.setColor( ColorAf( 1.0f, 0.8f, 0.75f, 1.0f ) );
		tbox.setBackgroundColor( ColorAf::black() );
		tbox.setPremultiplied( false );
		mTexture = gl::Texture::create( tbox.render() );
		while ( mText.size() > 75 ) {
			mText.erase( mText.begin() );
		}
	}
}
Ejemplo n.º 20
0
double TechUtils::CalulateWMA(const std::vector<TickWrapper>& data, const TickWrapper& current, size_t seconds)
{
	//datetime to timestamp
	size_t n = seconds * 2;
	double totalExchangeLastPrice = current.LastPrice() * n;
	long long count = n--;

	long long leftedge = current.toTimeStamp() - seconds * 2;

	for (auto it = data.rbegin(); it != data.rend(); it++)
	{
		if (it->toTimeStamp() > leftedge){
			totalExchangeLastPrice += (it->LastPrice() * n);
			--n;
			count += n;
		}
		else{
			break;
		}
	}

	//assert(totalVolume != 0);
	//assert(totalExchangePrice >= 0.0);

	return totalExchangeLastPrice / count;
}
Ejemplo n.º 21
0
void AttrCounter::getTopNameIds_(
    int topNum,
    std::vector<AttrTable::nid_t>& topNameIds)
{
    if (topNum == 0)
    {
        topNum = nameValueCountTable_.size();
    }

    AttrScoreQueue queue(topNum);
    for (NameValueCountTable::const_iterator it = nameValueCountTable_.begin();
            it != nameValueCountTable_.end(); ++it)
    {
        AttrTable::nid_t nameId = it->first;
        int valueCount = it->second;
        double score = getNameScore_(nameId);

        if (score > 0 && valueCount >= minValueCount_)
        {
            AttrScore attrScore(nameId, score);
            queue.insert(attrScore);
        }
    }

    topNameIds.resize(queue.size());
    for (std::vector<sf1r::faceted::AttrTable::nid_t>::reverse_iterator rit = topNameIds.rbegin();
            rit != topNameIds.rend(); ++rit)
    {
        *rit = queue.pop().first;
    }
}
Ejemplo n.º 22
0
  void switchRegisterSelection(std::vector<std::string> RegisterToSelect) {
    registerToBeFound = NULL;
    QList<QTreeWidgetItem*> registerList = qtHardMon->ui.registerTreeWidget->findItems(
        RegisterToSelect.back().c_str(), Qt::MatchExactly | Qt::MatchRecursive);
    RegisterToSelect.pop_back();

    for(std::vector<std::string>::reverse_iterator nameIter = RegisterToSelect.rbegin();
        nameIter != RegisterToSelect.rend();
        ++nameIter) {
      // Iterate the list until we find the one with the right module

      for(QList<QTreeWidgetItem*>::iterator registerIter = registerList.begin(); registerIter != registerList.end();
          ++registerIter) {
        // if we found the right register select it and quit the loop
        if((*registerIter)->parent()->text(0) == (*nameIter).c_str()) {
          registerToBeFound = *registerIter;
          break;
        }
      }
    }
    if(!registerToBeFound) {
      BOOST_FAIL("Register not found...");
    }
    else {
      qtHardMon->ui.registerTreeWidget->setCurrentItem(registerToBeFound);
    }
  }
Ejemplo n.º 23
0
void
AlnusPhyolgeticBranch::setRowIndex(unsigned int baseIndex)
{
    if (mChildren.empty()) {
        mRowIndex = baseIndex;
        return;
    }
    //    unsigned int numberOfNodesInTheMostLeftChild = mChildren.front()->getNumberOfNodes() + 1;
    
    // Cumulative numbers of nodes in the reverse order
    std::vector<unsigned int> numbersOfNodesInRightChildren;
    unsigned int numberOfNodes = 0;
    numbersOfNodesInRightChildren.push_back(numberOfNodes);
    for (std::vector<AlnusPhyolgeticBranch*>::reverse_iterator i = mChildren.rbegin();
         i != mChildren.rend(); i++) {
        numberOfNodes += (*i)->getNumberOfNodes() + 1;
        numbersOfNodesInRightChildren.push_back(numberOfNodes);
    }
    
    // Recursive calls
    mRowIndex = baseIndex - numbersOfNodesInRightChildren.at(mChildren.size() - 1);
    //    assert(mRowIndex == numberOfNodesInTheMostLeftChild + 1);
    AlnusPhyolgeticBranch *branch = mChildren.at(0);
    branch->setRowIndex(mRowIndex - 1);
    
    for (size_t i = 1; i < mChildren.size(); i++) {
        branch = mChildren.at(i);
        unsigned int childBaseIndex = baseIndex - numbersOfNodesInRightChildren.at(mChildren.size() - 1 - i);
        branch->setRowIndex(childBaseIndex);
    }
    
}
Ejemplo n.º 24
0
static mode_t get_device_perm(const char *path,
                              const std::vector<std::string> &links,
                              unsigned *uid, unsigned *gid)
{
    // Search the perms list in reverse so that ueventd.$hardware can
    // override ueventd.rc
    for (auto it = dev_perms.rbegin(); it != dev_perms.rend(); ++it) {
        bool match = false;

        const struct perms_ &dp = *it;

        if (perm_path_matches(path, &dp)) {
            match = true;
        } else {
            for (const std::string &link : links) {
                if (perm_path_matches(link.c_str(), &dp)) {
                    match = true;
                    break;
                }
            }
        }

        if (match) {
            *uid = dp.uid;
            *gid = dp.gid;
            return dp.perm;
        }
    }
    // Default if nothing found.
    *uid = 0;
    *gid = 0;
    return 0600;
}
Ejemplo n.º 25
0
void GxsChannelPostsWidget::insertChannelPosts(std::vector<RsGxsChannelPost> &posts, GxsMessageFramePostThread *thread, bool related)
{
    if (related && thread) {
        std::cerr << "GxsChannelPostsWidget::insertChannelPosts fill only related posts as thread is not possible" << std::endl;
        return;
    }

    std::vector<RsGxsChannelPost>::const_reverse_iterator it;

    int count = posts.size();
    int pos = 0;

    if (!thread) {
        ui->feedWidget->setSortingEnabled(false);
    }

    for (it = posts.rbegin(); it != posts.rend(); ++it)
    {
        if (thread && thread->stopped()) {
            break;
        }

        if (thread) {
            thread->emitAddPost(qVariantFromValue(*it), related, ++pos, count);
        } else {
            createPostItem(*it, related);
        }
    }

    if (!thread) {
        ui->feedWidget->setSortingEnabled(true);
    }
}
Ejemplo n.º 26
0
int32_t rdConfLoader::handle_as_section(const char* line, std::vector<std::string>& paths) 
{
    paths.clear();
    std::string line_trimed = rdStringUtil::trim(line);
    int32_t size = (int32_t)line_trimed.size();

    if (size < 2
            || '[' != line_trimed[0]
            || ']' != line_trimed[size - 1]) { 
        return E_CONF_ERROR;
    }

    line_trimed = line_trimed.substr(1, size - 2);
    size -= 2;

    std::vector<std::string> v;
    rdStringUtil::split_string(line_trimed, ".", v, /*filter_empty = */false);
    if (0 == v.size()) {
        return E_CONF_ERROR;
    }

    std::vector<std::string>::iterator itr;
    for (itr = v.begin(); itr != v.end(); ++itr) {
        std::string s = rdStringUtil::trim(*itr);

        if (s.empty()) {
            return E_CONF_ERROR;
        }
        else {
            paths.push_back(s);
        }
    }

    std::vector<std::string>::reverse_iterator ritr;
    ritr = paths.rbegin();
    if (ritr != paths.rend()) {
        ++ritr;
        while (ritr != paths.rend()) {
            if ('@' == (*ritr)[0]) {
                paths.clear();
                return E_CONF_ERROR;
            }
            ++ritr;
        }
    }
    return 0;
}
Ejemplo n.º 27
0
void FtpClientApp::update()
{
	mFrameRate = getFrameRate();
	
	if ( mFullScreen != isFullScreen() ) {
		setFullScreen( mFullScreen );
		mFullScreen = isFullScreen();
	}

	if ( !mText.empty() ) {
		TextBox tbox = TextBox()
			.alignment( TextBox::LEFT )
			.font( mFont )
			.size( ivec2( getWindowWidth() - 250, TextBox::GROW ) )
			.text( "" );
		for ( vector<string>::const_reverse_iterator iter = mText.rbegin(); iter != mText.rend(); ++iter ) {
			tbox.appendText( "> " + *iter + "\n" );
		}
		tbox.setColor( ColorAf( 1.0f, 0.8f, 0.75f, 1.0f ) );
		tbox.setBackgroundColor( ColorAf::black() );
		tbox.setPremultiplied( false );
		mTexture = gl::Texture::create( tbox.render() );
		while ( mText.size() > 75 ) {
			mText.erase( mText.begin() );
		}
	}

	if ( mConnectionControl->isConnected()	&& 
		 mConnectionControl->getBuffer()	&& 
		 mConnectionControl->getBuffer()->getSize() > 0 ) {
		const BufferRef& buffer = mConnectionControl->getBuffer();

		string s = ProtocolInterface::bufferToString( buffer );
		
		mFtpResponse.parse( buffer );
		mText.push_back( mFtpResponse.toString() );

		switch ( mFtpResponse.getReplyCode() ) {
		case FtpReplyCode_220_SERVICE_READY_FOR_NEW_USER:
			mFtpRequest.set( FtpCommand_USER, "****" );
			mText.push_back( mFtpRequest.toString() );
			// TODO get toBuffer to work here
			mConnectionControl->write( mFtpRequest.toBuffer() );
			break;
		case FtpReplyCode_230_USER_LOGGED_IN_PROCEED:
			// TODO open data connection here
			break;
		case FtpReplyCode_331_USER_NAME_OKAY_NEED_PASSWORD:
			mFtpRequest.set( FtpCommand_PASS, "****" );
			// TODO get toBuffer to work here
			mText.push_back( mFtpRequest.toString() );
			mConnectionControl->write( mFtpRequest.toBuffer() );
			break;
		default:
			mConnectionControl->close();
			break;
		}
	}
}
Ejemplo n.º 28
0
 ~CreatedGraphProperties()
 {
     /* First clear all consumers */
     std::vector<std::shared_ptr<flitr::ImageConsumer>>::reverse_iterator consumerIter = consumers.rbegin();
     while(consumerIter != consumers.rend()) {
         (*consumerIter) = nullptr;
         ++consumerIter;
     }
     consumers.clear();
     /* Now only clear all the producers */
     std::vector<std::shared_ptr<flitr::ImageProducer>>::reverse_iterator producerIter = producers.rbegin();
     while(producerIter != producers.rend()) {
         (*producerIter) = nullptr;
         ++producerIter;
     }
     producers.clear();
 }
Ejemplo n.º 29
0
/**
 * Sets the front of the Shoe to the given Card ranks and suits
 */
void FrontloadShoe(std::unique_ptr<Sim>& sim, std::vector<std::pair<int, int> > ranks)
{
    auto& shoeCards = sim->GetGame()->GetShoe()->GetCards();
    for (auto it = ranks.rbegin(); it != ranks.rend(); it++)
    {
        shoeCards.push_front(std::unique_ptr<Card>(new Card(it->first, it->second)));
    }
    return;
}
Ejemplo n.º 30
0
void eddic::as::restore(AssemblyFileWriter& writer, const std::vector<std::string>& registers){
    auto it = registers.rbegin();
    auto end = registers.rend();

    while(it != end){
        writer.stream() << "pop " << *it << '\n';
        ++it;
    }
}