Example #1
0
void ModalListPicker::ModalInit()
{
    m_dropped = true;

    // Try to center the current item unless within half the number of
    // shown rows from the top or bottom
    if (CurrentItem() != m_lb_wnd->end() && !m_lb_wnd->Empty()) {
        std::size_t current_ii(std::distance(m_lb_wnd->begin(), CurrentItem()));
        std::size_t half_shown((m_num_shown_rows / 2));
        std::size_t even_extra_one((m_num_shown_rows % 2 == 0) ? 1 : 0);

        m_lb_wnd->SetFirstRowShown(m_lb_wnd->begin());
        if (current_ii >= (m_lb_wnd->NumRows() - 1 - half_shown)) {
            m_lb_wnd->BringRowIntoView(--m_lb_wnd->end());
        } else if (current_ii >= half_shown) {
            m_lb_wnd->SetFirstRowShown(
                std::next(m_lb_wnd->begin(),
                          current_ii - half_shown + even_extra_one));
        }
    }

    m_lb_wnd->Hide(); // to enable CorrectListSize() to work
    CorrectListSize();
    Show();
}
Example #2
0
    virtual void _Reply_data(std::shared_ptr<protocol::Invoke> invoke) override final
    {
        if (invoke->has("_History_uid") == true)
        {
            // REGISTER THIS PROCESS ON HISTORY LIST
            std::shared_ptr<slave::InvokeHistory> history(new slave::InvokeHistory(invoke));
            progress_list_.insert({ history->getUID(), history });

            if (invoke->has("_Piece_first") == true)
            {
                // PARALLEL PROCESS
                size_t first = invoke->get("_Piece_first")->getValue<size_t>();
                size_t last = invoke->get("_Piece_last")->getValue<size_t>();

                invoke->erase(invoke->end() - 2, invoke->end());
                ((base::ParallelSystemArrayBase*)system_array_)->sendPieceData(invoke, first, last);
            }
            else if (invoke->has("_Process_name") == true)
            {
                // DISTRIBUTED PROCESS
                auto ds_system_array = (distributed::base::DistributedSystemArrayBase*)system_array_;

                // FIND THE MATCHED ROLE
                const std::string &process_name = invoke->get("_Process_name")->getValue<std::string>();
                if (ds_system_array->hasProcess(process_name) == false)
                    return;

                // SEND DATA VIA THE ROLE
                auto process = ds_system_array->getProcess(process_name);
                ((distributed::base::DistributedProcessBase*)(process.get()))->sendData(invoke, 1.0);
            }
        }
        else
            replyData(invoke);
    };
Example #3
0
 void receive_hello(std::shared_ptr<tcp::socket> socket
         , std::shared_ptr<std::vector<std::uint8_t>> buffer
         , std::size_t const read_size = sizeof(ofp_header))
 {
     auto const read_head = buffer->size();
     buffer->resize(read_head + read_size);
     boost::asio::async_read(*socket
             , boost::asio::buffer(&(*buffer)[read_head], read_size)
             , boost::asio::transfer_exactly(read_size)
             , [=](boost::system::error_code const& ec, std::size_t const) {
         if (ec) {
             std::cout << "read error: " << ec.message() << std::endl;
             return;
         }
         auto const header = detail::read_ofp_header(boost::asio::buffer(*buffer));
         if (header.type != hello::message_type) {
             std::cout << "not hello message" << std::endl;
             return;
         }
         if (header.length != buffer->size()) {
             receive_hello(std::move(socket), std::move(buffer), header.length - buffer->size());
             return;
         }
         auto channel = std::make_shared<v10::secure_channel_impl<ControllerHandler>>(
                 std::move(*socket), controller_handler_, *thread_pool_);
         auto it = buffer->begin();
         channel->run(hello::decode(it, buffer->end()));
     });
 }
