2
0
Эх сурвалжийг харах

Fix EngineAPI xml generation, utilizing fixed_tuple for default args

Lukas Joergensen 7 жил өмнө
parent
commit
c1a234cae6

+ 8 - 1
Engine/source/console/engineFunctions.h

@@ -25,6 +25,10 @@
 
 
 #include <tuple>
 #include <tuple>
 
 
+#ifndef _FIXEDTUPLE_H_
+#include "fixedTuple.h"
+#endif
+
 #ifndef _ENGINEEXPORTS_H_
 #ifndef _ENGINEEXPORTS_H_
    #include "console/engineExports.h"
    #include "console/engineExports.h"
 #endif
 #endif
@@ -94,6 +98,7 @@ template<typename ...ArgTs>
 struct _EngineFunctionDefaultArguments< void(ArgTs...) > : public EngineFunctionDefaultArguments
 struct _EngineFunctionDefaultArguments< void(ArgTs...) > : public EngineFunctionDefaultArguments
 {
 {
    template<typename T> using DefVST = typename EngineTypeTraits<T>::DefaultArgumentValueStoreType;
    template<typename T> using DefVST = typename EngineTypeTraits<T>::DefaultArgumentValueStoreType;
+   fixed_tuple<DefVST<ArgTs>  ...> mFixedArgs;
    std::tuple<DefVST<ArgTs>  ...> mArgs;
    std::tuple<DefVST<ArgTs>  ...> mArgs;
 private:
 private:
    using SelfType = _EngineFunctionDefaultArguments< void(ArgTs...) >;
    using SelfType = _EngineFunctionDefaultArguments< void(ArgTs...) >;
@@ -130,7 +135,9 @@ private:
 public:
 public:
    template<typename ...TailTs> _EngineFunctionDefaultArguments(TailTs ...tail)
    template<typename ...TailTs> _EngineFunctionDefaultArguments(TailTs ...tail)
    : EngineFunctionDefaultArguments({sizeof...(TailTs)}), mArgs(SelfType::tailInit(tail...))
    : EngineFunctionDefaultArguments({sizeof...(TailTs)}), mArgs(SelfType::tailInit(tail...))
-   {}
+   {
+      fixed_tuple_mutator<void(DefVST<ArgTs>...), void(DefVST<ArgTs>...)>::copy(mArgs, mFixedArgs);
+   }
 };
 };
 
 
 #pragma pack( pop )
 #pragma pack( pop )

+ 1 - 1
Engine/source/console/engineXMLExport.cpp

