コード例 #1
0
        static void InitializeHandle(out uint handle,
                                     int engineIndex, int branchIndex, int revisionIndex)
        {
            var encoder = new Bitwise.HandleBitEncoder();

            EngineBuildRevision.BitEncodeIndex(ref encoder, revisionIndex);
            EngineBuildBranch.BitEncodeIndex(ref encoder, branchIndex);
            BlamEngine.BitEncodeIndex(ref encoder, engineIndex);

            Contract.Assert(encoder.UsedBitCount == EngineBuildHandle.BitCount);

            handle = encoder.GetHandle32();
        }
コード例 #2
0
        static int RevisionIdResolver(EngineBuildBranch branch, int version)
        {
            int id = TypeExtensions.kNone;

            if (version.IsNotNone())
            {
                id = branch.Revisions.FindIndex(x => x.Version == version);

                if (id.IsNone())
                {
                    throw new KeyNotFoundException(string.Format("Engine branch {0} doesn't define a revision for version #{1}",
                                                                 branch.Name, version));
                }
            }

            return(id);
        }
コード例 #3
0
        /// <summary>Serialize a build handle, using a 'baseline' to populate or cull (from writing) root build information</summary>
        /// <param name="s"></param>
        /// <param name="baseline">Root build information (ie, engine, or engine and branch)</param>
        /// <param name="value"></param>
        public static void SerializeWithBaseline <TDoc, TCursor>(IO.TagElementStream <TDoc, TCursor, string> s,
                                                                 EngineBuildHandle baseline,
                                                                 ref EngineBuildHandle value)
            where TDoc : class
            where TCursor : class
        {
            int engine_index             = baseline.EngineIndex;
            int branch_index             = baseline.BranchIndex;
            int revisn_index             = baseline.RevisionIndex;
            EngineBuildRepository repo   = null;
            EngineBuildBranch     branch = null;

            if (s.IsWriting)
            {
                #region prepare engine_index
                if (value.EngineIndex == engine_index)
                {
                    repo = EngineRegistry.Engines[engine_index].BuildRepository;
                    // cause engine_index not to be written
                    engine_index = TypeExtensions.kNone;
                }
                else
                {
                    engine_index = value.EngineIndex;
                }
                #endregion

                #region prepare branch_index
                if (value.BranchIndex == branch_index)
                {
                    branch = repo.Branches[branch_index];
                    // cause branch_index not to be written
                    branch_index = TypeExtensions.kNone;
                }
                else
                {
                    branch_index = value.BranchIndex;
                }
                #endregion

                #region prepare revisn_index
                if (value.BranchIndex == revisn_index)
                {
                    // cause branch_index not to be written
                    branch_index = TypeExtensions.kNone;
                }
                else
                {
                    revisn_index = value.RevisionIndex;
                }
                #endregion
            }

            // This is a logic driven mess, but having branches for both IsReading and IsWriting would result in more copy&paste code

            // reading: baseline EngineIndex is valid, or index is serialized
            // writing: value EngineIndex mismatches baseline
            if (engine_index.IsNotNone() || BlamEngine.SerializeId(s, kAttributeNameEngine, ref engine_index, true))
            {
                repo = EngineRegistry.Engines[engine_index].BuildRepository;
            }

            // precondition: someone's EngineIndex was valid
            // reading: baseline BranchIndex is valid, or index is serialized
            // writing: value BranchIndex mismatches baseline
            if (repo != null && (branch_index.IsNotNone() || repo.SerializeBranchId(s, kAttributeNameBranch, ref branch_index, true)))
            {
                branch = repo.Branches[branch_index];
            }

            // precondition: someone's BranchIndex was valid
            // reading: baseline RevisionIndex is valid
            // writing: value RevisionIndex mismatches baseline
            if (branch != null && (revisn_index.IsNotNone() || s.IsReading))
            {
                branch.SerializeRevisionId(s, kAttributeNameRevisn, ref revisn_index, true);
            }

            if (s.IsReading)
            {
                if (engine_index.IsNotNone())
                {
                    value = new EngineBuildHandle(engine_index, branch_index, revisn_index);
                }
                else                 // engine_index is NONE, don't even bother trying to encode a new handle that should be all NONE anyway
                {
                    value = EngineBuildHandle.None;
                }
            }
        }
コード例 #4
0
        /// <summary>Tests whether this handle and the branch's are of the same <see cref="Engine"/> and <see cref="Branch"/></summary>
        /// <param name="branch">The branch to compare with</param>
        /// <returns></returns>
        /// <remarks>If either handle in this equation <see cref="IsNone"/>, this will return false</remarks>
        public bool IsWithinSameBranch(EngineBuildBranch branch)
        {
            Contract.Requires(branch != null);

            return(this.IsWithinSameBranch(branch.BranchHandle));
        }