text:
// STL
#include <iostream>
#include <fstream>
#include <algorithm>
#include <iterator>

// Boost
#include <boost/program_options/parsers.hpp>
#include <boost/program_options/variables_map.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/mpi/environment.hpp>
#include <boost/mpi/communicator.hpp>
#include <boost/lexical_cast.hpp>

// Local
#include "mpi-pyp-topics.hh"
#include "corpus.hh"
#include "mpi-corpus.hh"
#include "gzstream.hh"

static const char *REVISION = "$Rev: 170 $";

// Namespaces
using namespace boost;
using namespace boost::program_options;
using namespace std;

int main(int argc, char **argv)
{
  mpi::environment env(argc, argv);
  mpi::communicator world;
  int rank = world.rank();
  bool am_root = (rank==0);
  if (am_root) cout << "Pitman Yor topic models: Copyright 2010 Phil Blunsom\n";
  if (am_root) std::cout << "I am process " << world.rank() << " of " << world.size() << "." << std::endl;
  if (am_root) cout << REVISION << '\n' <<endl;

  ////////////////////////////////////////////////////////////////////////////////////////////
  // Command line processing
  variables_map vm;

  // Command line processing
  {
    options_description cmdline_specific("Command line specific options");
    cmdline_specific.add_options()
      ("help,h", "print help message")
      ("config,c", value<string>(), "config file specifying additional command line options")
      ;
    options_description config_options("Allowed options");
    config_options.add_options()
      ("help,h", "print help message")
      ("data,d", value<string>(), "file containing the documents and context terms")
      ("topics,t", value<int>()->default_value(50), "number of topics")
      ("document-topics-out,o", value<string>(), "file to write the document topics to")
      ("default-topics-out", value<string>(), "file to write default term topic assignments.")
      ("topic-words-out,w", value<string>(), "file to write the topic word distribution to")
      ("samples,s", value<int>()->default_value(10), "number of sampling passes through the data")
      ("backoff-type", value<string>(), "backoff type: none|simple")
//      ("filter-singleton-contexts", "filter singleton contexts")
      ("hierarchical-topics", "Use a backoff hierarchical PYP as the P0 for the document topics distribution.")
      ("binary-counts,b", "Use binary rather than integer counts for contexts.")
      ("freq-cutoff-start", value<int>()->default_value(0), "initial frequency cutoff.")
      ("freq-cutoff-end", value<int>()->default_value(0), "final frequency cutoff.")
      ("freq-cutoff-interval", value<int>()->default_value(0), "number of iterations between frequency decrement.")
      ("max-contexts-per-document", value<int>()->default_value(0), "Only sample the n most frequent contexts for a document.")
      ;

    cmdline_specific.add(config_options);

    store(parse_command_line(argc, argv, cmdline_specific), vm);
    notify(vm);

    if (vm.count("config") > 0) {
      ifstream config(vm["config"].as<string>().c_str());
      store(parse_config_file(config, config_options), vm);
    }

    if (vm.count("help")) {
      cout << cmdline_specific << "\n";
      return 1;
    }
  }
  ////////////////////////////////////////////////////////////////////////////////////////////

  if (!vm.count("data")) {
    cerr << "Please specify a file containing the data." << endl;
    return 1;
  }

  // seed the random number generator: 0 = automatic, specify value otherwise
  unsigned long seed = 0;
  MPIPYPTopics model(vm["topics"].as<int>(), vm.count("hierarchical-topics"), seed);

  // read the data
  BackoffGenerator* backoff_gen=0;
  if (vm.count("backoff-type")) {
    if (vm["backoff-type"].as<std::string>() == "none") {
      backoff_gen = 0;
    }
    else if (vm["backoff-type"].as<std::string>() == "simple") {
      backoff_gen = new SimpleBackoffGenerator();
    }
    else {
     cerr << "Backoff type (--backoff-type) must be one of none|simple." <<endl;
      return(1);
    }
  }

  //ContextsCorpus contexts_corpus;
  MPICorpus contexts_corpus;
  contexts_corpus.read_contexts(vm["data"].as<string>(), backoff_gen, /*vm.count("filter-singleton-contexts")*/ false, vm.count("binary-counts"));
  int mpi_start = 0, mpi_end = 0;
  contexts_corpus.bounds(&mpi_start, &mpi_end);
  std::cerr << "\tProcess " << rank << " has documents " << mpi_start << " -> " << mpi_end << "." << std::endl;

  model.set_backoff(contexts_corpus.backoff_index());

  if (backoff_gen)
    delete backoff_gen;

  // train the sampler
  model.sample_corpus(contexts_corpus, vm["samples"].as<int>(),
                      vm["freq-cutoff-start"].as<int>(),
                      vm["freq-cutoff-end"].as<int>(),
                      vm["freq-cutoff-interval"].as<int>(),
                      vm["max-contexts-per-document"].as<int>());

  if (vm.count("document-topics-out")) {
    std::ofstream documents_out((vm["document-topics-out"].as<string>() + ".pyp-process-" + boost::lexical_cast<std::string>(rank)).c_str());
    //int documents = contexts_corpus.num_documents();
    /*
    int mpi_start = 0, mpi_end = documents;
    if (world.size() != 1) {
      mpi_start = (documents / world.size()) * rank;
      if (rank == world.size()-1) mpi_end = documents;
      else mpi_end = (documents / world.size())*(rank+1);
    }
    */

    map<int,int> all_terms;
    for (int document_id=mpi_start; document_id<mpi_end; ++document_id) {
      assert (document_id < contexts_corpus.num_documents());
      const Document& doc = contexts_corpus.at(document_id);
      vector<int> unique_terms;
      for (Document::const_iterator docIt=doc.begin(); docIt != doc.end(); ++docIt) {
        if (unique_terms.empty() || *docIt != unique_terms.back())
          unique_terms.push_back(*docIt);
        // increment this terms frequency
        pair<map<int,int>::iterator,bool> insert_result = all_terms.insert(make_pair(*docIt,1));
        if (!insert_result.second)
          all_terms[*docIt] = all_terms[*docIt] + 1;
      }
      documents_out << contexts_corpus.key(document_id) << '\t';
      documents_out << model.max(document_id).first << " " << doc.size() << " ||| ";
      for (std::vector<int>::const_iterator termIt=unique_terms.begin(); termIt != unique_terms.end(); ++termIt) {
        if (termIt != unique_terms.begin())
          documents_out << " ||| ";
        vector<std::string> strings = contexts_corpus.context2string(*termIt);
        copy(strings.begin(), strings.end(),ostream_iterator<std::string>(documents_out, " "));
        std::pair<int,MPIPYPTopics::F> maxinfo = model.max(document_id, *termIt);
        documents_out << "||| C=" << maxinfo.first << " P=" << maxinfo.second;
      }
      documents_out <<endl;
    }
    documents_out.close();
    world.barrier();

    if (am_root) {
      ogzstream root_documents_out(vm["document-topics-out"].as<string>().c_str());
      for (int p=0; p < world.size(); ++p) {
        std::string rank_p_prefix((vm["document-topics-out"].as<string>() + ".pyp-process-" + boost::lexical_cast<std::string>(p)).c_str());
        std::ifstream rank_p_trees_istream(rank_p_prefix.c_str(), std::ios_base::binary);
        root_documents_out << rank_p_trees_istream.rdbuf();
        rank_p_trees_istream.close();
        remove((rank_p_prefix).c_str());
      }
      root_documents_out.close();
    }

    if (am_root && vm.count("default-topics-out")) {
      ofstream default_topics(vm["default-topics-out"].as<string>().c_str());
      default_topics << model.max_topic() <<endl;
      for (std::map<int,int>::const_iterator termIt=all_terms.begin(); termIt != all_terms.end(); ++termIt) {
        vector<std::string> strings = contexts_corpus.context2string(termIt->first);
        default_topics << model.max(-1, termIt->first).first << " ||| " << termIt->second << " ||| ";
        copy(strings.begin(), strings.end(),ostream_iterator<std::string>(default_topics, " "));
        default_topics <<endl;
      }
    }
  }

  if (am_root && vm.count("topic-words-out")) {
    ogzstream topics_out(vm["topic-words-out"].as<string>().c_str());
    model.print_topic_terms(topics_out);
    topics_out.close();
  }

  cout <<endl;

  return 0;
}

