Пример #1
0
 ModulePtr container_type(const std::string &/*type*/, ModulePtr m = std::make_shared<Module>())
 {
   m->add(fun<size_t (const ContainerType *)>([](const ContainerType *a) { return a->size(); } ), "size");
   m->add(fun<bool (const ContainerType *)>([](const ContainerType *a) { return a->empty(); } ), "empty");
   m->add(fun<void (ContainerType *)>([](ContainerType *a) { a->clear(); } ), "clear");
   return m;
 }
 ModulePtr container_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module()))
 {
   m->add(fun( std::function<size_t (const ContainerType *)>( [](const ContainerType *a) { return a->size(); } ) ), "size");
   m->add(fun( std::function<bool (const ContainerType *)>( [](const ContainerType *a) { return a->empty(); } ) ), "empty");
   m->add(fun( std::function<void (ContainerType *)>( [](ContainerType *a) { a->clear(); } ) ), "clear");
   return m;
 }
Пример #3
0
        ModulePtr back_insertion_sequence_type(const std::string &type, ModulePtr m = std::make_shared<Module>())
        {
          typedef typename ContainerType::reference (ContainerType::*backptr)();

          m->add(fun(static_cast<backptr>(&ContainerType::back)), "back");


          typedef void (ContainerType::*push_back)(const typename ContainerType::value_type &);
          m->add(fun(static_cast<push_back>(&ContainerType::push_back)),
              [&]()->std::string{
              if (typeid(typename ContainerType::value_type) == typeid(Boxed_Value)) {
                m->eval(
                    "# Pushes the second value onto the container while making a clone of the value\n"
                    "def push_back(" + type + " container, x)\n"
                    "{ \n"
                    "  if (x.is_var_return_value()) {\n"
                    "    x.reset_var_return_value() \n"
                    "    container.push_back_ref(x) \n"
                    "  } else { \n"
                    "    container.push_back_ref(clone(x)); \n"
                    "  }\n"
                    "} \n"
                    );

                  return "push_back_ref";
                } else {
                  return "push_back";
                }
              }());

          m->add(fun(&ContainerType::pop_back), "pop_back");
          return m;
        }
Пример #4
0
        ModulePtr front_insertion_sequence_type(const std::string &type, ModulePtr m = std::make_shared<Module>())
        {
          typedef typename ContainerType::reference (ContainerType::*front_ptr)();
          typedef typename ContainerType::const_reference (ContainerType::*const_front_ptr)() const;
          typedef void (ContainerType::*push_ptr)(typename ContainerType::const_reference);
          typedef void (ContainerType::*pop_ptr)();

          m->add(fun(static_cast<front_ptr>(&ContainerType::front)), "front");
          m->add(fun(static_cast<const_front_ptr>(&ContainerType::front)), "front");

          m->add(fun(static_cast<push_ptr>(&ContainerType::push_front)),
              [&]()->std::string{
                if (typeid(typename ContainerType::value_type) == typeid(Boxed_Value)) {
                  m->eval(
                      "# Pushes the second value onto the front of container while making a clone of the value\n"
                      "def push_front(" + type + " container, x)\n"
                      "{ \n"
                      "  if (x.is_var_return_value()) {\n"
                      "    x.reset_var_return_value() \n"
                      "    container.push_front_ref(x) \n"
                      "  } else { \n"
                      "    container.push_front_ref(clone(x)); \n"
                      "  }\n"
                      "} \n"
                      );
                  return "push_front_ref";
                } else {
                  return "push_front";
                }
              }());

          m->add(fun(static_cast<pop_ptr>(&ContainerType::pop_front)), "pop_front");
          return m;
        }
Пример #5
0
 ModulePtr container_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module()))
 {
   boost::function<int (const ContainerType *)> f = detail::return_int(&ContainerType::size);
   m->add(fun(f), "size");
   m->add(fun<bool (ContainerType::*)() const>(&ContainerType::empty), "empty");
   m->add(fun<void (ContainerType::*)()>(&ContainerType::clear), "clear");
   return m;
 }
Пример #6
0
        ModulePtr sequence_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module()))
        {
          std::string insert_name;
          if (typeid(typename ContainerType::value_type) == typeid(Boxed_Value))
          {
            insert_name = "insert_ref_at";
          } else {
            insert_name = "insert_at";
          }

          m->add(fun(&detail::insert_at<ContainerType>), insert_name);
          m->add(fun(&detail::erase_at<ContainerType>), "erase_at");

          return m;
        }