@@ -197,7 +197,7 @@ static String getDefaultArgumentValue( const EngineFunctionInfo* function, const
          //TODO: for now we store string literals in ASCII; needs to be sorted out
          //TODO: for now we store string literals in ASCII; needs to be sorted out
          if( TYPE< const char* >() == type )
          if( TYPE< const char* >() == type )
          {
          {
-            const char* val = getArgValue< const char* >( defaultArgs, offset );
+            const char* val = reinterpret_cast< const char* >(defaultArgs->getArgs() + offset);
             value = val;
             value = val;
          }
          }
             
             

+ 153 - 0
Engine/source/console/fixedTuple.h

@@ -0,0 +1,153 @@
+//-----------------------------------------------------------------------------
+// Copyright (c) 2012 GarageGames, LLC
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to
+// deal in the Software without restriction, including without limitation the
+// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+// IN THE SOFTWARE.
+//-----------------------------------------------------------------------------
+
+#ifndef _FIXEDTUPLE_H_
+#define _FIXEDTUPLE_H_
+/// @name Fixed-layout tuple definition
+/// These structs and templates serve as a way to pass arguments from external 
+/// applications and into the T3D console system.
+/// They work as std::tuple, but they ensure a standardized fixed memory 
+/// layout. Allowing for unmanaged calls with these tuples as the parameter 
+/// lists.
+///
+/// The implementation is from a SO solution:
+/// https://codereview.stackexchange.com/a/52279
+/// As out use-case is pretty simple, this code could probably be simplified by 
+/// stripping out a lot of extra functionality. But eh.
+///
+/// @{
+
+template <typename ...Ts>
+struct fixed_tuple;
+
+template <typename T, typename ...Ts>
+struct fixed_tuple<T, Ts...>
+{
+   T first;
+   fixed_tuple<Ts...> rest;
+
+   fixed_tuple() = default;
+   template <class U, class...Us, class = typename ::std::enable_if<!::std::is_base_of<fixed_tuple, typename ::std::decay<U>::type>::value>::type>
+   fixed_tuple(U&& u, Us&&...tail) :
+      first(::std::forward<U>(u)),
+      rest(::std::forward<Us>(tail)...) {}
+};
+
+template <typename T>
+struct fixed_tuple<T>
+{
+   T first;
+
+   fixed_tuple() = default;
+   template <class U, class = typename ::std::enable_if<!::std::is_base_of<fixed_tuple, typename ::std::decay<U>::type>::value>::type>
+   fixed_tuple(U&& u) :
+      first(::std::forward<U>(u)) {}
+};
+
+template <>
+struct fixed_tuple<> {};
+
+
+template < ::std::size_t i, class T>
+struct fixed_tuple_element;
+
+template < ::std::size_t i, class T, class... Ts>
+struct fixed_tuple_element<i, fixed_tuple<T, Ts...> >
+   : fixed_tuple_element<i - 1, fixed_tuple<Ts...> >
+{};
+
+template <class T, class... Ts>
+struct fixed_tuple_element<0, fixed_tuple<T, Ts...> >
+{
+   using type = T;
+};
+
+template < ::std::size_t i>
+struct fixed_tuple_accessor
+{
+   template <class... Ts>
+   static inline typename fixed_tuple_element<i, fixed_tuple<Ts...> >::type & get(fixed_tuple<Ts...> & t)
+   {
+      return fixed_tuple_accessor<i - 1>::get(t.rest);
+   }
+
+   template <class... Ts>
+   static inline const typename fixed_tuple_element<i, fixed_tuple<Ts...> >::type & get(const fixed_tuple<Ts...> & t)
+   {
+      return fixed_tuple_accessor<i - 1>::get(t.rest);
+   }
+};
+
+template <>
+struct fixed_tuple_accessor<0>
+{
+   template <class... Ts>
+   static inline typename fixed_tuple_element<0, fixed_tuple<Ts...> >::type & get(fixed_tuple<Ts...> & t)
+   {
+      return t.first;
+   }
+
+   template <class... Ts>
+   static inline const typename fixed_tuple_element<0, fixed_tuple<Ts...> >::type & get(const fixed_tuple<Ts...> & t)
+   {
+      return t.first;
+   }
+};
+
+template< typename T1, typename T2 >
+struct fixed_tuple_mutator {};
+
+template<typename... Tdest, typename... Tsrc>
+struct fixed_tuple_mutator<void(Tdest...), void(Tsrc...)>
+{
+   template<std::size_t I = 0>
+   static inline typename std::enable_if<I == sizeof...(Tsrc), void>::type
+      copy_r_t_l(fixed_tuple<Tsrc...>& src, fixed_tuple<Tdest...>& dest)
+   { }
+
+   template<std::size_t I = 0>
+   static inline typename std::enable_if<I < sizeof...(Tsrc), void>::type
+      copy_r_t_l(fixed_tuple<Tsrc...>& src, fixed_tuple<Tdest...>& dest)
+   {
+      fixed_tuple_accessor<I + (sizeof...(Tdest)-sizeof...(Tsrc))>::get(dest) = fixed_tuple_accessor<I>::get(src);
+      copy_r_t_l<I + 1>(src, dest);
+   }
+
+   template<std::size_t I = 0>
+   static inline typename std::enable_if<I == sizeof...(Tsrc), void>::type
+      copy(std::tuple<Tsrc...>& src, fixed_tuple<Tdest...>& dest)
+   { }
+
+   template<std::size_t I = 0>
+   static inline typename std::enable_if<I < sizeof...(Tsrc), void>::type
+      copy(std::tuple<Tsrc...>& src, fixed_tuple<Tdest...>& dest)
+   {
+      fixed_tuple_accessor<I>::get(dest) = std::get<I>(src);
+      copy<I + 1>(src, dest);
+   }
+};
+
+
+/// @}
+
+
+#endif // !_FIXEDTUPLE_H_