Пример #1
0
        internal bool TryGetReference(H5ObjectReference reference, HashSet <ulong> alreadyVisited, H5LinkAccess linkAccess, int recursionLevel, out H5NamedReference namedReference)
        {
            // similar to H5Gint.c (H5G_visit)
            if (recursionLevel >= 100)
            {
                throw new Exception("Too much recursion.");
            }

            bool skip = false;

            namedReference = default;

            /* If its ref count is > 1, we add it to the list of visited objects
             * (because it could come up again during traversal) */
            if (this.ReferenceCount > 1)
            {
                if (alreadyVisited.Contains(this.Reference.Value))
                {
                    skip = true;
                }
                else
                {
                    alreadyVisited.Add(this.Reference.Value);
                }
            }

            if (!skip)
            {
                var references = this
                                 .EnumerateReferences(linkAccess)
                                 .ToList();

                namedReference = references
                                 .FirstOrDefault(current => current.Value == reference.Value);

                if (namedReference.Name != null /* if struct value is not equal to default */)
                {
                    return(true);
                }
                else
                {
                    // search childs for reference
                    foreach (var childReference in references)
                    {
                        var group = childReference.Dereference() as H5Group;

                        if (group != null)
                        {
                            if (group.TryGetReference(reference, alreadyVisited, linkAccess, recursionLevel + 1, out namedReference))
                            {
                                return(true);
                            }
                        }
                    }
                }
            }

            return(false);
        }
Пример #2
0
        public H5Object Get(H5ObjectReference reference, H5LinkAccess linkAccess = default)
        {
            if (this.Reference.Value == reference.Value)
            {
                return(this);
            }

            return(this
                   .InternalGet(reference, linkAccess)
                   .Dereference());
        }
Пример #3
0
        internal H5NamedReference InternalGet(H5ObjectReference reference, H5LinkAccess linkAccess)
        {
            var alreadyVisted = new HashSet <ulong>();

            if (this.TryGetReference(reference, alreadyVisted, linkAccess, recursionLevel: 0, out var namedReference))
            {
                return(namedReference);
            }
            else
            {
                throw new Exception($"Could not find object for reference with value '{reference.Value:X}'.");
            }
        }