Exemple #1
0
        private static T AssertInstance <T>(NewExpression newExpression)
        {
            var value = CreateFunc <T>(Expr.Return(newExpression))();

            Assert.That(value, Is.InstanceOf <T>());
            return(value);
        }
Exemple #2
0
 public ObjectPool(int capacity, CreateFunc onCreateObject, params IPooledObjectProcessor <T>[] processors)
 {
     this.pool      = new Stack <T>(capacity);
     this.processor = Flat(processors);
     this.Create    = onCreateObject;
     Debug.Assert(Create != null, "onCreateObject cannot be null");
 }
 public GeneratorContainerEntry(CreateFunc <T> generator)
 {
     if (generator == null)
     {
         throw new ArgumentNullException(nameof(generator));
     }
     _generator = generator;
 }
Exemple #4
0
 public void Init(int poolSize, CreateFunc createFunc = null, Action <T> resetAction = null)
 {
     m_objStack = new Stack <T>(poolSize);
     for (int i = 0; i < poolSize; i++)
     {
         T item = new T();
         m_objStack.Push(item);
     }
 }
Exemple #5
0
 public LazyContainerEntry(CreateFunc <T> initializer)
 {
     if (initializer == null)
     {
         throw new ArgumentNullException(nameof(initializer));
     }
     _initializer = initializer;
     _initialized = false;
     _value       = null;
 }
Exemple #6
0
 public void Init(int poolSize, CreateFunc createFunc = null, Action <T> resetAction = null)
 {
     m_objStack    = new Stack <T>();
     m_resetAction = resetAction;
     m_createFunc  = createFunc;
     for (int i = 0; i < poolSize; i++)
     {
         T item = (m_createFunc != null) ? m_createFunc() : new T();
         m_objStack.Push(item);
     }
 }
Exemple #7
0
 public void Init(int poolSize, CreateFunc createFunc = null, Action <T> resetAction = null)
 {
     m_objStack    = new List <T>();
     m_resetAction = resetAction;
     m_createFunc  = createFunc;
     for (int i = 0; i < poolSize; i++)
     {
         T item = m_createFunc();
         m_objStack.Add(item);
     }
     m_topIndex = poolSize - 1;
 }
Exemple #8
0
        protected ObjectPool(int nMaxSize = int.MaxValue)
        {
#if DISABLE_POOLING
            _nMaxSize  = int.MaxValue;
            _iCursor   = -1;
            _nPoolSize = 0;
#else
            SetMaxSize(nMaxSize);

            _pCreator    = null;
            _objectQueue = new Deque <T>(1);

            _nPoolSize = 0;
#endif
        }
    public Pool(T sample, CreateFunc createFunc, DestroyFunc destroyFunc, ActivateFunc activateFunc, DeactivateFunc deactivateFunc, int initialSize = 100)
    {
        m_sample     = sample;
        m_create     = createFunc;
        m_destroy    = destroyFunc;
        m_activate   = activateFunc;
        m_deactivate = deactivateFunc;
        var go = sample as GameObject;

        if (go)
        {
            m_parent = new GameObject(go.name + "-Pool");
        }

        Grow(initialSize);
    }
Exemple #10
0
        protected FastPool(int nMaxSize = int.MaxValue)
        {
#if DISABLE_POOLING
            _nMaxSize = int.MaxValue;
            _iCursor = -1;
            _nPoolSize = 0;
#else
            SetMaxSize(nMaxSize);

            _pCreator = null;
            _arrObjectSlots = new T[0];

            _iCursor = -1;
            _nPoolSize = 0;
#endif
        }
Exemple #11
0
        public FastPool(int nInitSize, CreateFunc pCreator, int nMaxSize = int.MaxValue)
        {
#if DISABLE_POOLING
            _nMaxSize = int.MaxValue;
            _iCursor = -1;
            _nPoolSize = 0;
#else
            SetMaxSize(nMaxSize);

            _pCreator = pCreator;
            _arrObjectSlots = new T[nInitSize];

            _iCursor = -1;
            _nPoolSize = 0;

            for (int i = 0; i < nInitSize; ++i) Add(_pCreator(this));
#endif
        }
Exemple #12
0
        public ObjectPool(int nInitSize, CreateFunc pCreator, int nMaxSize = int.MaxValue)
        {
#if DISABLE_POOLING
            _nMaxSize  = int.MaxValue;
            _iCursor   = -1;
            _nPoolSize = 0;
#else
            _objectQueue = new Deque <T>(nInitSize == 0? 1 : nInitSize);

            SetMaxSize(nMaxSize);

            _pCreator  = pCreator;
            _nPoolSize = 0;

            for (int i = 0; i < nInitSize; ++i)
            {
                Add(_pCreator(this));
            }
#endif
        }
