int main(int, char**)
{
    static_assert(( std::is_convertible<std::shared_ptr<A>, std::shared_ptr<B> >::value), "");
    static_assert((!std::is_convertible<std::shared_ptr<B>, std::shared_ptr<A> >::value), "");
    static_assert((!std::is_convertible<std::shared_ptr<A>, std::shared_ptr<C> >::value), "");
    {
        const std::shared_ptr<A> pA(new A);
        assert(pA.use_count() == 1);
        assert(B::count == 1);
        assert(A::count == 1);
        {
            std::shared_ptr<B> pB(pA);
            assert(B::count == 1);
            assert(A::count == 1);
            assert(pB.use_count() == 2);
            assert(pA.use_count() == 2);
            assert(pA.get() == pB.get());
        }
        assert(pA.use_count() == 1);
        assert(B::count == 1);
        assert(A::count == 1);
    }
    assert(B::count == 0);
    assert(A::count == 0);
    {
        std::shared_ptr<A> pA;
        assert(pA.use_count() == 0);
        assert(B::count == 0);
        assert(A::count == 0);
        {
            std::shared_ptr<B> pB(pA);
            assert(B::count == 0);
            assert(A::count == 0);
            assert(pB.use_count() == 0);
            assert(pA.use_count() == 0);
            assert(pA.get() == pB.get());
        }
        assert(pA.use_count() == 0);
        assert(B::count == 0);
        assert(A::count == 0);
    }
    assert(B::count == 0);
    assert(A::count == 0);

  return 0;
}
Example #2
0
File: Node.hpp Project: Fdhvdu/lib
		~Node()
		{
			while(next.use_count()==1)
			{
				auto temp{std::move(next->next)};
				next=std::move(temp);
			}
		}
Example #3
0
void Camera::setImage(std::shared_ptr<Image>& image)
{
    if(image.use_count() == 1){
        image_ = image;
    } else {
        image_ = std::make_shared<Image>(*image);
    }
    image.reset();
}
Example #4
0
void RangeSensor::setRangeData(std::shared_ptr<RangeData>& data)
{
    if(data.use_count() == 1){
        rangeData_ = data;
    } else {
        rangeData_ = std::make_shared<RangeData>(*data);
    }
    data.reset();
}
Example #5
0
int main()
{
    static_assert(( std::is_convertible<std::shared_ptr<A>, std::weak_ptr<B> >::value), "");
    static_assert((!std::is_convertible<std::weak_ptr<B>, std::shared_ptr<A> >::value), "");
    static_assert((!std::is_convertible<std::shared_ptr<A>, std::weak_ptr<C> >::value), "");
    {
        const std::shared_ptr<A> pA(new A);
        assert(pA.use_count() == 1);
        assert(B::count == 1);
        assert(A::count == 1);
        {
            std::weak_ptr<B> pB(pA);
            assert(B::count == 1);
            assert(A::count == 1);
            assert(pB.use_count() == 1);
            assert(pA.use_count() == 1);
        }
        assert(pA.use_count() == 1);
        assert(B::count == 1);
        assert(A::count == 1);
    }
    assert(B::count == 0);
    assert(A::count == 0);
    {
        std::shared_ptr<A> pA;
        assert(pA.use_count() == 0);
        assert(B::count == 0);
        assert(A::count == 0);
        {
            std::weak_ptr<B> pB(pA);
            assert(B::count == 0);
            assert(A::count == 0);
            assert(pB.use_count() == 0);
            assert(pA.use_count() == 0);
        }
        assert(pA.use_count() == 0);
        assert(B::count == 0);
        assert(A::count == 0);
    }
    assert(B::count == 0);
    assert(A::count == 0);
}
void ClientNetworking::AsyncReadMessage(const std::shared_ptr<ClientNetworking>& keep_alive) {
    // If keep_alive's count < 2 the networking thread is orphaned so shut down
    if (keep_alive.use_count() < 2)
        DisconnectFromServerImpl();

    if (m_socket.is_open())
        boost::asio::async_read(
            m_socket, boost::asio::buffer(m_incoming_header),
            boost::bind(&ClientNetworking::HandleMessageHeaderRead, this, keep_alive,
                        boost::asio::placeholders::error,
                        boost::asio::placeholders::bytes_transferred));
}
bool collidechecker::init(std::shared_ptr<tools::Map2D<float> > map_ptr) {

    if (map_ptr.use_count() < 0) {
        std::cerr << "Error map is emty!" << std::endl;
        return false;
    }

    map_ptr_ = map_ptr;

    step_ = sqrt(map_ptr->getResolution() * map_ptr_->getResolution() * 2);
    return true;
}
Example #8
0
 void release_node(std::shared_ptr<struct binomial_node<T>> &n)
 {
       if (n.use_count() == 0)
           return;
       auto &sibling = n->mRight;
       while(sibling)
       {
           auto &s = sibling->mRight;
           release_node(sibling);
           sibling = s; 
       }
       release_node(n->mChild);
       n.reset();
 }
