Пример #1
0
Map::~Map()
{
    // Notify everyone that server is going down
    if(!(pTemplate->mapflag & MAP_INSTANCED))
        std::for_each(Players.begin(), Players.end(), boost::bind(&Player::OnServerShutdown, _1));

    // Cleanup entities
    std::for_each(Creatures.begin(), Creatures.end(), Deleter());
    std::for_each(GameObjects.begin(), GameObjects.end(), Deleter());
    std::for_each(Spells.begin(), Spells.end(), Deleter());
    
    delete pMapScript;

    sLog.Write("Map %u destroyed.", MapID);
}
Пример #2
0
 void Own( UniquePtr *source )
 {
     ASSUME( (_ptr != source->_ptr) || (_ptr == 0) );
     Deleter( (X *)_ptr );
     _ptr = source->_ptr;
     source->_ptr = 0;
 }
Пример #3
0
        std::shared_ptr<Component>
        get_ptr_postproc_helper(naming::address const& addr,
            naming::id_type const& id)
        {
            if (get_locality() != addr.locality_)
            {
                HPX_THROW_EXCEPTION(bad_parameter,
                    "hpx::get_ptr_postproc<Component, Deleter>",
                    "the given component id does not belong to a local object");
                return std::shared_ptr<Component>();
            }

            if (!traits::component_type_is_compatible<Component>::call(addr))
            {
                HPX_THROW_EXCEPTION(bad_component_type,
                    "hpx::get_ptr_postproc<Component, Deleter>",
                    "requested component type does not match the given component id");
                return std::shared_ptr<Component>();
            }

            Component* p = get_lva<Component>::call(addr.address_);
            std::shared_ptr<Component> ptr(p, Deleter(id));

            ptr->pin();     // the shared_ptr pins the component
            return ptr;
        }
Пример #4
0
void EuropaCapture::publish(double time, double timestamp, GraphicsWindow&
    window) {
#ifdef HAVE_MOOS_MESSAGES
  CompressedImageMsg msg;
  CompressedImageMsg::CompressedImage img;

  PNMImage screenshot;
  window.get_screenshot(screenshot);
  
  stream.str("");
  screenshot.write(stream, "capture.bmp");
  img.format = CompressedImageMsg::IF_BMP;
  img.size = stream.tellp();
  img.buffer.reset((unsigned char*)stream.str().data(), Deleter());
  img.timestamp = mClient->getTime(timestamp);
  img.frameNumber = frameNumber;
  img.cameraId = 0;
  
  msg.timestamp = mClient->getTime(timestamp);
  msg.compressedImages.push_back(img);

  MOOSPublisher::publish(mMsgName, msg.toString());
#endif

  ++frameNumber;
}
Пример #5
0
 UniquePtr &operator = ( UniquePtr &&source )
 {
     ASSUME( this != &source );
     Deleter( (X *)_ptr );
     _ptr = source._ptr;
     source._ptr = 0;
     return *this;
 }
