nodenetcdf 4.9.33 → 4.9.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/Variable.h CHANGED
@@ -10,12 +10,46 @@
10
10
  namespace nodenetcdfjs
11
11
  {
12
12
 
13
+ /**
14
+ * @brief Represents a NetCDF variable wrapper for Node.js
15
+ *
16
+ * This class provides a Node.js interface to NetCDF variables, which are the primary
17
+ * data containers in NetCDF files. Variables store multi-dimensional arrays of values
18
+ * along with descriptive attributes. This class supports reading and writing data,
19
+ * configuring compression, chunking, endianness, and other storage properties.
20
+ *
21
+ * The class extends node::ObjectWrap to provide JavaScript binding capabilities,
22
+ * allowing variables to be manipulated from JavaScript code.
23
+ */
13
24
  class Variable : public node::ObjectWrap
14
25
  {
15
26
  public:
27
+ /**
28
+ * @brief Initialize the Variable class and register it with Node.js
29
+ * @param exports The exports object to attach the Variable constructor to
30
+ *
31
+ * This static method sets up the Variable class for use in Node.js,
32
+ * defining its constructor and prototype methods.
33
+ */
16
34
  static void Init(v8::Local<v8::Object> exports);
35
+
36
+ /**
37
+ * @brief Construct a Variable object
38
+ * @param id_ The variable ID in the NetCDF file
39
+ * @param parent_id_ The parent group/file ID
40
+ *
41
+ * Creates a new variable wrapper for an existing NetCDF variable.
42
+ */
17
43
  Variable(int id_, int parent_id_) noexcept;
18
44
 
45
+ /**
46
+ * @brief Get the name of this variable
47
+ * @param name Buffer to store the variable name
48
+ * @return true if successful, false otherwise
49
+ *
50
+ * Retrieves the variable name from the NetCDF file and stores it
51
+ * in the provided buffer.
52
+ */
19
53
  [[nodiscard]] bool get_name(char *name) const noexcept;
20
54
 
21
55
  private:
@@ -25,62 +59,309 @@ class Variable : public node::ObjectWrap
25
59
  Variable(Variable &&) = delete;
26
60
  Variable &operator=(Variable &&) = delete;
27
61
 
62
+ /**
63
+ * @brief Read the entire variable data
64
+ * @param args JavaScript function arguments
65
+ *
66
+ * Reads all data from the variable and returns it as a JavaScript array.
67
+ */
28
68
  static void Read(const v8::FunctionCallbackInfo<v8::Value> &args);
69
+
70
+ /**
71
+ * @brief Read a slice of variable data
72
+ * @param args JavaScript function arguments (start indices, counts)
73
+ *
74
+ * Reads a hyperslab of data from the variable, specified by start positions
75
+ * and count values for each dimension.
76
+ */
29
77
  static void ReadSlice(const v8::FunctionCallbackInfo<v8::Value> &args);
78
+
79
+ /**
80
+ * @brief Read a strided slice of variable data
81
+ * @param args JavaScript function arguments (start indices, counts, strides)
82
+ *
83
+ * Reads a strided hyperslab of data from the variable, with additional
84
+ * stride parameters to skip elements in each dimension.
85
+ */
30
86
  static void ReadStridedSlice(const v8::FunctionCallbackInfo<v8::Value> &args);
87
+
88
+ /**
89
+ * @brief Write data to the entire variable
90
+ * @param args JavaScript function arguments (data array)
91
+ *
92
+ * Writes data to all elements of the variable.
93
+ */
31
94
  static void Write(const v8::FunctionCallbackInfo<v8::Value> &args);
95
+
96
+ /**
97
+ * @brief Write data to a slice of the variable
98
+ * @param args JavaScript function arguments (start indices, counts, data)
99
+ *
100
+ * Writes a hyperslab of data to the variable, specified by start positions
101
+ * and count values for each dimension.
102
+ */
32
103
  static void WriteSlice(const v8::FunctionCallbackInfo<v8::Value> &args);
104
+
105
+ /**
106
+ * @brief Write data to a strided slice of the variable
107
+ * @param args JavaScript function arguments (start indices, counts, strides, data)
108
+ *
109
+ * Writes a strided hyperslab of data to the variable.
110
+ */
33
111
  static void WriteStridedSlice(const v8::FunctionCallbackInfo<v8::Value> &args);
112
+
113
+ /**
114
+ * @brief Add a new attribute to this variable
115
+ * @param args JavaScript function arguments (name, type, value)
116
+ *
117
+ * Creates a new attribute associated with this variable.
118
+ */
34
119
  static void AddAttribute(const v8::FunctionCallbackInfo<v8::Value> &args);
35
120
 
121
+ /**
122
+ * @brief Getter for the variable ID property
123
+ * @param property The property name being accessed
124
+ * @param info Callback info containing the return value
125
+ */
36
126
  static void GetId(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value> &info);
127
+
128
+ /**
129
+ * @brief Getter for the variable type property
130
+ * @param property The property name being accessed
131
+ * @param info Callback info containing the return value
132
+ *
133
+ * Returns the NetCDF data type of this variable (e.g., "int", "float", "double").
134
+ */
37
135
  static void GetType(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value> &info);
136
+
137
+ /**
138
+ * @brief Getter for the dimensions property
139
+ * @param property The property name being accessed
140
+ * @param info Callback info containing the return value
141
+ *
142
+ * Returns an array of dimension IDs for this variable.
143
+ */
38
144
  static void GetDimensions(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value> &info);
145
+
146
+ /**
147
+ * @brief Getter for the attributes property
148
+ * @param property The property name being accessed
149
+ * @param info Callback info containing the return value
150
+ *
151
+ * Returns an object containing all attributes of this variable.
152
+ */
39
153
  static void GetAttributes(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value> &info);
154
+
155
+ /**
156
+ * @brief Getter for the variable name property
157
+ * @param property The property name being accessed
158
+ * @param info Callback info containing the return value
159
+ */
40
160
  static void GetName(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value> &info);
161
+
162
+ /**
163
+ * @brief Setter for the variable name property
164
+ * @param property The property name being set
165
+ * @param val The new value to set
166
+ * @param info Callback info for the setter
167
+ */
41
168
  static void SetName(v8::Local<v8::String> property, v8::Local<v8::Value> val,
42
169
  const v8::PropertyCallbackInfo<void> &info);
170
+
171
+ /**
172
+ * @brief Getter for the endianness property
173
+ * @param property The property name being accessed
174
+ * @param info Callback info containing the return value
175
+ *
176
+ * Returns the byte order (endianness) of the variable data.
177
+ */
43
178
  static void GetEndianness(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value> &info);
179
+
180
+ /**
181
+ * @brief Setter for the endianness property
182
+ * @param property The property name being set
183
+ * @param val The new value to set
184
+ * @param info Callback info for the setter
185
+ */
44
186
  static void SetEndianness(v8::Local<v8::String> property, v8::Local<v8::Value> val,
45
187
  const v8::PropertyCallbackInfo<void> &info);
188
+
189
+ /**
190
+ * @brief Getter for the checksum mode property
191
+ * @param property The property name being accessed
192
+ * @param info Callback info containing the return value
193
+ *
194
+ * Returns the checksum/integrity checking mode for this variable.
195
+ */
46
196
  static void GetChecksumMode(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value> &info);
197
+
198
+ /**
199
+ * @brief Setter for the checksum mode property
200
+ * @param property The property name being set
201
+ * @param val The new value to set
202
+ * @param info Callback info for the setter
203
+ */
47
204
  static void SetChecksumMode(v8::Local<v8::String> property, v8::Local<v8::Value> val,
48
205
  const v8::PropertyCallbackInfo<void> &info);
206
+
207
+ /**
208
+ * @brief Getter for the chunk mode property
209
+ * @param property The property name being accessed
210
+ * @param info Callback info containing the return value
211
+ *
212
+ * Returns the chunking mode (contiguous or chunked storage).
213
+ */
49
214
  static void GetChunkMode(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value> &info);
215
+
216
+ /**
217
+ * @brief Setter for the chunk mode property
218
+ * @param property The property name being set
219
+ * @param val The new value to set
220
+ * @param info Callback info for the setter
221
+ */
50
222
  static void SetChunkMode(v8::Local<v8::String> property, v8::Local<v8::Value> val,
51
223
  const v8::PropertyCallbackInfo<void> &info);
224
+
225
+ /**
226
+ * @brief Getter for the chunk sizes property
227
+ * @param property The property name being accessed
228
+ * @param info Callback info containing the return value
229
+ *
230
+ * Returns an array of chunk sizes for each dimension.
231
+ */
52
232
  static void GetChunkSizes(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value> &info);
233
+
234
+ /**
235
+ * @brief Setter for the chunk sizes property
236
+ * @param property The property name being set
237
+ * @param val The new value to set
238
+ * @param info Callback info for the setter
239
+ */
53
240
  static void SetChunkSizes(v8::Local<v8::String> property, v8::Local<v8::Value> val,
54
241
  const v8::PropertyCallbackInfo<void> &info);
242
+
243
+ /**
244
+ * @brief Getter for the fill mode property
245
+ * @param property The property name being accessed
246
+ * @param info Callback info containing the return value
247
+ *
248
+ * Returns whether fill values are enabled for this variable.
249
+ */
55
250
  static void GetFillMode(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value> &info);
251
+
252
+ /**
253
+ * @brief Setter for the fill mode property
254
+ * @param property The property name being set
255
+ * @param val The new value to set
256
+ * @param info Callback info for the setter
257
+ */
56
258
  static void SetFillMode(v8::Local<v8::String> property, v8::Local<v8::Value> val,
57
259
  const v8::PropertyCallbackInfo<void> &info);
260
+
261
+ /**
262
+ * @brief Getter for the fill value property
263
+ * @param property The property name being accessed
264
+ * @param info Callback info containing the return value
265
+ *
266
+ * Returns the fill value used for uninitialized data.
267
+ */
58
268
  static void GetFillValue(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value> &info);
269
+
270
+ /**
271
+ * @brief Setter for the fill value property
272
+ * @param property The property name being set
273
+ * @param val The new value to set
274
+ * @param info Callback info for the setter
275
+ */
59
276
  static void SetFillValue(v8::Local<v8::String> property, v8::Local<v8::Value> val,
60
277
  const v8::PropertyCallbackInfo<void> &info);
278
+
279
+ /**
280
+ * @brief Getter for the compression shuffle property
281
+ * @param property The property name being accessed
282
+ * @param info Callback info containing the return value
283
+ *
284
+ * Returns whether byte shuffle filter is enabled (improves compression).
285
+ */
61
286
  static void GetCompressionShuffle(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value> &info);
287
+
288
+ /**
289
+ * @brief Setter for the compression shuffle property
290
+ * @param property The property name being set
291
+ * @param val The new value to set
292
+ * @param info Callback info for the setter
293
+ */
62
294
  static void SetCompressionShuffle(v8::Local<v8::String> property, v8::Local<v8::Value> val,
63
295
  const v8::PropertyCallbackInfo<void> &info);
296
+
297
+ /**
298
+ * @brief Getter for the compression deflate property
299
+ * @param property The property name being accessed
300
+ * @param info Callback info containing the return value
301
+ *
302
+ * Returns whether deflate (gzip) compression is enabled.
303
+ */
64
304
  static void GetCompressionDeflate(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value> &info);
305
+
306
+ /**
307
+ * @brief Setter for the compression deflate property
308
+ * @param property The property name being set
309
+ * @param val The new value to set
310
+ * @param info Callback info for the setter
311
+ */
65
312
  static void SetCompressionDeflate(v8::Local<v8::String> property, v8::Local<v8::Value> val,
66
313
  const v8::PropertyCallbackInfo<void> &info);
314
+
315
+ /**
316
+ * @brief Getter for the compression level property
317
+ * @param property The property name being accessed
318
+ * @param info Callback info containing the return value
319
+ *
320
+ * Returns the compression level (0-9, where 9 is maximum compression).
321
+ */
67
322
  static void GetCompressionLevel(v8::Local<v8::String> property, const v8::PropertyCallbackInfo<v8::Value> &info);
323
+
324
+ /**
325
+ * @brief Setter for the compression level property
326
+ * @param property The property name being set
327
+ * @param val The new value to set
328
+ * @param info Callback info for the setter
329
+ */
68
330
  static void SetCompressionLevel(v8::Local<v8::String> property, v8::Local<v8::Value> val,
69
331
  const v8::PropertyCallbackInfo<void> &info);
332
+
333
+ /**
334
+ * @brief Custom inspect method for Node.js console output
335
+ * @param args JavaScript function arguments
336
+ */
70
337
  static void Inspect(const v8::FunctionCallbackInfo<v8::Value> &args);
338
+
339
+ /**
340
+ * @brief Convert variable to JSON representation
341
+ * @param args JavaScript function arguments
342
+ */
71
343
  static void ToJSON(const v8::FunctionCallbackInfo<v8::Value> &args);
72
344
 
345
+ /// Persistent reference to the JavaScript constructor function
73
346
  static v8::Persistent<v8::Function> constructor;
74
347
 
75
- // Use constexpr arrays for compile-time constants
348
+ /// Size in bytes for each NetCDF data type
76
349
  static constexpr std::array<unsigned char, 11> type_sizes = {1, 1, 2, 4, 4, 8, 1, 2, 4, 8, 0};
77
350
 
351
+ /// String names for each NetCDF data type
78
352
  static constexpr std::array<const char *, 11> type_names = {"byte", "char", "short", "int", "float", "double",
79
353
  "ubyte", "ushort", "uint", "int64", "string"};
80
354
 
355
+ /// The variable ID in the NetCDF file
81
356
  int id{-1};
357
+
358
+ /// The parent group/file ID
82
359
  int parent_id{-1};
360
+
361
+ /// The NetCDF data type of this variable
83
362
  nc_type type{NC_NAT};
363
+
364
+ /// Number of dimensions for this variable
84
365
  int ndims{0};
85
366
  };
86
367
 
@@ -7,15 +7,56 @@
7
7
  #include <string_view>
8
8
  #include <unordered_map>
9
9
 
10
+ /**
11
+ * @file nodenetcdfjs.h
12
+ * @brief Core utilities and type mappings for the NetCDF4 Node.js binding
13
+ *
14
+ * This header provides utility functions and type conversion mappings used
15
+ * throughout the NetCDF4 Node.js binding library.
16
+ */
17
+
10
18
  namespace nodenetcdfjs
11
19
  {
12
20
 
21
+ /**
22
+ * @brief Throw a JavaScript exception with a NetCDF error message
23
+ * @param isolate The V8 isolate for the current JavaScript context
24
+ * @param retval The NetCDF error code returned from a NetCDF library function
25
+ * @throws v8::Exception::TypeError with the NetCDF error description
26
+ *
27
+ * This function converts NetCDF error codes into human-readable error messages
28
+ * and throws them as JavaScript TypeErrors. It uses nc_strerror() to get the
29
+ * error description from the NetCDF library.
30
+ *
31
+ * @note This function is marked noexcept(false) to indicate it may throw
32
+ */
13
33
  inline void throw_netcdf_error(v8::Isolate *isolate, int retval) noexcept(false)
14
34
  {
15
35
  isolate->ThrowException(v8::Exception::TypeError(
16
36
  v8::String::NewFromUtf8(isolate, nc_strerror(retval), v8::NewStringType::kNormal).ToLocalChecked()));
17
37
  }
18
38
 
39
+ /**
40
+ * @brief Convert a type name string to a NetCDF type constant
41
+ * @param type_str The string representation of the type (e.g., "int", "float", "double")
42
+ * @return The corresponding NetCDF type constant (e.g., NC_INT, NC_FLOAT, NC_DOUBLE)
43
+ * @retval NC_NAT if the type string is not recognized
44
+ *
45
+ * This function performs a compile-time mapping from human-readable type names
46
+ * to NetCDF type constants. The following types are supported:
47
+ * - "byte" -> NC_BYTE (signed 8-bit integer)
48
+ * - "char" -> NC_CHAR (8-bit character)
49
+ * - "short" -> NC_SHORT (signed 16-bit integer)
50
+ * - "int" -> NC_INT (signed 32-bit integer)
51
+ * - "float" -> NC_FLOAT (32-bit floating point)
52
+ * - "double" -> NC_DOUBLE (64-bit floating point)
53
+ * - "ubyte" -> NC_UBYTE (unsigned 8-bit integer)
54
+ * - "ushort" -> NC_USHORT (unsigned 16-bit integer)
55
+ * - "uint" -> NC_UINT (unsigned 32-bit integer)
56
+ * - "string" -> NC_STRING (variable-length string)
57
+ *
58
+ * @note This function is constexpr, allowing it to be evaluated at compile time
59
+ */
19
60
  [[nodiscard]] constexpr int get_type(std::string_view type_str) noexcept
20
61
  {
21
62
  constexpr std::pair<std::string_view, int> type_map[] = {