1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165 | /**
* MOAB, a Mesh-Oriented datABase, is a software component for creating,
* storing and accessing finite element mesh data.
*
* Copyright 2004 Sandia Corporation. Under the terms of Contract
* DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
* retains certain rights in this software.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
*/
#include <H5Tpublic.h>
#include <H5Gpublic.h>
#include <H5Ppublic.h>
#include "mhdf.h"
#include "util.h"
#include "file-handle.h"
#include "status.h"
#include "names-and-paths.h"
int mhdf_haveAdjacency( mhdf_FileHandle file, const char* elem_group, mhdf_Status* status )
{
FileHandle* file_ptr;
hid_t elem_id;
int result;
API_BEGIN;
file_ptr = (FileHandle*)( file );
if( !mhdf_check_valid_file( file_ptr, status ) ) return -1;
if( elem_group == mhdf_node_type_handle() )
{
#if defined( H5Gopen_vers ) && H5Gopen_vers > 1
elem_id = H5Gopen( file_ptr->hdf_handle, NODE_GROUP, H5P_DEFAULT );
#else
elem_id = H5Gopen( file_ptr->hdf_handle, NODE_GROUP );
#endif
if( elem_id < 0 )
{
mhdf_setFail( status, "H5Gopen( \"%s\" ) failed.\n", NODE_GROUP );
return -1;
}
}
else
{
elem_id = mhdf_elem_group_from_handle( file_ptr, elem_group, status );
if( elem_id < 0 ) return -1;
}
result = mhdf_is_in_group( elem_id, ADJACENCY_NAME, status );
H5Gclose( elem_id );
mhdf_setOkay( status );
API_END;
return result;
}
hid_t mhdf_createAdjacency( mhdf_FileHandle file, const char* elem_handle, long adj_list_size, mhdf_Status* status )
{
FileHandle* file_ptr;
hid_t elem_id, table_id;<--- The scope of the variable 'elem_id' can be reduced. [+]The scope of the variable 'elem_id' can be reduced. Warning: Be careful when fixing this message, especially when there are inner loops. Here is an example where cppcheck will write that the scope for 'i' can be reduced:
void f(int x)
{
int i = 0;
if (x) {
// it's safe to move 'int i = 0;' here
for (int n = 0; n < 10; ++n) {
// it is possible but not safe to move 'int i = 0;' here
do_something(&i);
}
}
}
When you see this message it is always safe to reduce the variable scope 1 level.
hsize_t dim = (hsize_t)adj_list_size;
API_BEGIN;
file_ptr = (FileHandle*)( file );
if( !mhdf_check_valid_file( file_ptr, status ) ) return -1;
if( adj_list_size < 1 )
{
mhdf_setFail( status, "Invalid argument.\n" );
return -1;
}
if( elem_handle == mhdf_node_type_handle() )
{
table_id = mhdf_create_table( file_ptr->hdf_handle, NODE_ADJCY_PATH, file_ptr->id_type, 1, &dim, status );
}
else
{
elem_id = mhdf_elem_group_from_handle( file_ptr, elem_handle, status );
if( elem_id < 0 ) return -1;
table_id = mhdf_create_table( elem_id, ADJACENCY_NAME, file_ptr->id_type, 1, &dim, status );
H5Gclose( elem_id );
}
API_END_H( 1 );
return table_id;
}
hid_t mhdf_openAdjacency( mhdf_FileHandle file, const char* elem_handle, long* adj_list_size_out, mhdf_Status* status )
{
FileHandle* file_ptr;
hid_t elem_id, table_id;<--- The scope of the variable 'elem_id' can be reduced. [+]The scope of the variable 'elem_id' can be reduced. Warning: Be careful when fixing this message, especially when there are inner loops. Here is an example where cppcheck will write that the scope for 'i' can be reduced:
void f(int x)
{
int i = 0;
if (x) {
// it's safe to move 'int i = 0;' here
for (int n = 0; n < 10; ++n) {
// it is possible but not safe to move 'int i = 0;' here
do_something(&i);
}
}
}
When you see this message it is always safe to reduce the variable scope 1 level.
hsize_t dim;
API_BEGIN;
file_ptr = (FileHandle*)( file );
if( !mhdf_check_valid_file( file_ptr, status ) ) return -1;
if( !adj_list_size_out )
{
mhdf_setFail( status, "Invalid argument.\n" );
return -1;
}
if( elem_handle == mhdf_node_type_handle() )
{
table_id = mhdf_open_table( file_ptr->hdf_handle, NODE_ADJCY_PATH, 1, &dim, status );
}
else
{
elem_id = mhdf_elem_group_from_handle( file_ptr, elem_handle, status );
if( elem_id < 0 ) return -1;
table_id = mhdf_open_table( elem_id, ADJACENCY_NAME, 1, &dim, status );
H5Gclose( elem_id );
}
*adj_list_size_out = (long)dim;
API_END_H( 1 );
return table_id;
}
void mhdf_writeAdjacency( hid_t table_id, long offset, long count, hid_t type, const void* data, mhdf_Status* status )<--- The function 'mhdf_writeAdjacency' is never used.
{
API_BEGIN;
mhdf_write_data( table_id, offset, count, type, data, H5P_DEFAULT, status );
API_END;
}
void mhdf_writeAdjacencyWithOpt( hid_t table_id,
long offset,
long count,
hid_t type,
const void* data,
hid_t prop,
mhdf_Status* status )
{
API_BEGIN;
mhdf_write_data( table_id, offset, count, type, data, prop, status );
API_END;
}
void mhdf_readAdjacency( hid_t table_id, long offset, long count, hid_t type, void* data, mhdf_Status* status )
{
API_BEGIN;
mhdf_read_data( table_id, offset, count, type, data, H5P_DEFAULT, status );
API_END;
}
void mhdf_readAdjacencyWithOpt( hid_t table_id,
long offset,
long count,
hid_t type,
void* data,
hid_t prop,
mhdf_Status* status )
{
API_BEGIN;
mhdf_read_data( table_id, offset, count, type, data, prop, status );
API_END;
}
|