Пример #6
0
void testSmartPointer() {
  char *mem = (char*)malloc(4);
  {
    SmartPointer Deleter(mem);
    // destructor called here
  }
  *mem = 0; // expected-warning{{Use of memory after it is freed}}
}
Пример #7
0
//==============================================================================
Error GlPipelineHandle::commonConstructor(
	GlCommandBufferHandle& commands,
	const GlShaderHandle* progsBegin, const GlShaderHandle* progsEnd)
{
	class Command: public GlCommand
	{
	public:
		GlPipelineHandle m_ppline;
		Array<GlShaderHandle, 6> m_progs;
		U8 m_progsCount;

		Command(GlPipelineHandle& ppline, 
			const GlShaderHandle* progsBegin, const GlShaderHandle* progsEnd)
		:	m_ppline(ppline)
		{
			m_progsCount = 0;
			const GlShaderHandle* prog = progsBegin;
			do
			{
				m_progs[m_progsCount++] = *prog;
			} while(++prog != progsEnd);
		}

		Error operator()(GlCommandBuffer* cmdb)
		{
			Error err = m_ppline._get().create(
				&m_progs[0], &m_progs[0] + m_progsCount,
				cmdb->getGlobalAllocator());

			GlHandleState oldState = m_ppline._setState(
				err ? GlHandleState::ERROR : GlHandleState::CREATED);
			ANKI_ASSERT(oldState == GlHandleState::TO_BE_CREATED);
			(void)oldState;

			return err;
		}
	};

	using Alloc = GlAllocator<GlPipeline>;
	using DeleteCommand = GlDeleteObjectCommand<GlPipeline, Alloc>;
	using Deleter = 
		GlHandleDeferredDeleter<GlPipeline, Alloc, DeleteCommand>;

	Error err = _createAdvanced(
		&commands._get().getQueue().getDevice(),
		commands._get().getGlobalAllocator(), 
		Deleter());

	if(!err)
	{
		_setState(GlHandleState::TO_BE_CREATED);

		commands._pushBackNewCommand<Command>(*this, progsBegin, progsEnd);
	}

	return err;
}
Пример #8
0
void testSubclassSmartPointer() {
  char *mem = (char*)malloc(4);
  {
    Subclass Deleter(mem);
    // Remove dead bindings...
    doSomething();
    // destructor called here
  }
  *mem = 0; // expected-warning{{Use of memory after it is freed}}
}
Пример #9
0
void testMultipleInheritance2() {
  char *mem = (char*)malloc(4);
  {
    MultipleInheritance Deleter(0, mem);
    // Remove dead bindings...
    doSomething();
    // destructor called here
  }
  *mem = 0; // expected-warning{{Use of memory after it is freed}}
}
Пример #10
0
void testMultipleInheritance3() {
  char *mem = (char*)malloc(4);
  {
    MultipleInheritance Deleter(mem, mem);
    // Remove dead bindings...
    doSomething();
    // destructor called here
    // expected-warning@27 {{Attempt to free released memory}}
  }
}
Пример #11
0
ObjectMgr::~ObjectMgr()
{
    std::for_each(CreatureTemplates.begin(), CreatureTemplates.end(), MapDeleter());
    std::for_each(GameObjectTemplates.begin(), GameObjectTemplates.end(), MapDeleter());
    std::for_each(ItemTemplates.begin(), ItemTemplates.end(), MapDeleter());
    std::for_each(QuestTemplates.begin(), QuestTemplates.end(), MapDeleter());
    std::for_each(SpellTemplates.begin(), SpellTemplates.end(), MapDeleter());
    std::for_each(MapTemplates.begin(), MapTemplates.end(), MapDeleter());
    std::for_each(Players.begin(), Players.end(), Deleter());
}
Пример #12
0
int main()
{
    {
    A* p = new A[3];
    assert(A::count == 3);
    std::unique_ptr<A[], const Deleter&> s(p, Deleter());
    assert(s.get() == p);
    assert(s.get_deleter().state() == 5);
    }
    assert(A::count == 0);
}
Пример #13
0
fcppt::shared_ptr<
	Type,
	Deleter
>::shared_ptr(
	Other *const _ptr
)
:
	impl_(
		_ptr,
		Deleter()
	)
{
}
Пример #14
0
/* Constructs an envp array from a hash table.
 * The returned array occupies a single contiguous block of memory
 * such that it can be released by a single call to free(3).
 * The last element of the returned array is set to NULL for compatibility
 * with posix_spawn() */
std::unique_ptr<char*, ChildProcess::Deleter>
ChildProcess::Environment::asEnviron(size_t* env_size) const {
  size_t len = (1 + map_.size()) * sizeof(char*);

  // Make a pass through to compute the required memory size
  for (const auto& it : map_) {
    const auto& key = it.first;
    const auto& val = it.second;

    // key=value\0
    len += key.size() + 1 + val.size() + 1;
  }

  auto envp = (char**)malloc(len);
  if (!envp) {
    throw std::bad_alloc();
  }
  auto result = std::unique_ptr<char*, Deleter>(envp, Deleter());

  // Now populate
  auto buf = (char*)(envp + map_.size() + 1);
  size_t i = 0;
  for (const auto& it : map_) {
    const auto& key = it.first;
    const auto& val = it.second;

    envp[i++] = buf;

    // key=value\0
    memcpy(buf, key.data(), key.size());
    buf += key.size();

    memcpy(buf, "=", 1);
    buf++;

    memcpy(buf, val.data(), val.size());
    buf += val.size();

    *buf = 0;
    buf++;
  }

  envp[map_.size()] = nullptr;

  if (env_size) {
    *env_size = len;
  }
  return result;
}
Пример #15
0
fcppt::shared_ptr<
	Type,
	Deleter