ext: cc

max_stars_repo_name: agesmundo/FasterCubePruning

max_issues_repo_name: jhclark/cdec

max_forks_repo_name: jhclark/cdec


text:
// Copyright (c) 2012-2018 The Elastos Open Source Project
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "MerkleBlockMessage.h"

#include <P2P/PeerManager.h>
#include <P2P/Peer.h>
#include <Common/Log.h>
#include <Common/Utils.h>
#include <Plugin/Block/AuxPow.h>
#include <Plugin/Block/ELAMerkleBlock.h>
#include <Plugin/Registry.h>
#include <Plugin/Block/MerkleBlock.h>

#include <boost/scoped_ptr.hpp>

namespace Elastos {
	namespace ElaWallet {

		MerkleBlockMessage::MerkleBlockMessage(const MessagePeerPtr &peer) : Message(peer) {

		}

		bool MerkleBlockMessage::Accept(const bytes_t &msg) {
			std::vector<uint256> txHashes;
			int version;
			ByteStream stream(msg);

			PeerManager *manager = _peer->GetPeerManager();
			MerkleBlockPtr block(Registry::Instance()->CreateMerkleBlock(manager->GetChainID()));

			if (block == nullptr) {
				_peer->error("create merkle block pointer with type fail");
				return false;
			}

#ifdef SUPPORT_NEW_INV_TYPE
			version = MERKLEBLOCK_VERSION_1;
#else
			version = MERKLEBLOCK_VERSION_0;
#endif

			if (!block->Deserialize(stream, version)) {
				_peer->debug("merkle block orignal data: {}", msg.getHex());
				_peer->error("merkle block deserialize with type fail");
				return false;
			}

			if (!block->IsValid((uint32_t) time(nullptr))) {
				_peer->error("invalid merkleblock: {}", block->GetHash().GetHex());
				return false;
			} else if (!_peer->SentFilter() && !_peer->SentGetdata()) {
				_peer->error("got merkleblock message before loading a filter");
				return false;
			} else {
				_peer->SetWaitingBlocks(false);
				block->MerkleBlockTxHashes(txHashes);

				for (size_t i = txHashes.size(); i > 0; i--) { // reverse order for more efficient removal as tx arrive
					_peer->AddCurrentBlockTxHash(txHashes[i - 1]);
				}
			}

			if (_peer->CurrentBlockTxHashes().size() > 0) { // wait til we get all tx messages before processing the block
				_peer->SetCurrentBlock(block);
			} else {
				FireRelayedBlock(block);
			}

			return true;
		}

		void MerkleBlockMessage::Send(const SendMessageParameter &param) {
		}

		std::string MerkleBlockMessage::Type() const {
			return MSG_MERKLEBLOCK;
		}
	}
}

ext: cpp

max_forks_repo_name: yiyaowen/ela-spvwallet-desktop


text:
//
// keyvi - A key value store.
//
// Copyright 2015 Hendrik Muhs<hendrik.muhs@gmail.com>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

/*
 * generator_test.cpp
 *
 *  Created on: May 8, 2014
 *      Author: hendrik
 */

#include <boost/test/unit_test.hpp>
#include <boost/filesystem.hpp>
#include "dictionary/fsa/generator.h"
#include "dictionary/fsa/automata.h"
#include "dictionary/fsa/entry_iterator.h"
#include "dictionary/fsa/internal/sparse_array_persistence.h"
#include "dictionary/fsa/internal/int_value_store.h"

//#define ENABLE_TRACING
#include "dictionary/util/trace.h"

