vtkGenericIOUtilities.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Kitware Inc.
2 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
3 // SPDX-License-Identifier: BSD-3-Clause
12 #ifndef vtkGenericIOUtilities_h
13 #define vtkGenericIOUtilities_h
14 
15 #include "vtkType.h" // for vtkIdType
16 
17 #include <algorithm> // for std::find_if
18 #include <functional> // for std::ptr_fun
19 #include <string> // for std::string
20 
21 #include "vtk_mpi.h" // MPI
22 
24 class vtkDataArray;
25 
26 namespace gio
27 {
28 class GenericIOReader;
29 class GenericIOWriter;
30 }
31 
33 {
34 
35 //==============================================================================
37 
40 inline std::string& ltrim(std::string& s)
41 {
42  s.erase(
43  s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
44  return s;
45 }
47 
48 //==============================================================================
50 
53 inline std::string& rtrim(std::string& s)
54 {
55  s.erase(
56  std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(),
57  s.end());
58  return s;
59 }
61 
62 //==============================================================================
66 inline std::string& trim(std::string& s)
67 {
68  return ltrim(rtrim(s));
69 }
70 
71 //==============================================================================
77 
78 //==============================================================================
84 vtkDataArray* GetVtkDataArray(std::string name, int type, void* rawBuffer, int N);
85 
86 //==============================================================================
92 vtkIdType GetIdFromRawBuffer(const int type, void* buffer, vtkIdType buffer_idx);
93 
94 //==============================================================================
100 double GetDoubleFromRawBuffer(const int type, void* buffer, vtkIdType buffer_idx);
101 
102 //==============================================================================
106 gio::GenericIOReader* GetReader(
107  MPI_Comm comm, bool posix, int distribution, const std::string& fileName);
108 
109 //==============================================================================
114 gio::GenericIOWriter* GetWriter(MPI_Comm comm, const std::string& fileName);
115 
116 //==============================================================================
118 
123 inline void SafeDeleteString(char*& str)
124 {
125  if (str != nullptr)
126  {
127  delete[] str;
128  str = nullptr;
129  }
130 }
132 }
133 
134 #endif /* vtkGenericIOUtilities_h */
135 // VTK-HeaderTest-Exclude: vtkGenericIOUtilities.h
void SafeDeleteString(char *&str)
If the pointer given is non-nullptr this function deletes the string and set the pointer to nullptr...
type
MPI_Comm GetMPICommunicator(vtkMultiProcessController *mpc)
Returns the corresponding MPI communicator for the multi-process controller used by this instance...
gio::GenericIOWriter * GetWriter(MPI_Comm comm, const std::string &fileName)
This method constructs and returns the underlying GenericIO writer.
std::string & trim(std::string &s)
Trims leading & trailing whitespace from a string.
int vtkIdType
double GetDoubleFromRawBuffer(const int type, void *buffer, vtkIdType buffer_idx)
This method accesses the user-supplied buffer at the given index and returns the data as a double...
std::string & ltrim(std::string &s)
Trims leading whitespace from a string.
vtkIdType GetIdFromRawBuffer(const int type, void *buffer, vtkIdType buffer_idx)
This method accesses the user-supplied buffer at the given index and returns the data as a vtkIdType...
vtkDataArray * GetVtkDataArray(std::string name, int type, void *rawBuffer, int N)
This method parses the data in the rawbuffer and reads it into a vtkDataArray that can be attached as...
name
std::string & rtrim(std::string &s)
Trims trailing whitespace from a string.
gio::GenericIOReader * GetReader(MPI_Comm comm, bool posix, int distribution, const std::string &fileName)
This method constructs and returns the underlying GenericIO reader.