Exemple #13
0
    public void Init(int poolSize, CreateFunc createFunc, Action <T> resetAction)
    {
        m_objStack    = new Stack <T>();
        m_resetAction = resetAction;
        m_createFunc  = createFunc;

        if (m_createFunc == null)
        {
            throw new NullReferenceException("create function can't be null");
        }
        if (resetAction == null)
        {
            throw new NullReferenceException("reset function can't be null");
        }

        for (int i = 0; i < poolSize; i++)
        {
            T item = m_createFunc();
            m_objStack.Push(item);
        }
    }
Exemple #14
0
    private void CreateButton <T>(MenuSettings <T> settings, CreateFunc <T> func) where T : UnityEngine.Object
    {
        EditorGUILayout.BeginHorizontal();
        T[]      objs  = FindObjectsOfType <T>();
        string[] names = objs.Select(x => x.name).ToArray();
        string   msg   = "";

        if (ArrayUtility.Contains(names, settings.name))
        {
            msg = "Duplicate name"; GUI.enabled = false;
        }
        if (settings.name == "")
        {
            msg = "Empty Name"; GUI.enabled = false;
        }
        EditorGUILayout.LabelField(msg, GUILayout.Width(197));
        if (GUILayout.Button("Create", LayoutSettings.buttonOp))
        {
            func(settings);
        }
        EditorGUILayout.EndHorizontal();
    }
Exemple #15
0
 public static void ReplaceByLazyValueComponent <T>(this IServiceContainer container, String name, CreateFunc <T> initializer) where T : class
 {
     if (container == null)
     {
         throw new ArgumentNullException(nameof(container));
     }
     if (String.IsNullOrEmpty(name))
     {
         throw new ArgumentNullException(nameof(name));
     }
     if (initializer == null)
     {
         throw new ArgumentNullException(nameof(initializer));
     }
     ReplaceComponent <T>(container, name, new LazyContainerEntry <T>(initializer));
 }
Exemple #16
0
 public static void ReplaceByGeneratorComponent(this IServiceContainer container, Object key, CreateFunc <Object> generator)
 {
     if (container == null)
     {
         throw new ArgumentNullException(nameof(container));
     }
     if (key == null)
     {
         throw new ArgumentNullException(nameof(key));
     }
     if (generator == null)
     {
         throw new ArgumentNullException(nameof(generator));
     }
     ReplaceComponent(container, key, new GeneratorContainerEntry <Object>(generator));
 }
Exemple #17
0
 public static void ReplaceByLazyValueComponent(this IServiceContainer container, Object key, CreateFunc <Object> initializer)
 {
     if (container == null)
     {
         throw new ArgumentNullException(nameof(container));
     }
     if (key == null)
     {
         throw new ArgumentNullException(nameof(key));
     }
     if (initializer == null)
     {
         throw new ArgumentNullException(nameof(initializer));
     }
     ReplaceComponent(container, key, new LazyContainerEntry <Object>(initializer));
 }
Exemple #18
0
 /// <summary>
 /// Create a pool with argument values
 /// </summary>
 /// <param name="initCount"></param>
 public CObjectPool(CreateFunc func, int initCount)
 {
     InitializeCreateCount = initCount;
     OnCreate = func;
 }
Exemple #19
0
 public ObjectPool(CreateFunc onCreateObject, Transform storageNode)
     : this(0, onCreateObject, storageNode)
 {
 }
Exemple #20
0
 /// <summary>
 /// Create a pool with the size of the initial value.
 /// </summary>
 public CObjectPool(CreateFunc func)
 {
     OnCreate = func;
 }
Exemple #21
0
 public static void ReplaceByGeneratorComponent(this IServiceContainer container, String name, Type type, CreateFunc <Object> generator)
 {
     if (container == null)
     {
         throw new ArgumentNullException(nameof(container));
     }
     if (String.IsNullOrEmpty(name))
     {
         throw new ArgumentNullException(nameof(name));
     }
     if (type == null)
     {
         throw new ArgumentNullException(nameof(type));
     }
     if (generator == null)
     {
         throw new ArgumentNullException(nameof(generator));
     }
     ReplaceComponent(container, name, type, new GeneratorContainerEntry <Object>(generator));
 }
