<commit_before>// @(#)root/reflex:$Name:  $:$Id: CollectionProxy.h,v 1.11 2006/03/06 12:51:46 roiser Exp $
// Author: <NAME> 2004

// Copyright CERN, CH-1211 Geneva 23, 2004-2006, All rights reserved.
//
// Permission to use, copy, modify, and distribute this software for any
// purpose is hereby granted without fee, provided that this copyright and
// permissions notice appear in all copies and derivatives.
//
// This software is provided "as is" without express or implied warranty.

#ifndef ROOT_Reflex_CollectionProxy
#define ROOT_Reflex_CollectionProxy 1 1

#include <cstddef>

// Forward declarations
namespace std {
   template <class T, class A>  class deque;
   template <class T, class A>  class vector;
   template <class T, class A>  class list;
   template <class T, class A>  class queue;
   template <class T, class A>  class stack;
   template <class K, class T, class A>  class set;
   template <class K, class T, class A>  class multiset;
   template <class K, class T, class R, class A>  class map;
   template <class K, class T, class R, class A>  class multimap;
   template <class T> class allocator;
}
// Hash map forward declarations
#if defined(__GNUC__)
namespace __gnu_cxx {  // GNU GCC
   template <class T, class F, class E, class A>  class hash_set;
   template <class T, class F, class E, class A>  class hash_multiset;
   template <class K, class T, class F, class E, class A>  class hash_map;
   template <class K, class T, class F, class E, class A>  class hash_multimap;
}
#elif  defined(_WIN32)
namespace stdext {     // Visual C++
   template <class K, class T, class A>  class hash_set;
   template <class K, class T, class A>  class hash_multiset;
   template <class K, class T, class R, class A>  class hash_map;
   template <class K, class T, class R, class A>  class hash_multimap;
}
#endif

#if defined(_WIN32) 
#if _MSC_VER<1300
#define RFLX_TYPENAME
#else
#define RFLX_TYPENAME typename
#endif
#else
#define RFLX_TYPENAME typename
#endif

namespace ROOT {
   namespace Reflex  {

#ifndef __CINT__
      template <typename T> struct Environ  {
         typedef T           Iter_t;
         char                buff[64];
         size_t              idx;
         size_t              size;
         void*               object;
         void*               start;
         void*               temp;
         bool                delete_temp;
         int                 refSize;
         size_t              space;
         T& iter() { return *(T*)buff; }
      };
#else 
      template <typename T> struct Environ;
#endif

      template <typename T> struct Address {
         static void* addressGet(T ref) {
            return (void*)&ref;
         }
      };

      template <class T> struct CollType 
#ifdef _KCC  // KAI compiler
         : public Address<RFLX_TYPENAME T::value_type&> 
#else 
         : public Address<RFLX_TYPENAME T::const_reference> 
#endif 
      {
         typedef T                               Cont_t;
         typedef typename T::iterator            Iter_t;
         typedef typename T::value_type          Value_t;
         typedef ROOT::Reflex::Environ<Iter_t>   Env_t;
         typedef Env_t                          *PEnv_t;
         typedef Cont_t                         *PCont_t;
         typedef Value_t                        *PValue_t;

         static inline PCont_t object(void* ptr)   {
            return PCont_t(PEnv_t(ptr)->object);
         }
         static void* size(void* env)  {
            PEnv_t  e = PEnv_t(env);
            e->size   = PCont_t(e->object)->size();
            return &e->size;
         }
         static void* clear(void* env)  {
            object(env)->clear();
            return 0;
         }
         static void* first(void* env)  {
            PEnv_t  e = PEnv_t(env);
            PCont_t c = PCont_t(e->object);
            // Assume iterators do not need destruction
            ::new(e->buff) Iter_t(c->begin()); 
            e->size  = c->size();
            if ( 0 == e->size ) return e->start = 0;
#ifdef _KCC  // KAI compiler
            RFLX_TYPENAME T::value_type& ref = *(e->iter());
#else
            RFLX_TYPENAME T::const_reference ref = *(e->iter());
#endif
            return e->start = addressGet(ref);
         }
         static void* next(void* env)  {
            PEnv_t  e = PEnv_t(env);
            PCont_t c = PCont_t(e->object);
            for (; e->idx > 0 && e->iter() != c->end(); ++(e->iter()), --e->idx );
            // TODO: Need to find something for going backwards....
            if ( e->iter() == c->end() ) return 0;
#ifdef _KCC  // KAI compiler
            RFLX_TYPENAME T::value_type& ref = *(e->iter());
#else
            RFLX_TYPENAME T::const_reference ref = *(e->iter());
#endif
            return addressGet(ref);
         }
         static void* construct(void* env)  {
            PEnv_t  e = PEnv_t(env);
            PValue_t m = PValue_t(e->start);
            for (size_t i=0; i<e->size; ++i, ++m)  
               ::new(m) Value_t();
            return 0;
         }
         static void* collect(void* env)  {
            PEnv_t   e = PEnv_t(env);
            PCont_t  c = PCont_t(e->object);
            PValue_t m = PValue_t(e->start);
            for (Iter_t i=c->begin(); i != c->end(); ++i, ++m )
               ::new(m) Value_t(*i);
            return 0;
         }
         static void* destruct(void* env)  {
            PEnv_t   e = PEnv_t(env);
            PValue_t m = PValue_t(e->start);
            for (size_t i=0; i < e->size; ++i, ++m )
               m->~Value_t();
            return 0;
         }
      };