>::shared_ptr(
	Other *const _ptr,
	Alloc const &_alloc
)
:
	impl_(
		_ptr,
		Deleter(),
		_alloc
	)
{
}
Пример #16
0
    void clear()
    {
      /* Delete values if a deleter is defined */
      if (Deleter != nullptr) {
	while (_next_free_slot > 0) {
	  --_next_free_slot;
	  const size_t block_index = _next_free_slot / block_size;
	  const size_t value_index = _next_free_slot % block_size;
	  Deleter(_blocks[block_index][value_index]);
	}
      } else {
	_next_free_slot = 0;
      }
      /* Delete value blocks */
      for (auto block : _blocks) {
	delete [] block;
      }
      _blocks.clear();
      return;
    }
Пример #17
0
//==============================================================================
GlBufferHandle::GlBufferHandle(GlCommandBufferHandle& commands,
                               GLenum target, PtrSize size, GLenum flags)
{
    ANKI_ASSERT(!isCreated());

    using Alloc = GlGlobalHeapAllocator<GlBuffer>;

    using DeleteCommand =
        GlDeleteObjectCommand<GlBuffer, GlGlobalHeapAllocator<U8>>;

    using Deleter = GlHandleDeferredDeleter<GlBuffer, Alloc, DeleteCommand>;

    *static_cast<Base::Base*>(this) = Base::Base(
                                          &commands._getQueue().getDevice(),
                                          commands._getQueue().getDevice()._getAllocator(),
                                          Deleter());
    _setState(GlHandleState::TO_BE_CREATED);

    // Fire the command
    commands._pushBackNewCommand<GlBufferCreateCommand>(
        *this, target, size, flags);
}
Пример #18
0
 ~Sheduler() {
   
   std::for_each(m_preprocess.begin(), m_preprocess.end(), Deleter());
   std::for_each(m_process.begin(), m_process.end(), Deleter());
   std::for_each(m_postprocess.begin(), m_postprocess.end(), Deleter());      
 };
Пример #19
0
SourceReader::SourceReader()
: m_file(unique_ptr<istream, Deleter>(&cin, Deleter(false)))
{
  LOG_SHORT(LINFO, ("Reading OSM data from stdin"));
}
Пример #20
0
SourceReader::SourceReader(istringstream & stream)
: m_file(unique_ptr<istream, Deleter>(&stream, Deleter(false)))
{
  LOG_SHORT(LINFO, ("Reading OSM data from memory"));
}
Пример #21
0
SourceReader::SourceReader(string const & filename)
{
  m_file = unique_ptr<istream, Deleter>(new ifstream(filename), Deleter());
  CHECK(static_cast<ifstream *>(m_file.get())->is_open() , ("Can't open file:", filename));
  LOG_SHORT(LINFO, ("Reading OSM data from", filename));
}
Пример #22
0
CommandProcessor::~CommandProcessor()
{
    std::for_each(commandList.begin(),
                  commandList.end(),
                  Deleter());
}
Пример #23
0
 void clear()
 {
     std::for_each(this->states + 0, this->states + this->len, Deleter());
     this->len = 0;
 }
Пример #24
0
 ~UniquePtr()
 {
     Deleter( (X *)_ptr );  //  this dummy C-cast will eliminate a syntax confusion between creating a local variable _ptr and calling a constructor with the argument _ptr
 }
Пример #25
0
World::~World()
{
    std::for_each(Maps.begin(), Maps.end(), Deleter());
    delete pAIFactory;
    delete pWorldAcceptor;
}
Пример #26
0
 //!Constructs a scoped_ptr, storing a copy of p(which can be 0) and d.
 //!Does not throw.
 explicit scoped_ptr(const pointer &p = 0, const Deleter &d = Deleter())
    : Deleter(d), m_ptr(p) // throws if pointer/Deleter copy ctor throws
 {}
Пример #27
0
 void Release()
 {
     Deleter( (X *)_ptr );
     _ptr = 0;
 }
Пример #28
0
int main() {
  // expected-error@+1 {{call to deleted constructor of 'std::unique_ptr<int, const Deleter &>}}
  std::unique_ptr<int, const Deleter&> s((int*)nullptr, Deleter());
}
Пример #29
0
 void InitBuffer(size_t count)
 {
   m_offset = 0;
   m_size = count;
   m_data.reset(new char[m_size], Deleter());
 }
 ~multi_handle()
 {
     Deleter()(N, ids.data());
 }