Пример #7
0
        ModulePtr sequence_type(const std::string &/*type*/, ModulePtr m = std::make_shared<Module>())
        {
          m->add(fun(&detail::insert_at<ContainerType>), 
              []()->std::string{
                if (typeid(typename ContainerType::value_type) == typeid(Boxed_Value)) {
                  return "insert_ref_at";
                } else {
                  return "insert_at";
                }
              }());

          m->add(fun(&detail::erase_at<ContainerType>), "erase_at");

          return m;
        }
Пример #8
0
        ModulePtr pair_type(const std::string &type, ModulePtr m = std::make_shared<Module>())
        {
          m->add(user_type<PairType>(), type);


          typename PairType::first_type PairType::* f = &PairType::first;
          typename PairType::second_type PairType::* s = &PairType::second;

          m->add(fun(f), "first");
          m->add(fun(s), "second");

          basic_constructors<PairType>(type, m);
          m->add(constructor<PairType (const typename PairType::first_type &, const typename PairType::second_type &)>(), type);

          return m;
        }
Пример #9
0
        ModulePtr random_access_container_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module()))
        {
          typedef typename ContainerType::reference(ContainerType::*indexoper)(size_t);
          typedef typename ContainerType::const_reference(ContainerType::*constindexoper)(size_t) const;

          //In the interest of runtime safety for the m, we prefer the at() method for [] access,
          //to throw an exception in an out of bounds condition.
          m->add(
              fun(boost::function<typename ContainerType::reference (ContainerType *, int)>
                (boost::mem_fn(static_cast<indexoper>(&ContainerType::at)))), "[]");
          m->add(
              fun(boost::function<typename ContainerType::const_reference (const ContainerType *, int)>
                (boost::mem_fn(static_cast<constindexoper>(&ContainerType::at)))), "[]");

          return m;
        }
Пример #10
0
        ModulePtr map_type(const std::string &type, ModulePtr m = ModulePtr(new Module()))
        {
          m->add(user_type<MapType>(), type);

          typedef typename MapType::mapped_type &(MapType::*elemaccess)(const typename MapType::key_type &);

          m->add(fun(static_cast<elemaccess>(&MapType::operator[])), "[]");

          container_type<MapType>(type, m);
          assignable_type<MapType>(type, m);
          unique_associative_container_type<MapType>(type, m);
          pair_associative_container_type<MapType>(type, m);
          input_range_type<MapType>(type, m);

          return m;
        }
Пример #11
0
        ModulePtr random_access_container_type(const std::string &/*type*/, ModulePtr m = std::make_shared<Module>())
        {
          //In the interest of runtime safety for the m, we prefer the at() method for [] access,
          //to throw an exception in an out of bounds condition.
          m->add(
              fun(
                [](ContainerType &c, int index) -> typename ContainerType::reference {
                  return c.at(index);
                }), "[]");

          m->add(
              fun(
                [](const ContainerType &c, int index) -> typename ContainerType::const_reference {
                  return c.at(index);
                }), "[]");

          return m;
        }
Пример #12
0
        ModulePtr random_access_container_type(const std::string &/*type*/, ModulePtr m = std::make_shared<Module>())
        {
          // cppcheck-suppress syntaxError
          typedef typename ContainerType::reference(ContainerType::*indexoper)(size_t);

          //In the interest of runtime safety for the m, we prefer the at() method for [] access,
          //to throw an exception in an out of bounds condition.
          m->add(
              fun(std::function<typename ContainerType::reference (ContainerType *, int)>
                (std::mem_fn(static_cast<indexoper>(&ContainerType::at)))), "[]");
          m->add(
              fun<typename ContainerType::const_reference (const ContainerType *, int)>(
                [](const ContainerType *c, int index) -> typename ContainerType::const_reference {
                  return c->at(index);
                }), "[]");

          return m;
        }
Пример #13
0
        ModulePtr back_insertion_sequence_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module()))
        {
          typedef typename ContainerType::reference (ContainerType::*backptr)();

          m->add(fun(static_cast<backptr>(&ContainerType::back)), "back");

          std::string push_back_name;
          if (typeid(typename ContainerType::value_type) == typeid(Boxed_Value))
          {
            push_back_name = "push_back_ref";
          } else {
            push_back_name = "push_back";
          }

          typedef void (ContainerType::*pushback)(const typename ContainerType::value_type &);
          m->add(fun(static_cast<pushback>(&ContainerType::push_back)), push_back_name);
          m->add(fun(&ContainerType::pop_back), "pop_back");
          return m;
        }