static BufferInfoIterator findBufferId(
        const std::shared_ptr<const std::vector<const BufferInfo>> &array,
        IOMX::buffer_id bufferId) {
    return std::find_if(
            array->begin(), array->end(),
            [bufferId](const BufferInfo &info) { return bufferId == info.mBufferId; });
}
static BufferInfoIterator findClientBuffer(
        const std::shared_ptr<const std::vector<const BufferInfo>> &array,
        const sp<MediaCodecBuffer> &buffer) {
    return std::find_if(
            array->begin(), array->end(),
            [buffer](const BufferInfo &info) { return info.mClientBuffer == buffer; });
}
Example #6
0
void Output::printBinary(std::shared_ptr<std::vector<char>> data)
{
	try
	{
		if(!data || data->empty()) return;
		std::ostringstream stringstream;
		stringstream << std::hex << std::setfill('0') << std::uppercase;
		for(std::vector<char>::iterator i = data->begin(); i != data->end(); ++i)
		{
			stringstream << std::setw(2) << (int32_t)((uint8_t)(*i));
		}
		stringstream << std::dec;
		std::cout << stringstream.str() << std::endl;
	}
	catch(const std::exception& ex)
    {
    	printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
    }
    catch(const Exception& ex)
    {
    	printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
    }
    catch(...)
    {
    	printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__);
    }
}
Example #7
0
 void IdRef::VisitCheck(std::shared_ptr<std::map<std::string, ast::Matrix>> vars,
                        std::shared_ptr<reporter::ErrorReporter> reporter) const 
 {
     auto varname = id->Spelling();
     if (vars->find(varname) == vars->end())
         throw "Undefined function or variable \'" + varname + "\'.";
 }
Example #8
0
   /**
   *  This constructor populates this CountDB from file, reading the set of counts from fname.
   */
   CountDB( const std::string& fname, std::shared_ptr<std::vector<Kmer>>& kmers, uint32_t merSize ) :  
     _kmers(kmers), _merSize( merSize ) {

      std::cerr << "checking that kmers are sorted . . . ";
      assert( std::is_sorted( kmers->begin(), kmers->end() ) );
      std::cerr << "done\n";


      std::ifstream counts(fname, std::ios::in | std::ios::binary );
      uint32_t fileMerSize{0};
      counts.read( reinterpret_cast<char*>(&fileMerSize), sizeof(fileMerSize) );
      std::cerr << "checking that the mersizes are the same . . .";
      assert( fileMerSize == merSize );
      std::cerr << "done\n";

      size_t numCounts{0};
      
      counts.read( reinterpret_cast<char*>(&numCounts), sizeof(size_t) );
      
      std::cerr << "checking that the counts are the same . . .";
      assert( numCounts == kmers->size() );
      std::cerr << "done\n";

      _counts = std::vector< AtomicCount >( numCounts );
      std::cerr << "reading counts from file . . .";
      counts.read( reinterpret_cast<char*>(&_counts[0]), sizeof(_counts[0]) * numCounts );
      std::cerr << "done\n";
      counts.close();
   }
		void PeerComm::HandleMessagePayload(std::shared_ptr<std::vector<char>> payload_, const boost::system::error_code& error)
		{
			if (!error)
			{
				QueueReceiveMessage();

				auto id = (*payload_)[0];
					
				std::vector<char> payload;
				payload.reserve(payload_->size() - 1);
				payload.insert(payload.end(), payload_->begin() + 1, payload_->end());

				std::unique_lock<std::mutex> _(m_Mutex);

				switch ((Peer::MessageType)id)
				{
				case Peer::MessageType::Choke:
					m_State = PeerCommState::Choked;
					m_Incoming.push_back(std::make_unique<Peer::Choke>());
					break;
				case Peer::MessageType::Unchoke:
					m_State = PeerCommState::Working;
					m_Incoming.push_back(std::make_unique<Peer::Unchoke>());
					break;
				case Peer::MessageType::Interested:
					m_Incoming.push_back(std::make_unique<Peer::Interested>());
					break;
				case Peer::MessageType::NotInterested:
					m_Incoming.push_back(std::make_unique<Peer::NotInterested>());
					break;
				case Peer::MessageType::Have:
					m_Incoming.push_back(std::make_unique<Peer::Have>(payload));
					break;
				case Peer::MessageType::Bitfield:
					m_Incoming.push_back(std::make_unique<Peer::Bitfield>(payload));
					break;
				case Peer::MessageType::Request:
					m_Incoming.push_back(std::make_unique<Peer::Request>(payload));
					break;
				case Peer::MessageType::Piece:
					m_Incoming.push_back(std::make_unique<Peer::Piece>(payload));
					break;
				case Peer::MessageType::Cancel:
					m_Incoming.push_back(std::make_unique<Peer::Cancel>(payload));
					break;
				case Peer::MessageType::Port:
					m_Incoming.push_back(std::make_unique<Peer::Port>(payload));
					break;
				default:
					std::cout << "invalid message id" << std::endl;
					m_State = PeerCommState::Error;
					return;
				}
			}
			else
			{
				std::unique_lock<std::mutex> _(m_Mutex);
				m_State = PeerCommState::Error;
			}
		}
