MemberPathMap.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / ndp / fx / src / DataEntity / System / Data / Map / ViewGeneration / Structures / MemberPathMap.cs / 2 / MemberPathMap.cs

                            //---------------------------------------------------------------------- 
// 
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// 
// @owner [....]
// @backupOwner [....] 
//--------------------------------------------------------------------- 

using System.Collections.Generic; 
using System.Text;
using System.Data.Common.Utils;

namespace System.Data.Mapping.ViewGeneration.Structures { 

    /// Maps member paths to a dense space of integers, e.g., so that one can 
    /// store memberpaths in arrays and use array indexes for easy and 
    /// efficient handling
    internal class MemberPathMap : MemberPathMapBase { 

        #region Constructor
        // effects: Creates an empty map
        internal MemberPathMap() { 
            m_indexMap = new Dictionary(MemberPath.EqualityComparer);
            m_members = new List(); 
        } 
        #endregion
 
        #region Fields
        // A dictionary to get us from paths to indexes and an array for the
        // other way around
        private Dictionary m_indexMap; 
        private List m_members;
        #endregion 
 
        #region MemberPathMapBase Properties
        // effects: See MemberPathMapBase.Count 
        internal override int Count {
            get {return m_members.Count; }
        }
 
        // effects: See MemberPathMapBase.indexer
        internal override MemberPath this[int index] { 
            get { return m_members[index]; } 
        }
 
        // effects: Returns the indexes of the key slots corresponding to
        // fields in this for which IsPartOfKey is true
        internal override IEnumerable KeySlots {
            get { 
                List result = new List();
                for (int slotNum = 0; slotNum < Count; slotNum++) { 
                    // We pass for numboolslots since we know that this is not a 
                    // bool slot
                    if (ProjectedSlot.IsKeySlot(slotNum, this, 0)) { 
                        result.Add(slotNum);
                    }
                }
                return result; 
            }
        } 
 
        // effects: returns an enumeration of all members
        internal override IEnumerable Members 
        {
            get { return m_members; }
        }
        #endregion 

        #region MemberPathMapBase Methods 
        // effects: See MemberPathMapBase.IndexOf 
        internal override int IndexOf(MemberPath member) {
            int index; 
            if (m_indexMap.TryGetValue(member, out index)) {
                return index;
            } else {
                return -1; 
            }
        } 
        #endregion 

        #region Other Methods 
        // effects: If an index already exists for member, this is a
        // noop. Else creates the next index available for member and returns it
        internal int CreateIndex(MemberPath member) {
            int index; 
            if (false == m_indexMap.TryGetValue(member, out index)) {
                index = m_indexMap.Count; 
                m_indexMap[member] = index; 
                m_members.Add(member);
            } 
            return index;
        }

        internal override void ToCompactString(StringBuilder builder) { 
            builder.Append('<');
            StringUtil.ToCommaSeparatedString(builder, m_members); 
            builder.Append('>'); 
        }
 
        #endregion
    }

} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//---------------------------------------------------------------------- 
// 
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// 
// @owner [....]
// @backupOwner [....] 
//--------------------------------------------------------------------- 

using System.Collections.Generic; 
using System.Text;
using System.Data.Common.Utils;

namespace System.Data.Mapping.ViewGeneration.Structures { 

    /// Maps member paths to a dense space of integers, e.g., so that one can 
    /// store memberpaths in arrays and use array indexes for easy and 
    /// efficient handling
    internal class MemberPathMap : MemberPathMapBase { 

        #region Constructor
        // effects: Creates an empty map
        internal MemberPathMap() { 
            m_indexMap = new Dictionary(MemberPath.EqualityComparer);
            m_members = new List(); 
        } 
        #endregion
 
        #region Fields
        // A dictionary to get us from paths to indexes and an array for the
        // other way around
        private Dictionary m_indexMap; 
        private List m_members;
        #endregion 
 
        #region MemberPathMapBase Properties
        // effects: See MemberPathMapBase.Count 
        internal override int Count {
            get {return m_members.Count; }
        }
 
        // effects: See MemberPathMapBase.indexer
        internal override MemberPath this[int index] { 
            get { return m_members[index]; } 
        }
 
        // effects: Returns the indexes of the key slots corresponding to
        // fields in this for which IsPartOfKey is true
        internal override IEnumerable KeySlots {
            get { 
                List result = new List();
                for (int slotNum = 0; slotNum < Count; slotNum++) { 
                    // We pass for numboolslots since we know that this is not a 
                    // bool slot
                    if (ProjectedSlot.IsKeySlot(slotNum, this, 0)) { 
                        result.Add(slotNum);
                    }
                }
                return result; 
            }
        } 
 
        // effects: returns an enumeration of all members
        internal override IEnumerable Members 
        {
            get { return m_members; }
        }
        #endregion 

        #region MemberPathMapBase Methods 
        // effects: See MemberPathMapBase.IndexOf 
        internal override int IndexOf(MemberPath member) {
            int index; 
            if (m_indexMap.TryGetValue(member, out index)) {
                return index;
            } else {
                return -1; 
            }
        } 
        #endregion 

        #region Other Methods 
        // effects: If an index already exists for member, this is a
        // noop. Else creates the next index available for member and returns it
        internal int CreateIndex(MemberPath member) {
            int index; 
            if (false == m_indexMap.TryGetValue(member, out index)) {
                index = m_indexMap.Count; 
                m_indexMap[member] = index; 
                m_members.Add(member);
            } 
            return index;
        }

        internal override void ToCompactString(StringBuilder builder) { 
            builder.Append('<');
            StringUtil.ToCommaSeparatedString(builder, m_members); 
            builder.Append('>'); 
        }
 
        #endregion
    }

} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK