<commit_before>#ifndef VIENNAGRID_STORAGE_INSERTER_HPP
#define VIENNAGRID_STORAGE_INSERTER_HPP


//#include "viennagrid/storage/reference.hpp"
#include "viennagrid/storage/container_collection.hpp"
#include "viennagrid/storage/container_collection_element.hpp"

namespace viennagrid
{
    namespace storage
    {
        
        template<typename container_collection_type>
        class inserter_base_t
        {
        public:
            inserter_base_t(container_collection_type & _collection) : collection(_collection) {}
            
        protected:
            container_collection_type & collection;
        };

        

        template<typename container_collection_type, typename id_generator_type_>
        class physical_inserter_t
        {
        public:
            typedef container_collection_type physical_container_collection_type;
            typedef id_generator_type_ id_generator_type;
            
            physical_inserter_t() : collection(0) {}
            physical_inserter_t(container_collection_type & _collection, id_generator_type id_generator_) : collection(&_collection), id_generator(id_generator_) {}
            
            void set_container_collection(container_collection_type & _collection) { collection = &_collection; }
            
            template<bool generate_id, typename value_type, typename inserter_type>
            std::pair<
                typename viennagrid::storage::result_of::container_of<container_collection_type, value_type>::type::hook_type,
                bool
            >
                    physical_insert( value_type element, inserter_type & inserter )
            {
                typedef typename viennagrid::storage::result_of::container_of<container_collection_type, value_type>::type::iterator iterator;
                typedef typename viennagrid::storage::result_of::container_of<container_collection_type, value_type>::type container_type;
                typedef typename viennagrid::storage::result_of::container_of<container_collection_type, value_type>::type::hook_tag hook_tag;
                typedef typename viennagrid::storage::result_of::container_of<container_collection_type, value_type>::type::hook_type hook_type;
                
                
                container_type & container = viennagrid::storage::collection::get< value_type >( *collection );
                
                if ( generate_id && !container.is_present( element ) )
                    viennagrid::storage::id::set_id(element, id_generator( viennameta::tag<value_type>() ) );
                
                std::pair<hook_type, bool> ret = container.insert( element );
                
                //container.dereference_hook(ret.first).set_container(collection);

                viennagrid::storage::container_collection_element::insert_callback(
                    container.dereference_hook(ret.first),
                    ret.second,
                    inserter);
                
                //viennagrid::storage::container_collection_element::insert_callback(*ret.first, ret.second, inserter);
                
                inserter.hook_insert( ret.first, viennameta::tag<value_type>() );
                
                return ret;
            }
            
            template<typename hook_type, typename value_type>
            void hook_insert( hook_type ref, viennameta::tag<value_type> )
            {}
            
            template<typename value_type>
            std::pair<
                typename viennagrid::storage::result_of::container_of<container_collection_type, value_type>::type::hook_type,
                bool
            >
                operator()( const value_type & element )
            {
                return physical_insert<true>( element, *this );
            }
            
            template<typename value_type>
            std::pair<
                typename viennagrid::storage::result_of::container_of<container_collection_type, value_type>::type::hook_type,
                bool
            >
                insert_noid( const value_type & element )
            {
                return physical_insert<true>( element, *this );
            }
            
            container_collection_type & get_physical_container_collection() { return *collection; }
            id_generator_type & get_id_generator() { return id_generator; }
            
        private:
            container_collection_type * collection;
            id_generator_type id_generator;
        };
        
        
        
        
        
        
        
        
        template<typename view_collection_type, typename dependend_inserter_type>
        class recursive_inserter_t
        {
        public:            
            recursive_inserter_t() : view_collection(0), dependend_inserter(0) {}
            recursive_inserter_t(view_collection_type & collection_, dependend_inserter_type & dependend_inserter_) :
               view_collection(&collection_), dependend_inserter(&dependend_inserter_) {}
            
            void set_container_collection(view_collection_type & _collection) { view_collection = &_collection; }
            
            
            template<typename hook_type, typename value_type><commit_msg>fixed bug with no-id insert<commit_after>#ifndef VIENNAGRID_STORAGE_INSERTER_HPP
#define VIENNAGRID_STORAGE_INSERTER_HPP


//#include "viennagrid/storage/reference.hpp"
#include "viennagrid/storage/container_collection.hpp"
#include "viennagrid/storage/container_collection_element.hpp"

namespace viennagrid
{
    namespace storage
    {
        