Example #10
0
        inline void operator() (args_t&&... args) const
        {
            //add ref
            bool erased = false;
            auto slot_list = m_slot_list;
            auto keysref = m_keys;
            auto keys = *keysref;
            for (size_t i = 0; i < keys.size(); ++i)
            {
                auto it = m_slot_list->find(keys[i]);
                if (it != m_slot_list->end())
                {
                    it->second(std::forward<args_t>(args)...);
                }
                else
                {
                    erased = true;
                    (*keysref)[i] = 0;
                }
            }

            if (erased)
            {
                keysref->erase(std::remove(keysref->begin(), keysref->end(), 0), keysref->end());
            }

        }
Example #11
0
	rtf_reader(const std::shared_ptr<cainteoir::buffer> &aData)
		: cainteoir::buffer(aData->begin(), aData->end())
		, mCurrent(aData->begin())
		, mData(std::make_shared<cainteoir::buffer>(nullptr, nullptr))
		, mParameter(0)
		, mDepth(0)
	{
	}
Example #12
0
 Slice<ItemType>
 (   std::list<std::shared_ptr<Slice<ItemType>>> others)
 :   store(std::make_shared<Storage>())
 {
     uintptr_t total_size = 0;
     for (auto it = others.begin(); it != others.end(); ++it) {
         total_size += (*it)->size();
     };
     
     store->reserve(total_size);
     
     for (auto it = others.begin(); it != others.end(); ++it) {
         store->insert(store->end(), (*it)->istart, (*it)->iend);
     };
     istart = store->begin();
     iend = store->end();
 }
// Returns the value, for the given key, in that bucket, or 0 if not present.
int64_t getBucketValue(const std::shared_ptr<DimToValMap>& bucket,
                       const MetricDimensionKey& key) {
    const auto& itr = bucket->find(key);
    if (itr != bucket->end()) {
        return itr->second;
    }
    return 0;
}
Example #14
0
bool
Session::prepare_for_run( std::shared_ptr< const adcontrols::ControlMethod::Method > m )
{
    if ( m ) {
        auto it = m->find( m->begin(), m->end(), acqrscontrols::ap240::method::clsid() ); // "ap240" );
        if ( it != m->end() ) {
            auto method = std::make_shared< acqrscontrols::ap240::method >();
            if ( it->get<>( *it, *method ) ) {
                
                task::instance()->prepare_for_run( method );

                return true;
            }
        }
    }
    return false;
}
Example #15
0
 void GroupTree::getNodes(std::shared_ptr< GroupTreeNode > fromNode, std::vector<std::shared_ptr< const GroupTreeNode >>& nodes) const {
     std::map<std::string, std::shared_ptr< GroupTreeNode > >::const_iterator iter = fromNode->begin();
     while (iter != fromNode->end()) {
         std::shared_ptr< GroupTreeNode > child = (*iter).second;
         nodes.push_back(child);
         getNodes(child, nodes);
         ++iter;
     }
 }
