Ejemplo n.º 1
0
        public Dictionary <TKey, TValue> FromNative(IntPtr nativeBuffer, int arrayIndex, IntPtr prop)
        {
            IntPtr scriptMapAddress = nativeBuffer + (arrayIndex * Marshal.SizeOf(typeof(FScriptMap)));

            helper.Map = scriptMapAddress;

            unsafe
            {
                FScriptMap *map = (FScriptMap *)scriptMapAddress;
                Dictionary <TKey, TValue> result = new Dictionary <TKey, TValue>();
                int maxIndex = map->GetMaxIndex();
                for (int i = 0; i < maxIndex; ++i)
                {
                    if (map->IsValidIndex(i))
                    {
                        IntPtr keyPtr, valuePtr;
                        helper.GetPairPtr(i, out keyPtr, out valuePtr);
                        result.Add(
                            keyFromNative(keyPtr, 0, helper.KeyPropertyAddress),
                            valueFromNative(valuePtr, 0, helper.ValuePropertyAddress));
                    }
                }
                return(result);
            }
        }
Ejemplo n.º 2
0
        public FScriptMapHelper(IntPtr mapProperty, IntPtr map)
        {
            this.mapProperty = mapProperty;
            this.map         = (FScriptMap *)map;
            mapLayout        = Native_UMapProperty.Get_MapLayout(mapProperty);

            keyProp     = Native_UMapProperty.Get_KeyProp(mapProperty);
            keySize     = Native_UProperty.Get_ElementSize(keyProp);
            keyArrayDim = Native_UProperty.Get_ArrayDim(keyProp);

            valueProp     = Native_UMapProperty.Get_ValueProp(mapProperty);
            valueSize     = Native_UProperty.Get_ElementSize(valueProp);
            valueArrayDim = Native_UProperty.Get_ArrayDim(valueProp);
        }
Ejemplo n.º 3
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));
        }
Ejemplo n.º 4
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);
                }
            }
        }
Ejemplo n.º 5
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->Count;
                for (int i = 0; i < count; ++i)
                {
                    IntPtr keyPtr, valuePtr;
                    helper.GetPairPtr(i, out keyPtr, out valuePtr);
                    result.Add(
                        keyFromNative(keyPtr, 0, helper.KeyPropertyAddress),
                        valueFromNative(valuePtr, 0, helper.ValuePropertyAddress));
                }
                return(result);
            }
        }