1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2012 - Scilab Enterprises - Calixte DENIZET
4  *
5  * Copyright (C) 2012 - 2016 - Scilab Enterprises
6  *
7  * This file is hereby licensed under the terms of the GNU GPL v2.0,
8  * pursuant to article 5.3.4 of the CeCILL v.2.1.
9  * This file was originally licensed under the terms of the CeCILL v2.1,
10  * and continues to be available under such terms.
11  * For more information, see the COPYING file which you should have received
12  * along with this program.
13  *
14  */
15 
16 #include "H5LinksList.hxx"
17 
18 namespace org_modules_hdf5
19 {
H5LinksList(H5Object & _parent)20 H5LinksList::H5LinksList(H5Object & _parent) : H5ListObject<H5Object>(_parent) { }
21 
~H5LinksList()22 H5LinksList::~H5LinksList() { }
23 
getSize() const24 const unsigned int H5LinksList::getSize() const
25 {
26     H5G_info_t info;
27     herr_t err = H5Gget_info(getParent().getH5Id(), &info);
28 
29     if (err < 0)
30     {
31         throw H5Exception(__LINE__, __FILE__, _("Cannot get the number of links."));
32     }
33 
34     return (unsigned int)info.nlinks;
35 }
36 
setObject(const unsigned int pos,H5Object & obj)37 void H5LinksList::setObject(const unsigned int pos, H5Object & obj)
38 {
39 
40 }
41 
getObject(const int pos)42 H5Object & H5LinksList::getObject(const int pos)
43 {
44     return getObject(pos, true);
45 }
46 
getObject(const int pos,const bool checkPos)47 H5Object & H5LinksList::getObject(const int pos, const bool checkPos)
48 {
49     if (checkPos)
50     {
51         unsigned int size = getSize();
52         if (pos < 0 || pos >= size)
53         {
54             throw H5Exception(__LINE__, __FILE__, _("Invalid index %d: must be between 0 and %d."), pos, size);
55         }
56     }
57 
58     H5Object * obj = 0;
59     hid_t parentId = getParent().getH5Id();
60     ssize_t nameSize = H5Gget_objname_by_idx(parentId, (hsize_t)pos, 0, 0);
61     char * name = (char *)MALLOC((nameSize + 1) * sizeof(char));
62     H5Gget_objname_by_idx(parentId, (hsize_t)pos, name, nameSize + 1);
63     int type = H5Gget_objtype_by_idx(parentId, (hsize_t)pos);
64 
65     switch (type)
66     {
67         case H5G_LINK:
68             obj = &H5Link::getLink(getParent(), name);
69             break;
70         case H5G_GROUP:
71             obj = new H5Group(getParent(), name);
72             break;
73         case H5G_DATASET:
74             obj = new H5Dataset(getParent(), name);
75             break;
76         case H5G_TYPE:
77             obj = new H5Type(getParent(), name);
78             break;
79     }
80 
81     return *obj;
82 }
83 
dump(std::map<haddr_t,std::string> & alreadyVisited,const unsigned int indentLevel) const84 std::string H5LinksList::dump(std::map<haddr_t, std::string> & alreadyVisited, const unsigned int indentLevel) const
85 {
86     std::ostringstream os;
87     const unsigned int size = getSize();
88 
89     for (unsigned int i = 0; i < size; i++)
90     {
91         const H5Object & obj = const_cast<H5LinksList *>(this)->getObject(i, false);
92         os << obj.dump(alreadyVisited, indentLevel);
93 
94         delete &obj;
95     }
96 
97     return os.str();
98 }
99 
toString(const unsigned int indentLevel) const100 std::string H5LinksList::toString(const unsigned int indentLevel) const
101 {
102     return "";
103 }
104 }
105