Exemplo n.º 1
0
        public static void ToNative(IntPtr nativeBuffer, int arrayIndex, IntPtr prop, IDictionary <TKey, TValue> value)
        {
            FScriptMapHelper helper = new FScriptMapHelper(prop);

            TMapReadWriteMarshaler <TKey, TValue> .ToNativeInternal(
                nativeBuffer, arrayIndex, value, ref helper, keyToNative, valueToNative);
        }
Exemplo n.º 2
0
        public static IDictionary <TKey, TValue> FromNative(IntPtr nativeBuffer, int arrayIndex, IntPtr prop)
        {
            IntPtr           scriptMapAddress = nativeBuffer + (arrayIndex * Marshal.SizeOf(typeof(FScriptMap)));
            FScriptMapHelper helper           = new FScriptMapHelper(prop, scriptMapAddress);

            unsafe
            {
                FScriptMap *map = (FScriptMap *)scriptMapAddress;
                Dictionary <TKey, TValue> result = new Dictionary <TKey, TValue>();
                int count = map->GetMaxIndex();
                for (int i = 0; i < count; ++i)
                {
                    if (!map->IsValidIndex(i))
                    {
                        continue;
                    }

                    IntPtr keyPtr, valuePtr;
                    helper.GetPairPtr(i, out keyPtr, out valuePtr);
                    result.Add(
                        keyFromNative(keyPtr, 0, helper.KeyPropertyAddress),
                        valueFromNative(valuePtr, 0, helper.ValuePropertyAddress));
                }
                return(result);
            }
        }
Exemplo n.º 3
0
 public TMapCopyMarshaler(int length, UFieldAddress mapProperty,
                          MarshalingDelegates <TKey> .FromNative keyFromNative, MarshalingDelegates <TKey> .ToNative keyToNative,
                          MarshalingDelegates <TValue> .FromNative valueFromNative, MarshalingDelegates <TValue> .ToNative valueToNative)
 {
     property             = mapProperty;
     helper               = new FScriptMapHelper(property.Address);
     this.keyFromNative   = keyFromNative;
     this.keyToNative     = keyToNative;
     this.valueFromNative = valueFromNative;
     this.valueToNative   = valueToNative;
 }
Exemplo n.º 4
0
        public static FScriptMapHelper CreateHelperFormInnerProperty(IntPtr keyProperty, IntPtr valProperty, IntPtr map)
        {
            FScriptMapHelper scriptMapHelper = new FScriptMapHelper();

            scriptMapHelper.keyProp   = keyProperty;
            scriptMapHelper.valueProp = valProperty;
            scriptMapHelper.map       = (FScriptMap *)map;
            scriptMapHelper.mapLayout = FScriptMap.GetScriptLayout(
                Native_UProperty.GetSize(keyProperty), Native_UProperty.GetMinAlignment(keyProperty),
                Native_UProperty.GetSize(valProperty), Native_UProperty.GetMinAlignment(valProperty));
            return(scriptMapHelper);
        }
Exemplo n.º 5
0
        public TMapBase(UObject owner, UFieldAddress mapProperty, IntPtr address,
                        MarshalingDelegates <TKey> .FromNative keyFromNative, MarshalingDelegates <TKey> .ToNative keyToNative,
                        MarshalingDelegates <TValue> .FromNative valueFromNative, MarshalingDelegates <TValue> .ToNative valueToNative)
        {
            property = mapProperty;
            map      = (FScriptMap *)address;

            MapHelper = new FScriptMapHelper(property.Address, address);

            Owner           = owner;
            KeyFromNative   = keyFromNative;
            KeyToNative     = keyToNative;
            ValueFromNative = valueFromNative;
            ValueToNative   = valueToNative;

            ContainerHashValidator.Validate(Native_UMapProperty.Get_KeyProp(property.Address));
        }
Exemplo n.º 6
0
        internal static void ToNativeInternal(IntPtr nativeBuffer, int arrayIndex, IDictionary <TKey, TValue> value,
                                              ref FScriptMapHelper helper, MarshalingDelegates <TKey> .ToNative keyToNative, MarshalingDelegates <TValue> .ToNative valueToNative)
        {
            IntPtr scriptMapAddress = nativeBuffer + (arrayIndex * Marshal.SizeOf(typeof(FScriptMap)));

            helper.Map = scriptMapAddress;

            // Make sure any existing elements are properly destroyed
            helper.EmptyValues();

            if (value == null)
            {
                return;
            }

            unsafe
            {
                FScriptMap *map = (FScriptMap *)scriptMapAddress;

                Dictionary <TKey, TValue> dictionary = value as Dictionary <TKey, TValue>;
                if (dictionary != null)
                {
                    foreach (KeyValuePair <TKey, TValue> pair in dictionary)
                    {
                        helper.AddPair(pair.Key, pair.Value, keyToNative, valueToNative);
                    }
                    return;
                }

                TMapBase <TKey, TValue> mapBase = value as TMapBase <TKey, TValue>;
                if (mapBase != null)
                {
                    foreach (KeyValuePair <TKey, TValue> pair in mapBase)
                    {
                        helper.AddPair(pair.Key, pair.Value, keyToNative, valueToNative);
                    }
                    return;
                }

                foreach (KeyValuePair <TKey, TValue> pair in value)
                {
                    helper.AddPair(pair.Key, pair.Value, keyToNative, valueToNative);
                }
            }
        }