namespace keyvi {
namespace dictionary {
namespace fsa {

BOOST_AUTO_TEST_SUITE( GeneratorTests )

BOOST_AUTO_TEST_CASE( simple ) {
  internal::SparseArrayPersistence<> p(2048,
                                     boost::filesystem::temp_directory_path());

  Generator<internal::SparseArrayPersistence<>> g(fsa::generator_param_t({{"memory_limit_mb","10"}}));
  g.Add("aaaa");
  g.Add("aabb");
  g.Add("aabc");
  g.Add("aacd");
  g.Add("bbcd");

  g.CloseFeeding();

  std::ofstream out_stream("testFile", std::ios::binary);
  g.Write(out_stream);
  out_stream.close();

  automata_t f(new Automata("testFile"));

  EntryIterator it(f);
  EntryIterator end_it;

  BOOST_CHECK_EQUAL("aaaa", it.GetKey());
  ++it;
  BOOST_CHECK_EQUAL("aabb", it.GetKey());
  ++it;
  BOOST_CHECK_EQUAL("aabc", it.GetKey());
  ++it;
  BOOST_CHECK_EQUAL("aacd", it.GetKey());
  ++it;
  BOOST_CHECK_EQUAL("bbcd", it.GetKey());
  ++it;
  BOOST_CHECK(it == end_it);
}

BOOST_AUTO_TEST_CASE( simple2 ) {
  internal::SparseArrayPersistence<> p(2048,
                                     boost::filesystem::temp_directory_path());

  Generator<internal::SparseArrayPersistence<>> g(fsa::generator_param_t({{"memory_limit_mb","10"}}));
  g.Add("aaa");
  g.Add("abcde");
  g.Add("bar");
  g.Add("foo");
  g.Add("zar");

  g.CloseFeeding();

  std::ofstream out_stream("testFile2", std::ios::binary);
  g.Write(out_stream);
  out_stream.close();

  automata_t f(new Automata("testFile2"));
  EntryIterator it(f);
  EntryIterator end_it;

  BOOST_CHECK_EQUAL("aaa", it.GetKey());
  ++it;
  BOOST_CHECK_EQUAL("abcde", it.GetKey());
  ++it;
  BOOST_CHECK_EQUAL("bar", it.GetKey());
  ++it;
  BOOST_CHECK_EQUAL("foo", it.GetKey());
  ++it;
  BOOST_CHECK_EQUAL("zar", it.GetKey());
  ++it;
  BOOST_CHECK(it == end_it);
}

BOOST_AUTO_TEST_CASE( stringtest ) {
  Generator<internal::SparseArrayPersistence<>> g(fsa::generator_param_t({{"memory_limit_mb","10"}}));
  g.Add(std::string("aaa"));
  g.Add(std::string("abcde"));
  g.Add("bar");
  g.Add("foo");
  g.Add("zar");

  g.CloseFeeding();

  std::ofstream out_stream("testFile3", std::ios::binary);
  g.Write(out_stream);
  out_stream.close();

  automata_t f(new Automata("testFile3"));
  EntryIterator it(f);
  EntryIterator end_it;

  BOOST_CHECK_EQUAL("aaa", it.GetKey());
  ++it;
  BOOST_CHECK_EQUAL("abcde", it.GetKey());
  ++it;
  BOOST_CHECK_EQUAL("bar", it.GetKey());
  ++it;
  BOOST_CHECK_EQUAL("foo", it.GetKey());
  ++it;
  BOOST_CHECK_EQUAL("zar", it.GetKey());
  ++it;
  BOOST_CHECK(it == end_it);
}

BOOST_AUTO_TEST_CASE( intvaluetest ) {
  internal::SparseArrayPersistence<> p(2048,
                                     boost::filesystem::temp_directory_path());

  Generator<internal::SparseArrayPersistence<>, internal::IntInnerWeightsValueStore> g(fsa::generator_param_t({{"memory_limit_mb","10"}}));
  g.Add("eads", 576);

  g.Add("facebook", 4368451);
  g.Add("youtube", 2622207);

  g.CloseFeeding();

  std::ofstream out_stream("testFile4", std::ios::binary);
  g.Write(out_stream);
  out_stream.close();

  automata_t f(new Automata("testFile4"));
  EntryIterator it(f);
  EntryIterator end_it;

  BOOST_CHECK_EQUAL("eads", it.GetKey());
  BOOST_CHECK_EQUAL(576, it.GetValueId());

  ++it;
  BOOST_CHECK_EQUAL("facebook", it.GetKey());
  BOOST_CHECK_EQUAL(4368451, it.GetValueId());

  ++it;
  BOOST_CHECK_EQUAL("youtube", it.GetKey());
  BOOST_CHECK_EQUAL(2622207, it.GetValueId());
  ++it;

  BOOST_CHECK(it == end_it);
}

BOOST_AUTO_TEST_CASE( feedwithoutclose ) {
  // test that just triggers the case (if) generato is created but FSA creation is not finalized

  auto g = new   Generator<internal::SparseArrayPersistence<>, internal::IntInnerWeightsValueStore>(fsa::generator_param_t({{"memory_limit_mb","10"}}));
  g->Add("eads", 576);

  g->Add("facebook", 4368451);
  g->Add("youtube", 2622207);
  delete g;
}

BOOST_AUTO_TEST_CASE( manifesttest ) {
  Generator<internal::SparseArrayPersistence<>> g(fsa::generator_param_t({{"memory_limit_mb","10"}}));
  g.Add(std::string("aaa"));
  g.Add(std::string("abcde"));
  g.Add("bar");
  g.Add("foo");
  g.Add("zar");

  g.CloseFeeding();

  g.SetManifestFromString("{\"version\":\"42\"}");

  std::ofstream out_stream("testFile3", std::ios::binary);
  g.Write(out_stream);
  out_stream.close();

  automata_t f(new Automata("testFile3"));
  BOOST_CHECK_EQUAL("{\"version\":\"42\"}\n", f->GetManifestAsString());
}

BOOST_AUTO_TEST_CASE( zeroBytes ) {
  internal::SparseArrayPersistence<> p(2048,
                                     boost::filesystem::temp_directory_path());

  TRACE("test zerobyte");
  Generator<internal::SparseArrayPersistence<>> g(fsa::generator_param_t({{"memory_limit_mb","10"}}));
  g.Add(std::string("\0bbcd", 5));
  g.Add(std::string("a\0abc", 5));
  g.Add("aaaa");
  g.Add(std::string("aabb\0", 5));
  g.Add("aacd");
  g.Add("bbcd");

  g.CloseFeeding();

  std::ofstream out_stream("testFileZB", std::ios::binary);
  g.Write(out_stream);
  out_stream.close();

  TRACE("test zerobyte: load FSA");
  automata_t f(new Automata("testFileZB"));

  auto zero_state_walk = f->TryWalkTransition(f->GetStartState(), 0);
  BOOST_CHECK(zero_state_walk != 0);
  TRACE("test zerobyte: tested zb FSA");
  EntryIterator it(f);
  EntryIterator end_it;

  BOOST_CHECK_EQUAL(std::string("\0bbcd", 5), it.GetKey());
  ++it;
  BOOST_CHECK_EQUAL(std::string("a\0abc", 5), it.GetKey());
  ++it;
  BOOST_CHECK_EQUAL("aaaa", it.GetKey());
  ++it;
  BOOST_CHECK_EQUAL(std::string("aabb\0",5), it.GetKey());
  ++it;
  BOOST_CHECK_EQUAL("aacd", it.GetKey());
  ++it;
  BOOST_CHECK_EQUAL("bbcd", it.GetKey());
  ++it;
  BOOST_CHECK(it == end_it);
}

BOOST_AUTO_TEST_CASE( state_exception_handling ) {
  internal::SparseArrayPersistence<> p(2048,
                                       boost::filesystem::temp_directory_path());

  Generator<internal::SparseArrayPersistence<>> g(fsa::generator_param_t({{"memory_limit_mb","10"}}));

  BOOST_CHECK_THROW( g.WriteToFile("somefile"), generator_exception );

  g.Add("abcd");
  BOOST_CHECK_THROW( g.WriteToFile("somefile"), generator_exception );
  g.CloseFeeding();
  BOOST_CHECK_THROW( g.CloseFeeding(), generator_exception );

  BOOST_CHECK_THROW( g.Add("cdef"), generator_exception );

  ValueHandle handle;
  BOOST_CHECK_THROW( g.Add("ghij", handle), generator_exception );
}

BOOST_AUTO_TEST_CASE( value_handle ) {
  ValueHandle handle = {0,0,0,false, false};
  ValueHandle handle2 = {1,0,0,false, false};
  ValueHandle handle3 = {0,1,0,false, false};
  ValueHandle handle4 = {0,0,1,false, false};
  ValueHandle handle5 = {0,0,0,true, false};
  ValueHandle handle6 = {0,0,0,false, true};

  BOOST_CHECK(handle == handle);
  BOOST_CHECK(handle != handle2);
  BOOST_CHECK(handle != handle3);
  BOOST_CHECK(handle != handle4);
  BOOST_CHECK(handle != handle5);
  BOOST_CHECK(handle != handle6);
  BOOST_CHECK(handle6 == handle6);
  BOOST_CHECK(handle3 != handle4);
  BOOST_CHECK(handle5 != handle6);
}

BOOST_AUTO_TEST_SUITE_END()

} /* namespace fsa */
} /* namespace dictionary */
} /* namespace keyvi */