Пример #14
0
        ModulePtr back_insertion_sequence_type(const std::string &/*type*/, ModulePtr m = std::make_shared<Module>())
        {
          typedef typename ContainerType::reference (ContainerType::*backptr)();

          m->add(fun(static_cast<backptr>(&ContainerType::back)), "back");


          typedef void (ContainerType::*push_back)(const typename ContainerType::value_type &);
          m->add(fun(static_cast<push_back>(&ContainerType::push_back)),
              []()->std::string{
                if (typeid(typename ContainerType::value_type) == typeid(Boxed_Value)) {
                  return "push_back_ref";
                } else {
                  return "push_back";
                }
              }());

          m->add(fun(&ContainerType::pop_back), "pop_back");
          return m;
        }
Пример #15
0
        ModulePtr front_insertion_sequence_type(const std::string &, ModulePtr m = ModulePtr(new Module()))
        {
          typedef typename ContainerType::reference (ContainerType::*frontptr)();
          typedef void (ContainerType::*pushptr)(typename ContainerType::const_reference);
          typedef void (ContainerType::*popptr)();

          m->add(fun(static_cast<frontptr>(&ContainerType::front)), "front");

          std::string push_front_name;
          if (typeid(typename ContainerType::value_type) == typeid(Boxed_Value))
          {
            push_front_name = "push_front_ref";
          } else {
            push_front_name = "push_front";
          }

          m->add(fun(static_cast<pushptr>(&ContainerType::push_front)), push_front_name);
          m->add(fun(static_cast<popptr>(&ContainerType::pop_front)), "pop_front");
          return m;
        }
        ModulePtr unique_associative_container_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module()))
        {
          m->add(fun(detail::count<ContainerType>), "count");

          typedef size_t (ContainerType::*erase_ptr)(const typename ContainerType::key_type &);

          m->add(fun(static_cast<erase_ptr>(&ContainerType::erase)), "erase");

          m->add(fun(&detail::insert<ContainerType>), "insert");

          std::string insert_name;
          if (typeid(typename ContainerType::mapped_type) == typeid(Boxed_Value))
          {
            insert_name = "insert_ref";
          } else {
            insert_name = "insert";
          }

          m->add(fun(&detail::insert_ref<ContainerType>), insert_name);
          return m;
        }
Пример #17
0
        ModulePtr front_insertion_sequence_type(const std::string &, ModulePtr m = std::make_shared<Module>())
        {
          typedef typename ContainerType::reference (ContainerType::*front_ptr)();
          typedef typename ContainerType::const_reference (ContainerType::*const_front_ptr)() const;
          typedef void (ContainerType::*push_ptr)(typename ContainerType::const_reference);
          typedef void (ContainerType::*pop_ptr)();

          m->add(fun(static_cast<front_ptr>(&ContainerType::front)), "front");
          m->add(fun(static_cast<const_front_ptr>(&ContainerType::front)), "front");

          m->add(fun(static_cast<push_ptr>(&ContainerType::push_front)),
              []()->std::string{
                if (typeid(typename ContainerType::value_type) == typeid(Boxed_Value)) {
                  return "push_front_ref";
                } else {
                  return "push_front";
                }
              }());

          m->add(fun(static_cast<pop_ptr>(&ContainerType::pop_front)), "pop_front");
          return m;
        }
Пример #18
0
        ModulePtr unique_associative_container_type(const std::string &/*type*/, ModulePtr m = std::make_shared<Module>())
        {
          m->add(fun(detail::count<ContainerType>), "count");

          typedef size_t (ContainerType::*erase_ptr)(const typename ContainerType::key_type &);

          m->add(fun(static_cast<erase_ptr>(&ContainerType::erase)), "erase");

          m->add(fun(&detail::insert<ContainerType>), "insert");

          m->add(fun(&detail::insert_ref<ContainerType>), 
              []()->std::string{
                if (typeid(typename ContainerType::mapped_type) == typeid(Boxed_Value)) {
                  return "insert_ref";
                } else {
                  return "insert";
                }
              }());


          return m;
        }
Пример #19
0
        ModulePtr unique_associative_container_type(const std::string &/*type*/, ModulePtr m = ModulePtr(new Module()))
        {
          m->add(fun(boost::function<int (const ContainerType *, const typename ContainerType::key_type &)>(detail::return_int(&ContainerType::count))), "count");


          typedef size_t (ContainerType::*erase)(const typename ContainerType::key_type &);
          erase eraseptr(&ContainerType::erase);

          m->add(fun(boost::function<int (ContainerType *, const typename ContainerType::key_type &)>(detail::return_int(eraseptr))), "erase");

          m->add(fun(&detail::insert<ContainerType>), "insert");

          std::string insert_name;
          if (typeid(typename ContainerType::mapped_type) == typeid(Boxed_Value))
          {
            insert_name = "insert_ref";
          } else {
            insert_name = "insert";
          }

          m->add(fun(&detail::insert_ref<ContainerType>), insert_name);
          return m;
        }
