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(s.begin(), std::find_if(s.begin(), s.end(), [](int ch) { return !std::isspace(ch); }));
43  return s;
44 }
46 
47 //==============================================================================
49 
52 inline std::string& rtrim(std::string& s)
53 {
54  s.erase(
55  std::find_if(s.rbegin(), s.rend(), [](int ch) { return !std::isspace(ch); }).base(), s.end());
56  return s;
57 }
59 
60 //==============================================================================
64 inline std::string& trim(std::string& s)
65 {
66  return ltrim(rtrim(s));
67 }
68 
69 //==============================================================================
75 
76 //==============================================================================
82 vtkDataArray* GetVtkDataArray(std::string name, int type, void* rawBuffer, int N);
83 
84 //==============================================================================
90 vtkIdType GetIdFromRawBuffer(const int type, void* buffer, vtkIdType buffer_idx);
91 
92 //==============================================================================
98 double GetDoubleFromRawBuffer(const int type, void* buffer, vtkIdType buffer_idx);
99 
100 //==============================================================================
104 gio::GenericIOReader* GetReader(
105  MPI_Comm comm, bool posix, int distribution, const std::string& fileName);
106 
107 //==============================================================================
112 gio::GenericIOWriter* GetWriter(MPI_Comm comm, const std::string& fileName);
113 
114 //==============================================================================
116 
121 inline void SafeDeleteString(char*& str)
122 {
123  if (str != nullptr)
124  {
125  delete[] str;
126  str = nullptr;
127  }
128 }
130 }
131 
132 #endif /* vtkGenericIOUtilities_h */
133 // 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.