text:
#if !defined DumEvent_hxx
#define DumEvent_hxx

#include "resip/stack/SipMessage.hxx"
#include "tfm/Event.hxx"
#include "resip/dum/InviteSession.hxx"
#include "resip/dum/ClientInviteSession.hxx"
#include "resip/dum/ServerInviteSession.hxx"
#include "resip/dum/Handles.hxx"
#include <boost/shared_ptr.hpp>

class DumUserAgent;

class DumEvent : public Event
{
   public:
      DumEvent(DumUserAgent* dua);
      DumEvent(DumUserAgent* dua, const resip::SipMessage* msg);
      DumEvent(DumUserAgent* dua, const resip::SipMessage& msg);

      bool hasMessage() const { return mMessage.get() != 0; }
      boost::shared_ptr<resip::SipMessage> const getMessage() { return mMessage; }
   private:
      boost::shared_ptr<resip::SipMessage> mMessage;
};

/*
// ClientPagerMessage
typedef enum
{
   ClientPagerMessage_Success,
   ClientPagerMessage_Failure
} ClientPagerMessageEventType;

static const char* ClientPagerMessageEventTypeText[] =
{
   "Success",
   "Failure"
};

class ClientPagerMessageEvent : public DumEvent
{
   public:
      typedef ClientPagerMessageEventType Type;

      ClientPagerMessageEvent(DumUserAgent* dua, Type type, resip::ClientPagerMessageHandle h, const resip::SipMessage& msg)
         : DumEvent(dua, msg),
           mType(type),
           mHandle(h)
           //mMessage(msg)
      {
      }

      ClientPagerMessageEvent(DumUserAgent* dua, Type type, resip::ClientPagerMessageHandle h, const resip::SipMessage& msg,
                              std::auto_ptr<resip::Contents> constents)
         : DumEvent(dua, msg),
           mType(type),
           mHandle(h)
           //mMessage(msg)
      {
      }

      virtual resip::Data toString() const
      {
         resip::Data buffer;
         {
            resip::DataStream strm(buffer);
            strm << "ClientPagerMessageEvent - " << ClientPagerMessageEventTypeText[mType];
         }
         return buffer;
      }

      virtual resip::Data briefString() const
      {
         return toString();
      }

      static resip::Data getName() { return "ClientPagerMessgeEvent"; }
      static resip::Data getTypeName(Type type) { return ClientPagerMessageEventTypeText[type]; }

      Type getType() const { return mType; }

      resip::ClientPagerMessageHandle& getUsageHandle() { return mHandle; }

   protected:
      Type mType;
      resip::ClientPagerMessageHandle mHandle;
      //const resip::SipMessage mMessage;

};

// ServerPagerMessage
typedef enum
{
   ServerPagerMessage_MessageArrived
} ServerPagerMessageEventType;

static const char* ServerPagerMessageEventTypeText[] =
{
   "Message Arrived"
};

class ServerPagerMessageEvent : public DumEvent
{
   public:
      typedef ServerPagerMessageEventType Type;

      ServerPagerMessageEvent(DumUserAgent* dua, Type type, resip::ServerPagerMessageHandle h, const resip::SipMessage& msg)
         : DumEvent(dua, msg),
           mType(type),
           mHandle(h)
           //mMessage(msg)
      {
      }

      virtual resip::Data toString() const
      {
         resip::Data buffer;
         {
            resip::DataStream strm(buffer);
            strm << "ServerPagerMessageEvent - " << ServerPagerMessageEventTypeText[mType];
         }
         return buffer;
      }

      virtual resip::Data briefString() const
      {
         return toString();
      }

      static resip::Data getName() { return "ServerPagerMessgeEvent"; }
      static resip::Data getTypeName(Type type) { return ServerPagerMessageEventTypeText[type]; }

      Type getType() const { return mType; }

      resip::ServerPagerMessageHandle& getUsageHandle() { return mHandle; }

   protected:
      Type mType;
      resip::ServerPagerMessageHandle mHandle;
      //const resip::SipMessage mMessage;

};

// ServerOutOfDialogReq
typedef enum
{
ServerOutOfDialogReq_ReceivedRequest
   } ServerOutOfDialogReqEventType;

static const char* ServerOutOfDialogReqEventTypeText[] =
{
   "Received Request"
};

class ServerOutOfDialogReqEvent : public DumEvent
{
   public:
      typedef ServerOutOfDialogReqEventType Type;

      ServerOutOfDialogReqEvent(DumUserAgent* dua, Type type, resip::ServerOutOfDialogReqHandle h, const resip::SipMessage& msg)
         : DumEvent(dua, msg),
           mType(type),
           mHandle(h)
      {
      }

      virtual resip::Data toString() const
      {
         resip::Data buffer;
         {
            resip::DataStream strm(buffer);
            strm << "ServerOutOfDialogReqEvent - " << ServerOutOfDialogReqEventTypeText[mType];
         }
         return buffer;
      }

      virtual resip::Data briefString() const
      {
         return toString();
      }

      static resip::Data getName() { return "ServerOutOfDialogReqEvent"; }
      static resip::Data getTypeName(Type type) { return ServerOutOfDialogReqEventTypeText[type]; }

      Type getType() const { return mType; }

      resip::ServerOutOfDialogReqHandle& getUsageHandle() { return mHandle; }

   protected:
      Type mType;
      resip::ServerOutOfDialogReqHandle mHandle;
      //const resip::SipMessage mMessage;
};

// ClientOutOfDialogReq
typedef enum
{
   ClientOutOfDialogReq_Success,
   ClientOutOfDialogReq_Failure
} ClientOutOfDialogReqEventType;

static const char* ClientOutOfDialogReqEventTypeText[] =
{
   "Success",
   "Failure"
};

class ClientOutOfDialogReqEvent : public DumEvent
{
   public:
      typedef ClientOutOfDialogReqEventType Type;

      ClientOutOfDialogReqEvent(DumUserAgent* dua, Type type, resip::ClientOutOfDialogReqHandle h, const resip::SipMessage& msg)
         : DumEvent(dua, msg),
           mType(type),
           mHandle(h)
           //mMessage(msg)
      {
      }

      virtual resip::Data toString() const
      {
         resip::Data buffer;
         {
            resip::DataStream strm(buffer);
            strm << "ClientOutOfDialogReqEvent - " << ClientOutOfDialogReqEventTypeText[mType];
         }
         return buffer;
      }

      virtual resip::Data briefString() const
      {
         return toString();
      }

      static resip::Data getName() { return "ClientOutOfDialogReqEvent"; }
      static resip::Data getTypeName(Type type) { return ClientOutOfDialogReqEventTypeText[type]; }

      Type getType() const { return mType; }

      resip::ClientOutOfDialogReqHandle& getUsageHandle() { return mHandle; }

   protected:
      Type mType;
      resip::ClientOutOfDialogReqHandle mHandle;
      //const resip::SipMessage mMessage;
};
*/

