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 "H5Link.hxx"
17 #include "H5SoftLink.hxx"
18 #include "H5ExternalLink.hxx"
19 #include "H5HardLink.hxx"
20 #include "H5Object.hxx"
21 
22 namespace org_modules_hdf5
23 {
24 
H5Link(H5Object & _parent,const std::string & _name)25 H5Link::H5Link(H5Object & _parent, const std::string & _name) : H5Object(_parent, _name)
26 {
27     if (H5Lexists(_parent.getH5Id(), name.c_str(), H5P_DEFAULT) <= 0)
28     {
29         throw H5Exception(__LINE__, __FILE__, _("The link %s does not exist."), name.c_str());
30     }
31 }
32 
~H5Link()33 H5Link::~H5Link()
34 {
35 
36 }
37 
getLink(H5Object & _parent,const std::string & _name)38 H5Link & H5Link::getLink(H5Object & _parent, const std::string & _name)
39 {
40     return getLink(_parent, _name.c_str());
41 }
42 
getLink(H5Object & _parent,const char * _name)43 H5Link & H5Link::getLink(H5Object & _parent, const char * _name)
44 {
45     herr_t err;
46     H5L_info_t info;
47     H5Link * link = 0;
48     err = H5Lget_info(_parent.getH5Id(), _name, &info, H5P_DEFAULT);
49 
50     if (err < 0)
51     {
52         throw H5Exception(__LINE__, __FILE__, _("Cannot get the link info"));
53     }
54 
55     switch (info.type)
56     {
57         case H5L_TYPE_HARD:
58             link = new H5HardLink(_parent, _name);
59             break;
60         case H5L_TYPE_SOFT:
61             link = new H5SoftLink(_parent, _name);
62             break;
63         case H5L_TYPE_EXTERNAL:
64             link = new H5ExternalLink(_parent, _name);
65             break;
66         case H5L_TYPE_ERROR:
67         default:
68             throw H5Exception(__LINE__, __FILE__, _("Invalid link type: %s."), _name);
69     }
70 
71     return *link;
72 }
73 }
74