Example #16
0
size_t BitmapPrimitiveShape::AllConnectedComponents(const PointCloud &pc, float epsilon,
	BitmapInfo& bitmapInfo, std::shared_ptr<MiscLib::Vector< size_t > >indices, MiscLib::Vector< int >& componentsImg, 
		MiscLib::Vector< std::pair< int, size_t > >& labels, bool doFiltering )
{
	// first find the extent in the parametrization
	// but remember the parametrized points for projection into a bitmap
	size_t size = indices->size();
	if(!size)
		return 0;

	// set up bitmap
	MiscLib::Vector< std::pair< float, float > > extParams;

	BuildBitmap(pc, &epsilon, indices->begin(), indices->end(), &bitmapInfo.params,
		&bitmapInfo.bbox, &bitmapInfo.bitmap, &bitmapInfo.uextent, &bitmapInfo.vextent, &bitmapInfo.bmpIdx);

	/*static int fname_int = 0;
	std::ostringstream fn;
	fn << "bitmapImg" << fname_int++ << ".txt";
	std::ofstream file;
	file.open(fn.str().c_str(), std::ios::out);
	for(size_t j = 0; j < vextent; ++j)
	{
		for(size_t i = 0; i < uextent; ++i)
			file << bitmap[j * uextent + i];
		file << std::endl;
	}
	file.close();*/

	// do a wrapping by copying pixels
	PreWrapBitmap(bitmapInfo.bbox, epsilon, bitmapInfo.uextent, bitmapInfo.vextent, &bitmapInfo.bitmap);

	MiscLib::Vector< char > tempBmp(bitmapInfo.bitmap.size()); // temporary bitmap object
	bool uwrap, vwrap;
	WrapBitmap(bitmapInfo.bbox, epsilon, &uwrap, &vwrap);

	if (doFiltering)
	{
		// closing
		DilateCross(bitmapInfo.bitmap, bitmapInfo.uextent, bitmapInfo.vextent, uwrap, vwrap, &tempBmp);
		ErodeCross(tempBmp, bitmapInfo.uextent, bitmapInfo.vextent, uwrap, vwrap, &bitmapInfo.bitmap);
		// opening
		//ErodeCross(bitmap, uextent, vextent, uwrap, vwrap, &tempBmp);
		//DilateCross(tempBmp, uextent, vextent, uwrap, vwrap, &bitmap);
	}

	Components(bitmapInfo.bitmap, bitmapInfo.uextent, bitmapInfo.vextent, uwrap, vwrap, &componentsImg,
		&labels);
	if(labels.size() <= 1) // found no connected component!
	{
		return 0; // associate no points with this shape
	}

	WrapComponents(bitmapInfo.bbox, epsilon, bitmapInfo.uextent, bitmapInfo.vextent, &componentsImg, &labels);

	return labels.size();
}
Example #17
0
void ModalListPicker::LBSelChangedSlot(const ListBox::SelectionSet& rows)
{
    if (rows.empty()) {
        SignalChanged(m_lb_wnd->end());
    } else {
        auto sel_it = *rows.begin();
        SignalChanged(sel_it);
    }
}
Example #18
0
 void GroupTree::deepCopy(std::shared_ptr< GroupTreeNode > origin, std::shared_ptr< GroupTreeNode > copy) const {
     std::map<std::string, std::shared_ptr< GroupTreeNode > >::const_iterator iter = origin->begin();
     while (iter != origin->end()) {
         std::shared_ptr< GroupTreeNode > originChild = (*iter).second;
         std::shared_ptr< GroupTreeNode > copyChild = copy->addChildGroup(originChild->name());
         deepCopy(originChild, copyChild);
         ++iter;
     }
 }
Example #19
0
	void buildMap() {
		for(auto it = file->begin(); it != file->end(); it++) {
			std::stringstream ss(*it);
			std::string item;
			while(std::getline(ss, item, ' ')) {
				size_type lineNumber = it - file->begin();
				(*map)[item].insert(lineNumber);
			}
		}
	}
Example #20
0
 void GroupTree::printTree(std::ostream &os , std::shared_ptr< GroupTreeNode > fromNode) const {
     os << fromNode->name() << "(" << fromNode.get() << ")";
     std::map<std::string, std::shared_ptr< GroupTreeNode > >::const_iterator iter = fromNode->begin();
     while (iter != fromNode->end()) {
         const auto& child = (*iter).second;
         os << "<-" << child->name() << "(" << child.get() << ")" << std::endl;
         printTree(os , child);
         ++iter;
     }
 }