#endif

ext: hxx

max_stars_repo_name: dulton/reSipServer

max_issues_repo_name: dulton/reSipServer

max_forks_repo_name: dulton/reSipServer


text:
//==============================================================================
//         Copyright 2003 - 2011   LASMEA UMR 6602 CNRS/Univ. Clermont II
//         Copyright 2009 - 2011   LRI    UMR 8623 CNRS/Univ Paris Sud XI
//
//          Distributed under the Boost Software License, Version 1.0.
//                 See accompanying file LICENSE.txt or copy at
//                     http://www.boost.org/LICENSE_1_0.txt
//==============================================================================
#ifndef BOOST_SIMD_MEMORY_FUNCTIONS_PACK_SPLAT_HPP_INCLUDED
#define BOOST_SIMD_MEMORY_FUNCTIONS_PACK_SPLAT_HPP_INCLUDED

#include <boost/simd/include/functions/splat.hpp>
#include <boost/simd/sdk/simd/pack/forward.hpp>
#include <boost/proto/make_expr.hpp>
#include <boost/proto/traits.hpp>

namespace boost { namespace simd { namespace ext
{
  BOOST_DISPATCH_IMPLEMENT         ( splat_ , tag::cpu_
                            , (A0)(A1)
                            , (scalar_< fundamental_<A0> >)
                              ((target_< ast_<A1, boost::simd::domain> >))
                            )
  {
    typedef typename proto::domain_of<typename A1::type>::type  domain;
    typedef dispatch::meta::
            as_<typename dispatch::meta::
                semantic_of<typename A1::type>::type
               >  value;

    typedef typename proto::result_of::
            make_expr<tag::splat_, domain, const A0&, const value&>::type
    result_type;

    BOOST_FORCEINLINE result_type
    operator()(A0 const& a0, A1 const&) const
    {
      return boost::proto::detail::
             make_expr_<tag::splat_, domain, const A0&, const value&>()(a0, value());
    }
  };
} } }

#endif

ext: hpp


text:
// Boost.Geometry Index
//
// R-tree R*-tree insert algorithm implementation
//
// Copyright (c) 2011-2014 Adam Wulkiewicz, Lodz, Poland.
//
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#ifndef BOOST_GEOMETRY_INDEX_DETAIL_RTREE_RSTAR_INSERT_HPP
#define BOOST_GEOMETRY_INDEX_DETAIL_RTREE_RSTAR_INSERT_HPP

#include <boost/geometry/index/detail/algorithms/content.hpp>

namespace boost { namespace geometry { namespace index {

namespace detail { namespace rtree { namespace visitors {

namespace rstar {

template <typename Value, typename Options, typename Translator, typename Box, typename Allocators>
class remove_elements_to_reinsert
{
public:
    typedef typename rtree::node<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type node;
    typedef typename rtree::internal_node<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type internal_node;
    typedef typename rtree::leaf<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type leaf;

    typedef typename Options::parameters_type parameters_type;

    //typedef typename Allocators::internal_node_pointer internal_node_pointer;
    typedef internal_node * internal_node_pointer;