      /** @class TCollectionProxy::Map TCollectionProxy.h TCollectionProxy.h 
       *
       * Small helper to encapsulate all necessary data accesses for 
       * containers like vector, list, deque
       *
       * @author  M.Frank
       * @version 1.0
       * @date    10/10/2004
       */
      template <class T> struct Pushback : public CollType<T> {
         typedef T                      Cont_t;
         typedef typename T::iterator   Iter_t;
         typedef typename T::value_type Value_t;
         typedef Environ<Iter_t>        Env_t;
         typedef Env_t                 *PEnv_t;
         typedef Cont_t                *PCont_t;
         typedef Value_t               *PValue_t;
         static void* resize(void* env)  {
            PEnv_t  e = PEnv_t(env);
            PCont_t c = PCont_t(e->object);
            c->resize(e->size);
            e->idx = 0;
            return e->start = addressGet(*c->begin());
         }
         static void* feed(void* env)  {
            PEnv_t   e = PEnv_t(env);
            PCont_t  c = PCont_t(e->object);
            PValue_t m = PValue_t(e->start);
            for (size_t i=0; i<e->size; ++i, ++m)
               c->push_back(*m);
            return 0;
         }
         static int value_offset()  {
            return 0;
         }
      };

      /** @class TCollectionProxy::Map TCollectionProxy.h TCollectionProxy.h 
       *
       * Small helper to encapsulate all necessary data accesses for 
       * containers like set, multiset etc.
       *
       * @author  M.Frank
       * @version 1.0
       * @date    10/10/2004
       */
      template <class T> struct Insert : public CollType<T> {
         typedef T                      Cont_t;
         typedef typename T::iterator   Iter_t;
         typedef typename T::value_type Value_t;
         typedef Environ<Iter_t>        Env_t;
         typedef Env_t                 *PEnv_t;
         typedef Cont_t                *PCont_t;
         typedef Value_t               *PValue_t;
         static void* feed(void* env)  {
            PEnv_t   e = PEnv_t(env);
            PCont_t  c = PCont_t(e->object);
            PValue_t m = PValue_t(e->start);
            for (size_t i=0; i<e->size; ++i, ++m)
               c->insert(*m);
            return 0;
         }
         static void* resize(void* /* env */ )  {
            return 0;
         }
         static int value_offset()  {
            return 0;
         }
      };

      /** @class TCollectionProxy::Map TCollectionProxy.h TCollectionProxy.h 
       *
       * Small helper to encapsulate all necessary data accesses for 
       * containers like Set, multiset etc.
       *
       * @author  M.Frank
       * @version 1.0
       * @date    10/10/2004
       */
      template <class T> struct MapInsert : public CollType<T> {
         typedef T                      Cont_t;
         typedef typename T::iterator   Iter_t;
         typedef typename T::value_type Value_t;
         typedef Environ<Iter_t>        Env_t;
         typedef Env_t                 *PEnv_t;
         typedef Cont_t                *PCont_t;
         typedef Value_t               *PValue_t;
         static void* feed(void* env)  {
            PEnv_t   e = PEnv_t(env);
            PCont_t  c = PCont_t(e->object);
            PValue_t m = PValue_t(e->start);
            for (size_t i=0; i<e->size; ++i, ++m)
               c->insert(*m);
            return 0;
         }
         static void* resize(void* /* env */ )  {
            return 0;
         }
         static int value_offset()  {
            return ((char*)&((PValue_t(0x1000))->second)) - ((char*)PValue_t(0x1000));
         }
      };