Пример #20
0
        ModulePtr list_type(const std::string &type, ModulePtr m = std::make_shared<Module>())
        {
          m->add(user_type<ListType>(), type);

          front_insertion_sequence_type<ListType>(type, m);
          back_insertion_sequence_type<ListType>(type, m);
          sequence_type<ListType>(type, m);
          container_type<ListType>(type, m);
          default_constructible_type<ListType>(type, m);
          assignable_type<ListType>(type, m);
          input_range_type<ListType>(type, m);

          return m;
        }
Пример #21
0
        ModulePtr vector_type(const std::string &type, ModulePtr m = ModulePtr(new Module()))
        {
          m->add(user_type<VectorType>(), type);

          typedef typename VectorType::reference (VectorType::*frontptr)();
          m->add(fun(static_cast<frontptr>(&VectorType::front)), "front");


          back_insertion_sequence_type<VectorType>(type, m);
          sequence_type<VectorType>(type, m);
          random_access_container_type<VectorType>(type, m);
          container_type<VectorType>(type, m);
          default_constructible_type<VectorType>(type, m);
          assignable_type<VectorType>(type, m);
          input_range_type<VectorType>(type, m);

          if (typeid(VectorType) == typeid(std::vector<Boxed_Value>))
          {
            m->eval("def Vector::`==`(rhs) : type_match(rhs, this) { \
                       if ( rhs.size() != this.size() ) {    \
                         return false;  \
                       } else {  \
                         var r1 = range(this); \
                         var r2 = range(rhs);  \
                         while (!r1.empty()) \
                         {  \
                           if (!eq(r1.front(), r2.front())) \
                           {  \
                             return false; \
                           } \
                           r1.pop_front(); \
                           r2.pop_front(); \
                         } \
                       return true; \
                     } \
                   }");
Пример #22
0
          ModulePtr input_range_type_impl(const std::string &type, ModulePtr m = std::make_shared<Module>())
          {
            m->add(user_type<Bidir_Type>(), type + "_Range");

            copy_constructor<Bidir_Type>(type + "_Range", m);

            m->add(constructor<Bidir_Type (typename Bidir_Type::container_type &)>(), "range_internal");

            m->add(fun(&Bidir_Type::empty), "empty");
            m->add(fun(&Bidir_Type::pop_front), "pop_front");
            m->add(fun(&Bidir_Type::front), "front");
            m->add(fun(&Bidir_Type::pop_back), "pop_back");
            m->add(fun(&Bidir_Type::back), "back");

            return m;
          } 
Пример #23
0
 ModulePtr right_shift(ModulePtr m = ModulePtr(new Module()))
 {
   m->add(fun(&right_shift<T, const T &, const T &>), ">>");
   return m;
 }
Пример #24
0
 ModulePtr remainder(ModulePtr m = ModulePtr(new Module()))
 {
   m->add(fun(&remainder<T, const T &, const T &>), "%");
   return m;
 }
Пример #25
0
 ModulePtr multiplication(ModulePtr m = ModulePtr(new Module()))
 {
   m->add(fun(&multiplication<T, const T &, const T &>), "*");
   return m;
 }
Пример #26
0
 ModulePtr left_shift(ModulePtr m = ModulePtr(new Module()))
 {
   m->add(fun(&left_shift<T, const T &, const T &>), "<<");
   return m;
 }
Пример #27
0
 ModulePtr division(ModulePtr m = ModulePtr(new Module()))
 {
   m->add(fun(&division<T, const T &, const T &>), "/");
   return m;
 }
Пример #28
0
 ModulePtr bitwise_or(ModulePtr m = ModulePtr(new Module()))
 {
   m->add(fun(&bitwise_or<T, const T &, const T &>), "|");
   return m;
 }
Пример #29
0
 ModulePtr bitwise_compliment(ModulePtr m = ModulePtr(new Module()))
 {
   m->add(fun(&bitwise_compliment<T, const T &>), "~");
   return m;
 }
Пример #30
0
 ModulePtr bitwise_and(ModulePtr m = ModulePtr(new Module()))
 {
   m->add(fun(&bitwise_and<T, const T &, const T &>), "&");
   return m;
 }