コード例 #1
0
        internal override void deepCopy(TObject.Version source_)
        {
            TArrayVersion <T> source = (TArrayVersion <T>)source_;

            base.deepCopy(source);
            merge(source, true);
        }
コード例 #2
0
        internal override TObject.Version merge(TObject.Version target, TObject.Version next, bool threadPrivate)
        {
            TArrayVersion <T> source = (TArrayVersion <T>)next;
            TArrayVersion <T> merged = (TArrayVersion <T>)base.merge(target, next, threadPrivate);

            merged.merge(source, false);
            return(merged);
        }
コード例 #3
0
        //

        public override void writeWrite(Writer writer, int index)
        {
            if (writer.interrupted())
            {
                writer.resume();
            }

            if (IS_TOBJECT)
            {
                writer.writeTObject((TObject)(object)get(index));

                if (writer.interrupted())
                {
                    writer.interrupt(null);
                    return;
                }
            }
            else if (typeof(T) == typeof(bool))
            {
                if (!writer.canWriteBoolean())
                {
                    writer.interrupt(null);
                    return;
                }

                TArrayVersion <bool> version = (TArrayVersion <bool>)(object) this;
                writer.writeBoolean(version.get(index));
            }
            else if (typeof(T) == typeof(byte))
            {
                if (!writer.canWriteByte())
                {
                    writer.interrupt(null);
                    return;
                }

                TArrayVersion <byte> version = (TArrayVersion <byte>)(object) this;
                writer.writeByte(version.get(index));
            }
            else if (typeof(T) == typeof(char))
            {
                if (!writer.canWriteCharacter())
                {
                    writer.interrupt(null);
                    return;
                }

                TArrayVersion <char> version = (TArrayVersion <char>)(object) this;
                writer.writeCharacter(version.get(index));
            }
            else if (typeof(T) == typeof(short))
            {
                if (!writer.canWriteShort())
                {
                    writer.interrupt(null);
                    return;
                }

                TArrayVersion <short> version = (TArrayVersion <short>)(object) this;
                writer.writeShort(version.get(index));
            }
            else if (typeof(T) == typeof(int))
            {
                if (!writer.canWriteInteger())
                {
                    writer.interrupt(null);
                    return;
                }

                TArrayVersion <int> version = (TArrayVersion <int>)(object) this;
                writer.writeInteger(version.get(index));
            }
            else if (typeof(T) == typeof(long))
            {
                if (!writer.canWriteLong())
                {
                    writer.interrupt(null);
                    return;
                }

                TArrayVersion <long> version = (TArrayVersion <long>)(object) this;
                writer.writeLong(version.get(index));
            }
            else if (typeof(T) == typeof(float))
            {
                if (!writer.canWriteFloat())
                {
                    writer.interrupt(null);
                    return;
                }

                TArrayVersion <float> version = (TArrayVersion <float>)(object) this;
                writer.writeFloat(version.get(index));
            }
            else if (typeof(T) == typeof(double))
            {
                if (!writer.canWriteDouble())
                {
                    writer.interrupt(null);
                    return;
                }

                TArrayVersion <double> version = (TArrayVersion <double>)(object) this;
                writer.writeDouble(version.get(index));
            }
            else if (typeof(T) == typeof(string))
            {
                TArrayVersion <string> version = (TArrayVersion <string>)(object) this;
                writer.writeString(version.get(index));

                if (writer.interrupted())
                {
                    writer.interrupt(null);
                    return;
                }
            }
            else if (typeof(T) == typeof(System.DateTime?))
            {
                if (!writer.canWriteDate())
                {
                    writer.interrupt(null);
                    return;
                }

                TArrayVersion <System.DateTime?> version = (TArrayVersion <System.DateTime?>)(object) this;
                writer.writeDate(version.get(index));
            }
            else if (typeof(T) == typeof(System.Numerics.BigInteger?))
            {
                TArrayVersion <System.Numerics.BigInteger?> version = (TArrayVersion <System.Numerics.BigInteger?>)(object) this;
                writer.writeBigInteger(version.get(index));

                if (writer.interrupted())
                {
                    writer.interrupt(null);
                    return;
                }
            }
            else if (typeof(T) == typeof(decimal?))
            {
                TArrayVersion <decimal?> version = (TArrayVersion <decimal?>)(object) this;
                writer.writeDecimal(version.get(index));

                if (writer.interrupted())
                {
                    writer.interrupt(null);
                    return;
                }
            }
            else if (typeof(T) == typeof(byte[]))
            {
                TArrayVersion <byte[]> version = (TArrayVersion <byte[]>)(object) this;
                writer.writeBinary(version.get(index));

                if (writer.interrupted())
                {
                    writer.interrupt(null);
                    return;
                }
            }
            else
            {
                UnknownObjectSerializer.write(writer, get(index));

                if (writer.interrupted())
                {
                    writer.interrupt(null);
                    return;
                }
            }
        }
コード例 #4
0
        // TODO simplify
        // @SuppressWarnings("cast")
        private void merge(TArrayVersion <T> source, bool deep)
        {
            bool skip1 = _values == null;

            if (skip1)
            {
                if (getBits() != null && source.getBits() != null)
                {
                    if (getBits().Length != source.getBits().Length)
                    {
                        skip1 = false;
                    }
                }
            }

            if (skip1)
            {
                if (!source.bitsEmpty() && source._values != null)
                {
                    if (deep)
                    {
                        int arrayLength = source._values.Length;
                        _values = new T[arrayLength][];

                        for (int i = _values.Length - 1; i >= 0; i--)
                        {
                            if (source._values[i] != null)
                            {
                                arrayLength = org.objectfabric.Bits.BITS_PER_UNIT;
                                _values[i]  = new T[arrayLength];
                                Platform.arraycopy(source._values[i], 0, _values[i], 0, _values[i].Length);
                            }
                        }
                    }
                    else
                    {
                        _values = source._values;
                    }
                }
            }
            else
            {
                org.objectfabric.Bits.Entry[] writes = source.getBits();

                if (writes != null)
                {
                    for (int i = writes.Length - 1; i >= 0; i--)
                    {
                        if (writes[i] != null && writes[i].Value != 0)
                        {
                            if (_values == null)
                            {
                                int arrayLength = getBits().Length;
                                _values = new T[arrayLength][];
                            }

                            int  folded = org.objectfabric.Bits.getFoldedIntIndexFromIntIndex(getBits(), writes[i].IntIndex);
                            bool skip2  = false;

                            if (!deep)
                            {
                                skip2 = _values[folded] == null;

                                if (!skip2) // All overwritten
                                {
                                    skip2 = writes[i].Value == -1 && source._values != null && source._values[i] != null;
                                }
                            }
                            else if (_values[folded] == null)
                            {
                                int arrayLength = org.objectfabric.Bits.BITS_PER_UNIT;
                                _values[folded] = new T[arrayLength];
                            }

                            if (skip2)
                            {
                                _values[folded] = source._values != null ? source._values[i] : null;
                            }
                            else
                            {
                                merge(_values[folded], writes[i], source._values != null ? source._values[i] : null);
                            }
                        }
                    }
                }
            }

            if (org.objectfabric.Debug.ENABLED)
            {
                checkInvariants();
            }
        }