Example #21
0
void print_local(madness::World& world, const std::shared_ptr<TiledArray::Pmap>& pmap) {
  for(ProcessID r = 0; r < world.size(); ++r) {
    world.gop.fence();
    if(r == world.rank()) {
      std::cout << r << ": { ";
      for(TiledArray::Pmap::const_iterator it = pmap->begin(); it != pmap->end(); ++it)
        std::cout << *it << " ";
      std::cout << "}\n";
    }
  }
}
Example #22
0
void Entropy::setFin(std::shared_ptr< const std::map<int, int> > ptr_fin_map) 
{
    fin.clear();
    n = 0;
    for ( auto it = ptr_fin_map->begin(); it != ptr_fin_map->end(); ++it )
    {
        int freq = it->first, cnt = it->second;
        fin.push_back( std::make_pair( freq, cnt ) );
        n += (freq * cnt);
    }
}
void set_value(const std::shared_ptr<pj::object> &cfg, const char *part, const char* key, const pj::value &val)
{
    if (cfg->find(part) == cfg->end())
    {
        pj::object temp;
        cfg->insert({ part, pj::value(temp) });
    }

    pj::object o = cfg->at(part).get<pj::object>();
    o[key] = val;
    (*cfg.get())[part] = pj::value(o);
}
std::shared_ptr<pj::value> find_value(const std::shared_ptr<pj::object> &cfg, const char *part, const char* key)
{
    if (cfg->find(part) == cfg->end()) { return nullptr; }

    pj::value v = cfg->at(part);
    if (!v.is<pj::object>()) { return nullptr; }

    pj::object o = v.get<pj::object>();
    if (o.find(key) == o.end()) { return nullptr; }

    return std::make_shared<pj::value>(o.at(key));
}
Example #25
0
ResultF memoize_recursive_helper(const F f, std::shared_ptr<Cache> storage)
{
    return [f, storage](FIn2 x) {
        const auto it = storage->find(x);
        if (it == storage->end())
        {
            const auto g = memoize_recursive_helper(f, storage);
            (*storage)[x] = internal::invoke(f, g, x);
        }
        return (*storage)[x];
    };
    }
