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 "H5GroupsList.hxx"
17 
18 namespace org_modules_hdf5
19 {
20 
H5GroupsList(H5Object & _parent)21 H5GroupsList::H5GroupsList(H5Object & _parent) : H5ListObject<H5Group>(_parent) { }
22 
~H5GroupsList()23 H5GroupsList::~H5GroupsList() { }
24 
getSize() const25 const unsigned int H5GroupsList::getSize() const
26 {
27     H5G_info_t info;
28     hsize_t count = 0;
29     hid_t parentId = getParent().getH5Id();
30     herr_t err = H5Gget_info(parentId, &info);
31 
32     if (err < 0)
33     {
34         throw H5Exception(__LINE__, __FILE__, _("Cannot get the number of groups."));
35     }
36 
37     for (hsize_t i = 0; i < info.nlinks; i++)
38     {
39         int type = H5Gget_objtype_by_idx(parentId, i);
40         if (type == H5G_GROUP)
41         {
42             count++;
43         }
44     }
45 
46     return (unsigned int)count;
47 }
48 
setObject(const unsigned int pos,H5Group & obj)49 void H5GroupsList::setObject(const unsigned int pos, H5Group & obj)
50 {
51 
52 }
53 
getObject(const int pos)54 H5Group & H5GroupsList::getObject(const int pos)
55 {
56     return getObject(pos, true);
57 }
58 
getObject(const int pos,const bool checkPos)59 H5Group & H5GroupsList::getObject(const int pos, const bool checkPos)
60 {
61     int type;
62     herr_t err;
63     hsize_t count = 0;
64     hsize_t index = 0;
65     hid_t parentId = getParent().getH5Id();
66     ssize_t nameSize;
67     char * name = 0;
68 
69     if (checkPos)
70     {
71         unsigned int size = getSize();
72         if (pos < 0 || pos >= size)
73         {
74             throw H5Exception(__LINE__, __FILE__, _("Invalid index %d: must be between 0 and %d."), pos, size);
75         }
76     }
77 
78     err = H5Gget_info(parentId, &info);
79     if (err < 0)
80     {
81         throw H5Exception(__LINE__, __FILE__, _("Cannot get the number of groups."));
82     }
83 
84     for (; index < info.nlinks; index++)
85     {
86         int type = H5Gget_objtype_by_idx(parentId, index);
87         if (type == H5G_GROUP)
88         {
89             count++;
90             if (count == pos)
91             {
92                 break;
93             }
94         }
95     }
96 
97     nameSize = H5Gget_objname_by_idx(parentId, index, 0, 0);
98     name = (char *)MALLOC((nameSize + 1) * sizeof(char));
99     H5Gget_objname_by_idx(parentId, index, name, nameSize + 1);
100 
101     return *new H5Group(getParent(), name);
102 }
103 
dump(const unsigned int indentLevel) const104 std::string H5GroupsList::dump(const unsigned int indentLevel) const
105 {
106     std::ostringstream os;
107     const unsigned int size = getSize();
108 
109     for (unsigned int i = 0; i < size; i++)
110     {
111         const H5Group & group = const_cast<H5GroupsList *>(this)->getObject(i, false);
112         os << group.toString(indentLevel) << std::endl;
113 
114         delete &group;
115     }
116 
117     return os.str();
118 }
119 
toString(const unsigned int indentLevel) const120 std::string H5GroupsList::toString(const unsigned int indentLevel) const
121 {
122 
123 }
124 }
125