      // Need specialization for boolean references due to stupid STL vector<bool>
      template<> inline void* ROOT::Reflex::Address<std::vector<bool,std::allocator<bool> >::const_reference>::addressGet(std::vector<bool,std::allocator<bool> >::const_reference ) {
         return 0;
      }
<commit_msg>removing not needed macros, simplifying code<commit_after>// @(#)root/reflex:$Name:  $:$Id: CollectionProxy.h,v 1.12 2006/03/13 15:49:50 roiser Exp $
// Author: <NAME> 2004

// Copyright CERN, CH-1211 Geneva 23, 2004-2006, All rights reserved.
//
// Permission to use, copy, modify, and distribute this software for any
// purpose is hereby granted without fee, provided that this copyright and
// permissions notice appear in all copies and derivatives.
//
// This software is provided "as is" without express or implied warranty.

#ifndef ROOT_Reflex_CollectionProxy
#define ROOT_Reflex_CollectionProxy 1 1

#include <cstddef>

// Forward declarations
namespace std {
   template <class T, class A>  class deque;
   template <class T, class A>  class vector;
   template <class T, class A>  class list;
   template <class T, class A>  class queue;
   template <class T, class A>  class stack;
   template <class K, class T, class A>  class set;
   template <class K, class T, class A>  class multiset;
   template <class K, class T, class R, class A>  class map;
   template <class K, class T, class R, class A>  class multimap;
   template <class T> class allocator;
}
// Hash map forward declarations
#if defined(__GNUC__)
namespace __gnu_cxx {  // GNU GCC
   template <class T, class F, class E, class A>  class hash_set;
   template <class T, class F, class E, class A>  class hash_multiset;
   template <class K, class T, class F, class E, class A>  class hash_map;
   template <class K, class T, class F, class E, class A>  class hash_multimap;
}
#elif  defined(_WIN32)
namespace stdext {     // Visual C++
   template <class K, class T, class A>  class hash_set;
   template <class K, class T, class A>  class hash_multiset;
   template <class K, class T, class R, class A>  class hash_map;
   template <class K, class T, class R, class A>  class hash_multimap;
}
#endif

namespace ROOT {
   namespace Reflex  {

#ifndef __CINT__
      template <typename T> struct Environ  {
         typedef T           Iter_t;
         char                buff[64];
         size_t              idx;
         size_t              size;
         void*               object;
         void*               start;
         void*               temp;
         bool                delete_temp;
         int                 refSize;
         size_t              space;
         T& iter() { return *(T*)buff; }
      };
#else 
      template <typename T> struct Environ;
#endif

      template <typename T> struct Address {
         static void* address(T ref) {
            return (void*)&ref;
         }
      };

      template <class T> struct CollType 
#ifdef _KCC  // KAI compiler
         : public Address<typename T::value_type&> 
#else 
         : public Address<typename T::const_reference> 
#endif 
      {
         typedef T                               Cont_t;
         typedef typename T::iterator            Iter_t;
         typedef typename T::value_type          Value_t;
         typedef ROOT::Reflex::Environ<Iter_t>   Env_t;
         typedef Env_t                          *PEnv_t;
         typedef Cont_t                         *PCont_t;
         typedef Value_t                        *PValue_t;

         static inline PCont_t object(void* ptr)   {
            return PCont_t(PEnv_t(ptr)->object);
         }
         static void* size(void* env)  {
            PEnv_t  e = PEnv_t(env);
            e->size   = PCont_t(e->object)->size();
            return &e->size;
         }
         static void* clear(void* env)  {
            object(env)->clear();
            return 0;
         }
         static void* first(void* env)  {
            PEnv_t  e = PEnv_t(env);
            PCont_t c = PCont_t(e->object);
            // Assume iterators do not need destruction
            ::new(e->buff) Iter_t(c->begin()); 
            e->size  = c->size();
            if ( 0 == e->size ) return e->start = 0;
#ifdef _KCC  // KAI compiler
            typename T::value_type& ref = *(e->iter());
#else
            typename T::const_reference ref = *(e->iter());
#endif
            return e->start = address(ref);
         }
         static void* next(void* env)  {
            PEnv_t  e = PEnv_t(env);
            PCont_t c = PCont_t(e->object);
            for (; e->idx > 0 && e->iter() != c->end(); ++(e->iter()), --e->idx );
            // TODO: Need to find something for going backwards....
            if ( e->iter() == c->end() ) return 0;
#ifdef _KCC  // KAI compiler
            typename T::value_type& ref = *(e->iter());
#else
            typename T::const_reference ref = *(e->iter());
#endif
            return address(ref);
         }
         static void* construct(void* env)  {
            PEnv_t  e = PEnv_t(env);
            PValue_t m = PValue_t(e->start);
            for (size_t i=0; i<e->size; ++i, ++m)  
               ::new(m) Value_t();
            return 0;
         }
         static void* collect(void* env)  {
            PEnv_t   e = PEnv_t(env);
            PCont_t  c = PCont_t(e->object);
            PValue_t m = PValue_t(e->start);
            for (Iter_t i=c->begin(); i != c->end(); ++i, ++m )
               ::new(m) Value_t(*i);
            return 0;
         }
         static void* destruct(void* env)  {
            PEnv_t   e = PEnv_t(env);
            PValue_t m = PValue_t(e->start);
            for (size_t i=0; i < e->size; ++i, ++m )
               m->~Value_t();
            return 0;
         }
      };

