Exemple #1
0
        internal unsafe SSSPCell_Accessor(long CellID, ActionOnCellNotFound action)
        {
            int tmp;

            CellPtr = Global.LocalStorage.GetLockedUnsafeCellLocation(CellID, out tmp, out CellEntryIndex);
            if (CellPtr == null)
            {
                if (action == ActionOnCellNotFound.ThrowException)
                {
                    throw new CellNotFoundException("Cell with ID=" + CellID + " not found!");
                }
                else if (action == ActionOnCellNotFound.CreateNew)
                {
                    int    size;
                    byte[] defaultContent = construct(CellID);
                    CellPtr = Global.LocalStorage.AddOrUse(CellID, out size, out CellEntryIndex, defaultContent, (ushort)CellType.SSSPCell);
                }
                else
                {
                    this.CellID = -1;
                    return;
                }
            }

            neighbors_Accessor_Field = new longList(null,
                                                    (ptr, ptr_offset, delta) =>
            {
                int substructure_offset = (int)(ptr - this.CellPtr);
                this.ResizeFunction(this.CellPtr, ptr_offset + substructure_offset, delta);
                return(this.CellPtr + substructure_offset);
            });

            this.CellID = CellID;
        }
Exemple #2
0
        internal static SSSPCell_Accessor New(long CellID, ActionOnCellNotFound action)
        {
            if (accessorPool == null)
            {
                accessorPool = new Stack <SSSPCell_Accessor>();
            }
            SSSPCell_Accessor ret = null;

            if (accessorPool.Count != 0)
            {
                ret = accessorPool.Pop();
                int tmp;
                ret.CellPtr = Global.LocalStorage.GetLockedUnsafeCellLocation(CellID, out tmp, out ret.CellEntryIndex);
                if (ret.CellPtr == null)
                {
                    if (action == ActionOnCellNotFound.ThrowException)
                    {
                        throw new CellNotFoundException("Cell with ID=" + CellID + " not found!");
                    }
                    else if (action == ActionOnCellNotFound.CreateNew)
                    {
                        int    size;
                        byte[] defaultContent = construct(CellID);
                        ret.CellPtr = Global.LocalStorage.AddOrUse(CellID, out size, out ret.CellEntryIndex, defaultContent, (ushort)CellType.SSSPCell);
                    }
                    else
                    {
                        accessorPool.Push(ret);
                        return(null);
                    }
                }
                ret.CellID = CellID;
                return(ret);
            }
            ret = new SSSPCell_Accessor(CellID, action);
            if (ret.CellID == -1 && CellID != -1)
            {
                return(null);
            }
            else
            {
                return(ret);
            }
        }
Exemple #3
0
 public unsafe static SSSPCell_Accessor UseSSSPCell(this Trinity.Storage.LocalMemoryStorage storage, long CellID, ActionOnCellNotFound action)
 {
     return(SSSPCell_Accessor.New(CellID, action));
 }