Exemple #22
0
        /// <summary>
        /// Завантаження інформації товарів
        /// </summary>
        /// <param name="localLoadedTempFiles">Шляхи до файлів</param>
        /// <param name="onlyUpdate">Якщо ture то завантажувати інформацію лише з нових файлів в іншому випадку завантажувати з всіх</param>
        /// <returns>Завантажена інформація</returns>
        public static object[] LoadData(string[] localLoadedTempFiles, bool onlyUpdate)
        {
            winapi.WApi.OutputDebugString("--- LoadData_begin");

            FileStream fs = null;
            DataTable[] dTables = new DataTable[3];
            bool exchangeFldUsed = false;
            IntPtr hFile = IntPtr.Zero;
            ReadFunc[] rdFunc = new ReadFunc[3];
            rdFunc[0] = ReadArtSDF;
            rdFunc[1] = ReadAltSDF;
            rdFunc[2] = ReadCardSDF;
            CreateFunc[] crFunc = new CreateFunc[3];
            crFunc[0] = CreateArtDataTable;
            crFunc[1] = CreateAltDataTable;
            crFunc[2] = CreateCardDataTable;

            if (!Directory.Exists(AppConfig.Path_Articles))
                Directory.CreateDirectory(AppConfig.Path_Articles);

            string[] artFiles = new string[3];
            artFiles[0] = AppConfig.Path_Articles + "\\" + string.Format("Art_{0:X2}.saf", AppConfig.APP_SubUnit);
            artFiles[1] = AppConfig.Path_Articles + "\\" + string.Format("Alt_{0:X2}.saf", AppConfig.APP_SubUnit);
            artFiles[2] = AppConfig.Path_Articles + "\\" + "DCards.saf";

            for (int i = 0; i < artFiles.Length; i++)
                if (localLoadedTempFiles != null && localLoadedTempFiles[i] != "")
                {

                    winapi.WApi.OutputDebugString("EXCHAGE LoadingFromNewSource_begin");
                    dTables[i] = crFunc[i].Invoke();
                    rdFunc[i].Invoke(localLoadedTempFiles[i], ref dTables[i]);
                    fs = new FileStream(artFiles[i], FileMode.Create);
                    binF.Serialize(fs, dTables[i]);
                    //dTables[i].TableName = Path.GetFileNameWithoutExtension(localLoadedTempFiles[i]);
                    //dTables[i].WriteXml(fs);
                    fs.Close();
                    fs.Dispose();
                    exchangeFldUsed = true;
                    if (!AppConfig.Content_Articles_KeepDataAfterImport)
                        Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile(localLoadedTempFiles[i], UIOption.AllDialogs, RecycleOption.SendToRecycleBin);
                    winapi.WApi.OutputDebugString("EXCHAGE LoadingFromNewSource_end");
                }
                else
                {
                    if (!onlyUpdate && winapi.WApi.PathFileExists(artFiles[i]))
                    {
                        winapi.WApi.OutputDebugString("LOCAL LoadingFromLocalCopy_begin");
                        fs = new FileStream(artFiles[i], FileMode.Open, FileAccess.Read);
                        //dTables[i].ReadXml(fs);
                        dTables[i] = (DataTable)binF.Deserialize(fs);
                        if (!new sgmode.ClassMode().FullLoader())
                        {
                            DataTable tDt = dTables[i].Clone();
                            for (int jp = 0; jp < 10; jp++)
                            {
                                if (dTables[i].Rows.Count <= jp) break;
                                tDt.Rows.Add(dTables[i].Rows[jp].ItemArray);
                            }
                            dTables[i] = tDt.Copy();
                        }
                        fs.Close();
                        fs.Dispose();
                        winapi.WApi.OutputDebugString("LOCAL LoadingFromLocalCopy_end");
                    }
                }

            if (fs != null)
                fs.Dispose();

            object[] rez = new object[] { dTables, exchangeFldUsed };

            winapi.WApi.OutputDebugString("--- LoadData_end");
            return rez;
        }