Example #26
0
playlist HlsParser::CreateSinglePlaylist(std::shared_ptr<std::vector<TAG>> tag,std::string playlisturldir)
{
	playlist tmpplaylist = { 0, 0, playlisttype::VOD};
	std::vector<TAG>::iterator playlisttagitr = tag->begin();
	for (; playlisttagitr != tag->end(); playlisttagitr++)
	{
		switch (playlisttagitr->tagname)
		{
		case TAG_EXT_X_TARGETDURATTION:
		{
			tmpplaylist.targetduration = atoi(playlisttagitr->tagvalue.c_str());
		}break;
		case TAG_EXT_X_MEDIA_SEQUENCE:
		{
			tmpplaylist.sequenceid = atoi(playlisttagitr->tagvalue.c_str());
		}break;
		case TAG_EXT_X_PLAYLIST_TYPE:
		{
			if (playlisttagitr->tagvalue == "VOD")
			{
				tmpplaylist.type = playlisttype::VOD;
			}
			else if (playlisttagitr->tagvalue == "LIVE")
			{
				tmpplaylist.type = playlisttype::LIVE;
			}
		}break;
		case TAG_EXTINF:
		{
			chunk tmpchunk;
			int pos = playlisttagitr->tagvalue.find(',');
			tmpchunk.chunkduration = atof(playlisttagitr->tagvalue.substr(0,pos).c_str());
			tmpplaylist.chunklist.push_back(tmpchunk);
		}break;
		case TAG_EXT_X_BYTERANGE:
		{
			int pos = playlisttagitr->tagvalue.find('@');
			tmpplaylist.chunklist.back().byterange_low = atoi(playlisttagitr->tagvalue.substr(pos + 1).c_str());
			tmpplaylist.chunklist.back().byterange_up = atoi(playlisttagitr->tagvalue.substr(0, pos).c_str()) + tmpplaylist.chunklist.back().byterange_low;
		}break;
		default:
		{

		}break;
		}
		if (!playlisttagitr->tagurl.empty())
		{
			tmpplaylist.chunklist.back().url = playlisturldir + playlisttagitr->tagurl;
		}
	}
	return tmpplaylist;
}
std::unordered_map<std::string, std::vector<Feature>>
FeatureIndex::lookupSymbolFeatures(const std::vector<IndexedSubfeature>& symbolFeatures,
                                   const RenderedQueryOptions& queryOptions,
                                   const std::vector<const RenderLayer*>& layers,
                                   const OverscaledTileID& tileID,
                                   const std::shared_ptr<std::vector<size_t>>& featureSortOrder) const {
    std::unordered_map<std::string, std::vector<Feature>> result;
    if (!tileData) {
        return result;
    }
    std::vector<IndexedSubfeature> sortedFeatures(symbolFeatures.begin(), symbolFeatures.end());

    std::sort(sortedFeatures.begin(), sortedFeatures.end(), [featureSortOrder](const IndexedSubfeature& a, const IndexedSubfeature& b) {
        // Same idea as the non-symbol sort order, but symbol features may have changed their sort order
        // since their corresponding IndexedSubfeature was added to the CollisionIndex
        // The 'featureSortOrder' is relatively inefficient for querying but cheap to build on every bucket sort
        if (featureSortOrder) {
            // queryRenderedSymbols documentation says we'll return features in
            // "top-to-bottom" rendering order (aka last-to-first).
            // Actually there can be multiple symbol instances per feature, so
            // we sort each feature based on the first matching symbol instance.
            auto sortedA = std::find(featureSortOrder->begin(), featureSortOrder->end(), a.index);
            auto sortedB = std::find(featureSortOrder->begin(), featureSortOrder->end(), b.index);
            assert(sortedA != featureSortOrder->end());
            assert(sortedB != featureSortOrder->end());
            return sortedA > sortedB;
        } else {
            // Bucket hasn't been re-sorted based on angle, so use same "reverse of appearance in source data"
            // logic as non-symboles
            return a.sortIndex > b.sortIndex;
        }
    });

    for (const auto& symbolFeature : sortedFeatures) {
        mat4 unusedMatrix;
        addFeature(result, symbolFeature, queryOptions, tileID.canonical, layers, GeometryCoordinates(), {}, 0, unusedMatrix);
    }
    return result;
}
Example #28
0
 static std::shared_ptr< std::vector<int> > getVectOfIndex(std::shared_ptr< std::vector<T> >& input, std::shared_ptr<std::vector<T> >& keys){
     if (std::is_fundamental<T>::value){
         std::shared_ptr< std::vector<int> > indexVecPtr = std::make_shared< std::vector<int> >();
         
         std::for_each(keys->begin(), keys->end(), [&](T& element) -> void{
             int element_index = BinarySearchNumbers::getElementIndex(input, element);
             indexVecPtr->push_back(element_index);
         });
         
         return indexVecPtr;
     }else
         return nullptr;
 };
Example #29
0
    void TransMult::applyMULTFLT( std::shared_ptr<const Fault> fault) {
        double transMult = fault->getTransMult();

        for (auto face_iter = fault->begin(); face_iter != fault->end(); ++face_iter) {
            std::shared_ptr<const FaultFace> face = *face_iter;
            FaceDir::DirEnum faceDir = face->getDir();
            std::shared_ptr<GridProperty<double> > multProperty = getDirectionProperty(faceDir);

            for (auto cell_iter = face->begin(); cell_iter != face->end(); ++cell_iter) {
                size_t globalIndex = *cell_iter;
                multProperty->multiplyValueAtIndex( globalIndex , transMult);
            }
        }
    }
 cache_iterator_type get_initial_data(const double& x) const
 {
   cache_iterator_type after(cache_->lower_bound(x));
   
   if (after == cache_->begin())
     return after;
   
   if (after == cache_->end())
     return --cache_iterator_type(after);
   
   cache_iterator_type before(after);
   --before;
   return abs(before->first - x) < abs(after->first - x) ? before : after;
 }