    template <typename ResultElements, typename Node>
    static inline void apply(ResultElements & result_elements,
                             Node & n,
                             internal_node_pointer parent,
                             size_t current_child_index,
                             parameters_type const& parameters,
                             Translator const& translator,
                             Allocators & allocators)
    {
        typedef typename rtree::elements_type<Node>::type elements_type;
        typedef typename elements_type::value_type element_type;
        typedef typename geometry::point_type<Box>::type point_type;
        // TODO: awulkiew - change second point_type to the point type of the Indexable?
        typedef typename
            geometry::default_comparable_distance_result<point_type>::type
                comparable_distance_type;

        elements_type & elements = rtree::elements(n);

        const size_t elements_count = parameters.get_max_elements() + 1;
        const size_t reinserted_elements_count = (::std::min)(parameters.get_reinserted_elements(), elements_count - parameters.get_min_elements());

        BOOST_GEOMETRY_INDEX_ASSERT(parent, "node shouldn't be the root node");
        BOOST_GEOMETRY_INDEX_ASSERT(elements.size() == elements_count, "unexpected elements number");
        BOOST_GEOMETRY_INDEX_ASSERT(0 < reinserted_elements_count, "wrong value of elements to reinsert");

        // calculate current node's center
        point_type node_center;
        geometry::centroid(rtree::elements(*parent)[current_child_index].first, node_center);

        // fill the container of centers' distances of children from current node's center
        typedef typename index::detail::rtree::container_from_elements_type<
            elements_type,
            std::pair<comparable_distance_type, element_type>
        >::type sorted_elements_type;

        sorted_elements_type sorted_elements;
        // If constructor is used instead of resize() MS implementation leaks here
        sorted_elements.reserve(elements_count);                                                         // MAY THROW, STRONG (V, E: alloc, copy)

        for ( typename elements_type::const_iterator it = elements.begin() ;
              it != elements.end() ; ++it )
        {
            point_type element_center;
            geometry::centroid( rtree::element_indexable(*it, translator), element_center);
            sorted_elements.push_back(std::make_pair(
                geometry::comparable_distance(node_center, element_center),
                *it));                                                                                // MAY THROW (V, E: copy)
        }

        // sort elements by distances from center
        std::partial_sort(
            sorted_elements.begin(),
            sorted_elements.begin() + reinserted_elements_count,
            sorted_elements.end(),
            distances_dsc<comparable_distance_type, element_type>);                                                // MAY THROW, BASIC (V, E: copy)

        // copy elements which will be reinserted
        result_elements.clear();
        result_elements.reserve(reinserted_elements_count);                                             // MAY THROW, STRONG (V, E: alloc, copy)
        for ( typename sorted_elements_type::const_iterator it = sorted_elements.begin() ;
              it != sorted_elements.begin() + reinserted_elements_count ; ++it )
        {
            result_elements.push_back(it->second);                                                      // MAY THROW (V, E: copy)
        }

        BOOST_TRY
        {
            // copy remaining elements to the current node
            elements.clear();
            elements.reserve(elements_count - reinserted_elements_count);                                // SHOULDN'T THROW (new_size <= old size)
            for ( typename sorted_elements_type::const_iterator it = sorted_elements.begin() + reinserted_elements_count;
                  it != sorted_elements.end() ; ++it )
            {
                elements.push_back(it->second);                                                         // MAY THROW (V, E: copy)
            }
        }
        BOOST_CATCH(...)
        {
            elements.clear();

            for ( typename sorted_elements_type::iterator it = sorted_elements.begin() ;
                  it != sorted_elements.end() ; ++it )
            {
                destroy_element<Value, Options, Translator, Box, Allocators>::apply(it->second, allocators);
            }

            BOOST_RETHROW                                                                                // RETHROW
        }
        BOOST_CATCH_END

        ::boost::ignore_unused_variable_warning(parameters);
    }

private:
    template <typename Distance, typename El>
    static inline bool distances_asc(
        std::pair<Distance, El> const& d1,
        std::pair<Distance, El> const& d2)
    {
        return d1.first < d2.first;
    }