Exemple #23
0
 public ObjectPool(CreateFunc onCreateObject)
     : this(0, onCreateObject)
 {
 }
        /// <summary>
        /// Завантаження інформації товарів
        /// </summary>
        /// <param name="localLoadedTempFiles">Шляхи до файлів</param>
        /// <param name="onlyUpdate">Якщо ture то завантажувати інформацію лише з нових файлів в іншому випадку завантажувати з всіх</param>
        /// <returns>Завантажена інформація</returns>
        public static object[] LoadData(string[] localLoadedTempFiles, bool onlyUpdate)
        {
            FileStream fs = null;
            DataTable[] dTables = new DataTable[3];
            bool exchangeFldUsed = false;
            IntPtr hFile = IntPtr.Zero;
            ReadFunc[] rdFunc = new ReadFunc[3];
            rdFunc[0] = ReadArtSDF;
            rdFunc[1] = ReadAltSDF;
            rdFunc[2] = ReadCardSDF;
            CreateFunc[] crFunc = new CreateFunc[3];
            crFunc[0] = CreateArtDataTable;
            crFunc[1] = CreateAltDataTable;
            crFunc[2] = CreateCardDataTable;

            if (!Directory.Exists(AppConfig.Path_Articles))
                Directory.CreateDirectory(AppConfig.Path_Articles);

            string[] artFiles = new string[3];
            artFiles[0] = AppConfig.Path_Articles + "\\" + string.Format("Art_{0:X2}.saf", AppConfig.APP_SubUnit);
            artFiles[1] = AppConfig.Path_Articles + "\\" + string.Format("Alt_{0:X2}.saf", AppConfig.APP_SubUnit);
            artFiles[2] = AppConfig.Path_Articles + "\\" + "DCards.saf";

            for (int i = 0; i < artFiles.Length; i++)
                if (localLoadedTempFiles != null && localLoadedTempFiles[i] != "")
                {
                    dTables[i] = crFunc[i].Invoke();
                    rdFunc[i].Invoke(localLoadedTempFiles[i], ref dTables[i]);
                    fs = new FileStream(artFiles[i], FileMode.Create);
                    binF.Serialize(fs, dTables[i]);
                    fs.Close();
                    fs.Dispose();
                    exchangeFldUsed = true;
                    if (!AppConfig.Content_Articles_KeepDataAfterImport)
                        Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile(localLoadedTempFiles[i], UIOption.AllDialogs, RecycleOption.SendToRecycleBin);
                }
                else
                {
                    if (!onlyUpdate && winapi.WApi.PathFileExists(artFiles[i]))
                    {
                        fs = new FileStream(artFiles[i], FileMode.Open, FileAccess.Read);
                        dTables[i] = (DataTable)binF.Deserialize(fs);
                        fs.Close();
                        fs.Dispose();
                    }
                }

            if (fs != null)
                fs.Dispose();

            object[] rez = new object[] { dTables, exchangeFldUsed };

            return rez;
        }
Exemple #25
0
 public ObjectPool(int capacity, CreateFunc onCreateObject, Transform storageNode)
     : this(capacity, onCreateObject, new OnOff <T>(), new Store <T>(storageNode))
 {
 }
Exemple #26
0
 public static void ReplaceByGeneratorComponent <T>(this IServiceContainer container, String name, CreateFunc <T> generator) where T : class
 {
     if (container == null)
     {
         throw new ArgumentNullException(nameof(container));
     }
     if (String.IsNullOrEmpty(name))
     {
         throw new ArgumentNullException(nameof(name));
     }
     if (generator == null)
     {
         throw new ArgumentNullException(nameof(generator));
     }
     ReplaceComponent <T>(container, name, new GeneratorContainerEntry <T>(generator));
 }
Exemple #27
0
 public static void ReplaceByLazyValueComponent(this IServiceContainer container, String name, Type type, CreateFunc <Object> initializer)
 {
     if (container == null)
     {
         throw new ArgumentNullException(nameof(container));
     }
     if (String.IsNullOrEmpty(name))
     {
         throw new ArgumentNullException(nameof(name));
     }
     if (type == null)
     {
         throw new ArgumentNullException(nameof(type));
     }
     if (initializer == null)
     {
         throw new ArgumentNullException(nameof(initializer));
     }
     ReplaceComponent(container, name, type, new LazyContainerEntry <Object>(initializer));
 }
 private static T NullFunc <T>()
 {
     return(CreateFunc <T>(Expr.Return(Expr.Null(typeof(T))))());
 }
Exemple #29
0
 public ObjectPool(int poolSize, CreateFunc createFunc = null, Action <T> resetAction = null)
 {
     Init(poolSize, createFunc, resetAction);
 }
 public ObjectPool(int capacity, CreateFunc createFunc = null, ResetFunc resetFunc = null)
 {
     pool            = new Stack <T>(capacity);
     this.createFunc = createFunc;
     this.resetFunc  = resetFunc;
 }
 private bool IsEqual <T1, T2>(T1 arg1, T2 arg2)
 {
     return(CreateFunc <T1, T2, bool>(Expr.Return(Expr.Equal(Expr.Parameter(0, typeof(T1)), Expr.Parameter(1, typeof(T2)))))(arg1, arg2));
 }
Exemple #32
0
 public ObjectPool(int capacity, CreateFunc onCreateObject)
     : this(capacity, onCreateObject, new OnOff <T>())
 {
 }