      /** @class TCollectionProxy::Map TCollectionProxy.h TCollectionProxy.h 
       *
       * Small helper to encapsulate all necessary data accesses for 
       * containers like vector, list, deque
       *
       * @author  M.Frank
       * @version 1.0
       * @date    10/10/2004
       */
      template <class T> struct Pushback : public CollType<T> {
         typedef T                      Cont_t;
         typedef typename T::iterator   Iter_t;
         typedef typename T::value_type Value_t;
         typedef Environ<Iter_t>        Env_t;
         typedef Env_t                 *PEnv_t;
         typedef Cont_t                *PCont_t;
         typedef Value_t               *PValue_t;
         static void* resize(void* env)  {
            PEnv_t  e = PEnv_t(env);
            PCont_t c = PCont_t(e->object);
            c->resize(e->size);
            e->idx = 0;
            return e->start = address(*c->begin());
         }
         static void* feed(void* env)  {
            PEnv_t   e = PEnv_t(env);
            PCont_t  c = PCont_t(e->object);
            PValue_t m = PValue_t(e->start);
            for (size_t i=0; i<e->size; ++i, ++m)
               c->push_back(*m);
            return 0;
         }
         static int value_offset()  {
            return 0;
         }
      };

      /** @class TCollectionProxy::Map TCollectionProxy.h TCollectionProxy.h 
       *
       * Small helper to encapsulate all necessary data accesses for 
       * containers like set, multiset etc.
       *
       * @author  M.Frank
       * @version 1.0
       * @date    10/10/2004
       */
      template <class T> struct Insert : public CollType<T> {
         typedef T                      Cont_t;
         typedef typename T::iterator   Iter_t;
         typedef typename T::value_type Value_t;
         typedef Environ<Iter_t>        Env_t;
         typedef Env_t                 *PEnv_t;
         typedef Cont_t                *PCont_t;
         typedef Value_t               *PValue_t;
         static void* feed(void* env)  {
            PEnv_t   e = PEnv_t(env);
            PCont_t  c = PCont_t(e->object);
            PValue_t m = PValue_t(e->start);
            for (size_t i=0; i<e->size; ++i, ++m)
               c->insert(*m);
            return 0;
         }
         static void* resize(void* /* env */ )  {
            return 0;
         }
         static int value_offset()  {
            return 0;
         }
      };

      /** @class TCollectionProxy::Map TCollectionProxy.h TCollectionProxy.h 
       *
       * Small helper to encapsulate all necessary data accesses for 
       * containers like Set, multiset etc.
       *
       * @author  M.Frank
       * @version 1.0
       * @date    10/10/2004
       */
      template <class T> struct MapInsert : public CollType<T> {
         typedef T                      Cont_t;
         typedef typename T::iterator   Iter_t;
         typedef typename T::value_type Value_t;
         typedef Environ<Iter_t>        Env_t;
         typedef Env_t                 *PEnv_t;
         typedef Cont_t                *PCont_t;
         typedef Value_t               *PValue_t;
         static void* feed(void* env)  {
            PEnv_t   e = PEnv_t(env);
            PCont_t  c = PCont_t(e->object);
            PValue_t m = PValue_t(e->start);
            for (size_t i=0; i<e->size; ++i, ++m)
               c->insert(*m);
            return 0;
         }
         static void* resize(void* /* env */ )  {
            return 0;
         }
         static int value_offset()  {
            return ((char*)&((PValue_t(0x1000))->second)) - ((char*)PValue_t(0x1000));
         }
      };

      // Need specialization for boolean references due to stupid STL vector<bool>
      template<> inline void* ROOT::Reflex::Address<std::vector<bool,std::allocator<bool> >::const_reference>::address(std::vector<bool,std::allocator<bool> >::const_reference ) {
         return 0;
      }

{'fraction_non_alphanumeric': 0.11094144903117102, 'fraction_numerical': 0.011162594776748105, 'mean_word_length': 1.6269709543568465, 'pattern_counts': {'":': 0, '<': 100, '<?xml version=': 0, '>': 199, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6877888', 'n_tokens_mistral': 6056, 'n_tokens_neox': 5748, 'n_words': 1663}