Example #9
0
// The purpose of self is to represent shared ownership during
// processByteEvents.  This allows the owner to release ownership of the tracker
// from a callback without causing problems
bool ByteEventTracker::processByteEvents(std::shared_ptr<ByteEventTracker> self,
                                         uint64_t bytesWritten,
                                         bool eorTrackingEnabled) {
  bool advanceEOM = false;

  while (!byteEvents_.empty() &&
         (byteEvents_.front().byteOffset_ <= bytesWritten)) {
    ByteEvent& event = byteEvents_.front();
    int64_t latency;
    auto txn = event.getTransaction();

    switch (event.eventType_) {
    case ByteEvent::FIRST_HEADER_BYTE:
      txn->onEgressHeaderFirstByte();
      break;
    case ByteEvent::FIRST_BYTE:
      txn->onEgressBodyFirstByte();
      break;
    case ByteEvent::LAST_BYTE:
      txn->onEgressBodyLastByte();
      addAckToLastByteEvent(txn, event, eorTrackingEnabled);
      advanceEOM = true;
      break;
    case ByteEvent::PING_REPLY_SENT:
      latency = event.getLatency();
      callback_->onPingReplyLatency(latency);
      break;
    }

    VLOG(5) << " removing ByteEvent " << event;
    // explicitly remove from the list, in case delete event triggers a
    // callback that would absorb this ByteEventTracker.
    event.listHook.unlink();
    delete &event;
  }

  if (eorTrackingEnabled && advanceEOM) {
    nextLastByteEvent_ = nullptr;
    for (auto& event : byteEvents_) {
      if (event.eventType_ == ByteEvent::LAST_BYTE) {
        nextLastByteEvent_ = &event;
        break;
      }
    }

    VLOG(5) << "Setting nextLastByteNo to "
            << (nextLastByteEvent_ ? nextLastByteEvent_->byteOffset_ : 0);
  }
  return self.use_count() == 1;
}
Example #10
0
void CarBlock::showNotesDialog(int _idNotes, int _idCar)
{
    emit inProgress();
    if(_idCar == idCar) {
        if(Database::isOpen()) {
                notesDialogPointer = std::shared_ptr<NotesDialog>(new NotesDialog(_idNotes, _idCar));
                if(notesDialogPointer.use_count() == 1 && notesDialogPointer.get()->exec() == NotesDialog::Rejected){
                    if(!(BookingDialog::isOpen || ServiceBlock::isOpen)) emit progressFinished();
                    emit noteClosed();
                }
        }
        else {
            QMessageBox::critical(this,tr("Błąd!"), tr("Utracono połączenie z bazą danych!"));
        }
    }
    emit progressFinished();
}
void print(const boost::system::error_code& ec,
           const std::shared_ptr<boost::asio::deadline_timer>& timer_ptr,
           const std::shared_ptr<int>& count_ptr){
    std::cout << "wait until: "
              << timer_ptr->expires_at() << std::endl;
    std::cout << "Timer pointer count: "
              << timer_ptr.use_count() << std::endl;
    if(*count_ptr < 5){
        std::cout << *count_ptr << std::endl;
        ++(*count_ptr);
        // timerのexpiry timeを移動
        timer_ptr->expires_at(
                    timer_ptr->expires_at() + boost::posix_time::seconds(1));
        timer_ptr->async_wait(
                    [&ec, &timer_ptr, &count_ptr]
                    (const boost::system::error_code&){
                        return print(
                                ec,
                                timer_ptr,
                                count_ptr);
                    });
    }
}
static void test_enable_shared_from_this(std::shared_ptr<C> sp) {
  ASSERT_EQ(1l, sp.use_count());

  // Test shared_from_this().
  std::shared_ptr<C> sp2 = sp->shared_from_this();
  ASSERT_EQ(sp, sp2);

  // Test weak_from_this().
  std::weak_ptr<C> wp = sp->weak_from_this();
  ASSERT_EQ(sp, wp.lock());
  sp.reset();
  sp2.reset();
  ASSERT_EQ(nullptr, wp.lock());

  // Test shared_from_this() and weak_from_this() on object not owned by a
  // shared_ptr. Undefined in C++14 but well-defined in C++17. Also known to
  // work with libstdc++ >= 20150123. Feel free to add other standard library
  // versions where the behavior is known.
#if __cplusplus >= 201700L || __GLIBCXX__ >= 20150123L
  C stack_resident;
  ASSERT_THROW(stack_resident.shared_from_this(), std::bad_weak_ptr);
  ASSERT_TRUE(stack_resident.weak_from_this().expired());
#endif
}
Example #13
0
void process(std::shared_ptr<int> ptr)
{
    std::cout << "inside the process function:" << ptr.use_count() << "\n";
}
Example #14
0
File: main.cpp Project: CCJY/coliru
int f( std::shared_ptr< int > ptr )
{
  return ptr.use_count( );
}
Example #15
0
File: main.cpp Project: CCJY/coliru
int g( std::shared_ptr< int > &ptr )
{
  return ptr.use_count( );
}
//---------------------------------------------------------
int f_00(std::shared_ptr<base> ptr)
{
	//ptr.use_count() increase by 1

	return ptr.use_count();
}
Example #17
0
void process(std::shared_ptr<int> ptr)
{
	std::cout << ptr.use_count() << std::endl;
}
Example #18
0
void process (std::shared_ptr<int> ptr) {
	std::cout << "process : ";
	std::cout << "ptr use count : " << ptr.use_count() << std::endl;
	return;
}
//---------------------------------------------------------
int f_01(const std::shared_ptr<base>& ptr)
{
	return ptr.use_count();
}