    template <typename Distance, typename El>
    static inline bool distances_dsc(
        std::pair<Distance, El> const& d1,
        std::pair<Distance, El> const& d2)
    {
        return d1.first > d2.first;
    }
};

template <size_t InsertIndex, typename Element, typename Value, typename Options, typename Box, typename Allocators>
struct level_insert_elements_type
{
    typedef typename rtree::elements_type<
        typename rtree::internal_node<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type
    >::type type;
};

template <typename Value, typename Options, typename Box, typename Allocators>
struct level_insert_elements_type<0, Value, Value, Options, Box, Allocators>
{
    typedef typename rtree::elements_type<
        typename rtree::leaf<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag>::type
    >::type type;
};

template <size_t InsertIndex, typename Element, typename Value, typename Options, typename Translator, typename Box, typename Allocators>
struct level_insert_base
    : public detail::insert<Element, Value, Options, Translator, Box, Allocators>
{
    typedef detail::insert<Element, Value, Options, Translator, Box, Allocators> base;
    typedef typename base::node node;
    typedef typename base::internal_node internal_node;
    typedef typename base::leaf leaf;

    typedef typename level_insert_elements_type<InsertIndex, Element, Value, Options, Box, Allocators>::type elements_type;
    typedef typename index::detail::rtree::container_from_elements_type<
        elements_type,
        typename elements_type::value_type
    >::type result_elements_type;

    typedef typename Options::parameters_type parameters_type;

    typedef typename Allocators::node_pointer node_pointer;
    typedef typename Allocators::size_type size_type;

    inline level_insert_base(node_pointer & root,
                             size_type & leafs_level,
                             Element const& element,
                             parameters_type const& parameters,
                             Translator const& translator,
                             Allocators & allocators,
                             size_type relative_level)
        : base(root, leafs_level, element, parameters, translator, allocators, relative_level)
        , result_relative_level(0)
    {}

    template <typename Node>
    inline void handle_possible_reinsert_or_split_of_root(Node &n)
    {
        BOOST_GEOMETRY_INDEX_ASSERT(result_elements.empty(), "reinsert should be handled only once for level");

        result_relative_level = base::m_leafs_level - base::m_traverse_data.current_level;

        // overflow
        if ( base::m_parameters.get_max_elements() < rtree::elements(n).size() )
        {
            // node isn't root node
            if ( !base::m_traverse_data.current_is_root() )
            {
                // NOTE: exception-safety
                // After an exception result_elements may contain garbage, don't use it
                rstar::remove_elements_to_reinsert<Value, Options, Translator, Box, Allocators>::apply(
                    result_elements, n,
                    base::m_traverse_data.parent, base::m_traverse_data.current_child_index,
                    base::m_parameters, base::m_translator, base::m_allocators);                            // MAY THROW, BASIC (V, E: alloc, copy)
            }
            // node is root node
            else
            {
                BOOST_GEOMETRY_INDEX_ASSERT(&n == &rtree::get<Node>(*base::m_root_node), "node should be the root node");
                base::split(n);                                                                             // MAY THROW (V, E: alloc, copy, N: alloc)
            }
        }
    }

    template <typename Node>
    inline void handle_possible_split(Node &n) const
    {
        // overflow
        if ( base::m_parameters.get_max_elements() < rtree::elements(n).size() )
        {
            base::split(n);                                                                                // MAY THROW (V, E: alloc, copy, N: alloc)
        }
    }

    template <typename Node>
    inline void recalculate_aabb_if_necessary(Node &n) const
    {
        if ( !result_elements.empty() && !base::m_traverse_data.current_is_root() )
        {
            // calulate node's new box
            base::m_traverse_data.current_element().first =
                elements_box<Box>(rtree::elements(n).begin(), rtree::elements(n).end(), base::m_translator);
        }
    }

    size_type result_relative_level;
    result_elements_type result_elements;
};

template <size_t InsertIndex, typename Element, typename Value, typename Options, typename Translator, typename Box, typename Allocators>
struct level_insert
    : public level_insert_base<InsertIndex, Element, Value, Options, Translator, Box, Allocators>
{
    typedef level_insert_base<InsertIndex, Element, Value, Options, Translator, Box, Allocators> base;
    typedef typename base::node node;
    typedef typename base::internal_node internal_node;
    typedef typename base::leaf leaf;

    typedef typename Options::parameters_type parameters_type;

    typedef typename Allocators::node_pointer node_pointer;
    typedef typename Allocators::size_type size_type;

    inline level_insert(node_pointer & root,
                        size_type & leafs_level,
                        Element const& element,
                        parameters_type const& parameters,
                        Translator const& translator,
                        Allocators & allocators,
                        size_type relative_level)
        : base(root, leafs_level, element, parameters, translator, allocators, relative_level)
    {}

    inline void operator()(internal_node & n)
    {
        BOOST_GEOMETRY_INDEX_ASSERT(base::m_traverse_data.current_level < base::m_leafs_level, "unexpected level");

        if ( base::m_traverse_data.current_level < base::m_level )
        {
            // next traversing step
            base::traverse(*this, n);                                                                       // MAY THROW (E: alloc, copy, N: alloc)

            // further insert
            if ( 0 < InsertIndex )
            {
                BOOST_GEOMETRY_INDEX_ASSERT(0 < base::m_level, "illegal level value, level shouldn't be the root level for 0 < InsertIndex");

                if ( base::m_traverse_data.current_level == base::m_level - 1 )
                {
                    base::handle_possible_reinsert_or_split_of_root(n);                                     // MAY THROW (E: alloc, copy, N: alloc)
                }
            }
        }
        else
        {
            BOOST_GEOMETRY_INDEX_ASSERT(base::m_level == base::m_traverse_data.current_level, "unexpected level");

            BOOST_TRY
            {
                // push new child node
                rtree::elements(n).push_back(base::m_element);                                              // MAY THROW, STRONG (E: alloc, copy)
            }
            BOOST_CATCH(...)
            {
                // NOTE: exception-safety
                // if the insert fails above, the element won't be stored in the tree, so delete it

                rtree::visitors::destroy<Value, Options, Translator, Box, Allocators> del_v(base::m_element.second, base::m_allocators);
                rtree::apply_visitor(del_v, *base::m_element.second);

                BOOST_RETHROW                                                                                // RETHROW
            }
            BOOST_CATCH_END

            // first insert
            if ( 0 == InsertIndex )
            {
                base::handle_possible_reinsert_or_split_of_root(n);                                         // MAY THROW (E: alloc, copy, N: alloc)
            }
            // not the first insert
            else
            {
                base::handle_possible_split(n);                                                             // MAY THROW (E: alloc, N: alloc)
            }
        }

        base::recalculate_aabb_if_necessary(n);
    }

    inline void operator()(leaf &)
    {
        BOOST_GEOMETRY_INDEX_ASSERT(false, "this visitor can't be used for a leaf");
    }
};

template <size_t InsertIndex, typename Value, typename Options, typename Translator, typename Box, typename Allocators>
struct level_insert<InsertIndex, Value, Value, Options, Translator, Box, Allocators>
    : public level_insert_base<InsertIndex, Value, Value, Options, Translator, Box, Allocators>
{
    typedef level_insert_base<InsertIndex, Value, Value, Options, Translator, Box, Allocators> base;
    typedef typename base::node node;
    typedef typename base::internal_node internal_node;
    typedef typename base::leaf leaf;

    typedef typename Options::parameters_type parameters_type;

    typedef typename Allocators::node_pointer node_pointer;
    typedef typename Allocators::size_type size_type;

    inline level_insert(node_pointer & root,
                        size_type & leafs_level,
                        Value const& v,
                        parameters_type const& parameters,
                        Translator const& translator,
                        Allocators & allocators,
                        size_type relative_level)
        : base(root, leafs_level, v, parameters, translator, allocators, relative_level)
    {}

    inline void operator()(internal_node & n)
    {
        BOOST_GEOMETRY_INDEX_ASSERT(base::m_traverse_data.current_level < base::m_leafs_level, "unexpected level");
        BOOST_GEOMETRY_INDEX_ASSERT(base::m_traverse_data.current_level < base::m_level, "unexpected level");

        // next traversing step
        base::traverse(*this, n);                                                                       // MAY THROW (V, E: alloc, copy, N: alloc)

        BOOST_GEOMETRY_INDEX_ASSERT(0 < base::m_level, "illegal level value, level shouldn't be the root level for 0 < InsertIndex");

        if ( base::m_traverse_data.current_level == base::m_level - 1 )
        {
            base::handle_possible_reinsert_or_split_of_root(n);                                         // MAY THROW (E: alloc, copy, N: alloc)
        }

        base::recalculate_aabb_if_necessary(n);
    }

    inline void operator()(leaf & n)
    {
        BOOST_GEOMETRY_INDEX_ASSERT(base::m_traverse_data.current_level == base::m_leafs_level,
                                    "unexpected level");
        BOOST_GEOMETRY_INDEX_ASSERT(base::m_level == base::m_traverse_data.current_level ||
                                    base::m_level == (std::numeric_limits<size_t>::max)(),
                                    "unexpected level");

        rtree::elements(n).push_back(base::m_element);                                                  // MAY THROW, STRONG (V: alloc, copy)

        base::handle_possible_split(n);                                                                 // MAY THROW (V: alloc, copy, N: alloc)
    }
};

template <typename Value, typename Options, typename Translator, typename Box, typename Allocators>
struct level_insert<0, Value, Value, Options, Translator, Box, Allocators>
    : public level_insert_base<0, Value, Value, Options, Translator, Box, Allocators>
{
    typedef level_insert_base<0, Value, Value, Options, Translator, Box, Allocators> base;
    typedef typename base::node node;
    typedef typename base::internal_node internal_node;
    typedef typename base::leaf leaf;

    typedef typename Options::parameters_type parameters_type;

    typedef typename Allocators::node_pointer node_pointer;
    typedef typename Allocators::size_type size_type;

    inline level_insert(node_pointer & root,
                        size_type & leafs_level,
                        Value const& v,
                        parameters_type const& parameters,
                        Translator const& translator,
                        Allocators & allocators,
                        size_type relative_level)
        : base(root, leafs_level, v, parameters, translator, allocators, relative_level)
    {}

    inline void operator()(internal_node & n)
    {
        BOOST_GEOMETRY_INDEX_ASSERT(base::m_traverse_data.current_level < base::m_leafs_level,
                                    "unexpected level");
        BOOST_GEOMETRY_INDEX_ASSERT(base::m_traverse_data.current_level < base::m_level,
                                    "unexpected level");

        // next traversing step
        base::traverse(*this, n);                                                                       // MAY THROW (V: alloc, copy, N: alloc)

        base::recalculate_aabb_if_necessary(n);
    }

    inline void operator()(leaf & n)
    {
        BOOST_GEOMETRY_INDEX_ASSERT(base::m_traverse_data.current_level == base::m_leafs_level,
                                    "unexpected level");
        BOOST_GEOMETRY_INDEX_ASSERT(base::m_level == base::m_traverse_data.current_level ||
                                    base::m_level == (std::numeric_limits<size_t>::max)(),
                                    "unexpected level");

        rtree::elements(n).push_back(base::m_element);                                                  // MAY THROW, STRONG (V: alloc, copy)

        base::handle_possible_reinsert_or_split_of_root(n);                                             // MAY THROW (V: alloc, copy, N: alloc)

        base::recalculate_aabb_if_necessary(n);
    }
};

} // namespace rstar

// R*-tree insert visitor
// After passing the Element to insert visitor the Element is managed by the tree
// I.e. one should not delete the node passed to the insert visitor after exception is thrown
// because this visitor may delete it
template <typename Element, typename Value, typename Options, typename Translator, typename Box, typename Allocators>
class insert<Element, Value, Options, Translator, Box, Allocators, insert_reinsert_tag>
    : public rtree::visitor<Value, typename Options::parameters_type, Box, Allocators, typename Options::node_tag, false>::type
{
    typedef typename Options::parameters_type parameters_type;

    typedef typename rtree::node<Value, parameters_type, Box, Allocators, typename Options::node_tag>::type node;
    typedef typename rtree::internal_node<Value, parameters_type, Box, Allocators, typename Options::node_tag>::type internal_node;
    typedef typename rtree::leaf<Value, parameters_type, Box, Allocators, typename Options::node_tag>::type leaf;

    typedef typename Allocators::node_pointer node_pointer;
    typedef typename Allocators::size_type size_type;

public:
    inline insert(node_pointer & root,
                  size_type & leafs_level,
                  Element const& element,
                  parameters_type const& parameters,
                  Translator const& translator,
                  Allocators & allocators,
                  size_type relative_level = 0)
        : m_root(root), m_leafs_level(leafs_level), m_element(element)
        , m_parameters(parameters), m_translator(translator)
        , m_relative_level(relative_level), m_allocators(allocators)
    {}

    inline void operator()(internal_node & n)
    {
        boost::ignore_unused(n);
        BOOST_GEOMETRY_INDEX_ASSERT(&n == &rtree::get<internal_node>(*m_root), "current node should be the root");

        // Distinguish between situation when reinserts are required and use adequate visitor, otherwise use default one
        if ( m_parameters.get_reinserted_elements() > 0 )
        {
            rstar::level_insert<0, Element, Value, Options, Translator, Box, Allocators> lins_v(
                m_root, m_leafs_level, m_element, m_parameters, m_translator, m_allocators, m_relative_level);

            rtree::apply_visitor(lins_v, *m_root);                                                              // MAY THROW (V, E: alloc, copy, N: alloc)

            if ( !lins_v.result_elements.empty() )
            {
                recursive_reinsert(lins_v.result_elements, lins_v.result_relative_level);                       // MAY THROW (V, E: alloc, copy, N: alloc)
            }
        }
        else
        {
            visitors::insert<Element, Value, Options, Translator, Box, Allocators, insert_default_tag> ins_v(
                m_root, m_leafs_level, m_element, m_parameters, m_translator, m_allocators, m_relative_level);

            rtree::apply_visitor(ins_v, *m_root);
        }
    }

    inline void operator()(leaf & n)
    {
        boost::ignore_unused(n);
        BOOST_GEOMETRY_INDEX_ASSERT(&n == &rtree::get<leaf>(*m_root), "current node should be the root");

        // Distinguish between situation when reinserts are required and use adequate visitor, otherwise use default one
        if ( m_parameters.get_reinserted_elements() > 0 )
        {
            rstar::level_insert<0, Element, Value, Options, Translator, Box, Allocators> lins_v(
                m_root, m_leafs_level, m_element, m_parameters, m_translator, m_allocators, m_relative_level);

            rtree::apply_visitor(lins_v, *m_root);                                                              // MAY THROW (V, E: alloc, copy, N: alloc)

            // we're in the root, so root should be split and there should be no elements to reinsert
            BOOST_GEOMETRY_INDEX_ASSERT(lins_v.result_elements.empty(), "unexpected state");
        }
        else
        {
            visitors::insert<Element, Value, Options, Translator, Box, Allocators, insert_default_tag> ins_v(
                m_root, m_leafs_level, m_element, m_parameters, m_translator, m_allocators, m_relative_level);

            rtree::apply_visitor(ins_v, *m_root);
        }
    }

private:
    template <typename Elements>
    inline void recursive_reinsert(Elements & elements, size_t relative_level)
    {
        typedef typename Elements::value_type element_type;

        // reinsert children starting from the minimum distance
        typename Elements::reverse_iterator it = elements.rbegin();
        for ( ; it != elements.rend() ; ++it)
        {
            rstar::level_insert<1, element_type, Value, Options, Translator, Box, Allocators> lins_v(
                m_root, m_leafs_level, *it, m_parameters, m_translator, m_allocators, relative_level);

            BOOST_TRY
            {
                rtree::apply_visitor(lins_v, *m_root);                                                          // MAY THROW (V, E: alloc, copy, N: alloc)
            }
            BOOST_CATCH(...)
            {
                ++it;
                for ( ; it != elements.rend() ; ++it)
                    rtree::destroy_element<Value, Options, Translator, Box, Allocators>::apply(*it, m_allocators);
                BOOST_RETHROW                                                                                // RETHROW
            }
            BOOST_CATCH_END

            BOOST_GEOMETRY_INDEX_ASSERT(relative_level + 1 == lins_v.result_relative_level, "unexpected level");

            // non-root relative level
            if ( lins_v.result_relative_level < m_leafs_level && !lins_v.result_elements.empty())
            {
                recursive_reinsert(lins_v.result_elements, lins_v.result_relative_level);                   // MAY THROW (V, E: alloc, copy, N: alloc)
            }
        }
    }

    node_pointer & m_root;
    size_type & m_leafs_level;
    Element const& m_element;

    parameters_type const& m_parameters;
    Translator const& m_translator;

    size_type m_relative_level;

    Allocators & m_allocators;
};

}}} // namespace detail::rtree::visitors

}}} // namespace boost::geometry::index

#endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_RSTAR_INSERT_HPP

max_stars_repo_name: Abce/boost