        template<typename container_collection_type>
        class inserter_base_t
        {
        public:
            inserter_base_t(container_collection_type & _collection) : collection(_collection) {}
            
        protected:
            container_collection_type & collection;
        };

        

        template<typename container_collection_type, typename id_generator_type_>
        class physical_inserter_t
        {
        public:
            typedef container_collection_type physical_container_collection_type;
            typedef id_generator_type_ id_generator_type;
            
            physical_inserter_t() : collection(0) {}
            physical_inserter_t(container_collection_type & _collection, id_generator_type id_generator_) : collection(&_collection), id_generator(id_generator_) {}
            
            void set_container_collection(container_collection_type & _collection) { collection = &_collection; }
            
            template<bool generate_id, typename value_type, typename inserter_type>
            std::pair<
                typename viennagrid::storage::result_of::container_of<container_collection_type, value_type>::type::hook_type,
                bool
            >
                    physical_insert( value_type element, inserter_type & inserter )
            {
                typedef typename viennagrid::storage::result_of::container_of<container_collection_type, value_type>::type::iterator iterator;
                typedef typename viennagrid::storage::result_of::container_of<container_collection_type, value_type>::type container_type;
                typedef typename viennagrid::storage::result_of::container_of<container_collection_type, value_type>::type::hook_tag hook_tag;
                typedef typename viennagrid::storage::result_of::container_of<container_collection_type, value_type>::type::hook_type hook_type;
                
                
                container_type & container = viennagrid::storage::collection::get< value_type >( *collection );
                
                if ( generate_id && !container.is_present( element ) )
                    viennagrid::storage::id::set_id(element, id_generator( viennameta::tag<value_type>() ) );
                
                std::pair<hook_type, bool> ret = container.insert( element );
                
                //container.dereference_hook(ret.first).set_container(collection);

                viennagrid::storage::container_collection_element::insert_callback(
                    container.dereference_hook(ret.first),
                    ret.second,
                    inserter);
                
                //viennagrid::storage::container_collection_element::insert_callback(*ret.first, ret.second, inserter);
                
                inserter.hook_insert( ret.first, viennameta::tag<value_type>() );
                
                return ret;
            }
            
            template<typename hook_type, typename value_type>
            void hook_insert( hook_type ref, viennameta::tag<value_type> )
            {}
            
            template<typename value_type>
            std::pair<
                typename viennagrid::storage::result_of::container_of<container_collection_type, value_type>::type::hook_type,
                bool
            >
                operator()( const value_type & element )
            {
                return physical_insert<true>( element, *this );
            }
            
            template<typename value_type>
            std::pair<
                typename viennagrid::storage::result_of::container_of<container_collection_type, value_type>::type::hook_type,
                bool
            >
                insert_noid( const value_type & element )
            {
                return physical_insert<false>( element, *this );
            }
            
            container_collection_type & get_physical_container_collection() { return *collection; }
            id_generator_type & get_id_generator() { return id_generator; }
            
        private:
            container_collection_type * collection;
            id_generator_type id_generator;
        };
        
        
        
        
        
        
        
        
        template<typename view_collection_type, typename dependend_inserter_type>
        class recursive_inserter_t
        {
        public:            
            recursive_inserter_t() : view_collection(0), dependend_inserter(0) {}
            recursive_inserter_t(view_collection_type & collection_, dependend_inserter_type & dependend_inserter_) :
               view_collection(&collection_), dependend_inserter(&dependend_inserter_) {}
            
            void set_container_collection(view_collection_type & _collection) { view_collection = &_collection; }
            
            
            template<typename hook_type, typename value_type>
{'fraction_non_alphanumeric': 0.07651565307859642, 'fraction_numerical': 0.0005674832119549796, 'mean_word_length': 2.1265523358959197, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '796050', 'n_tokens_mistral': 2766, 'n_tokens_neox': 2633, 'n_words': 391}