vtkGenericIOUtilities.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkGenericIOUtilities.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
23 #ifndef vtkGenericIOUtilities_h
24 #define vtkGenericIOUtilities_h
25 
26 #include "vtkType.h"
27 
28 #include <algorithm>
29 #include <functional>
30 #include <string>
31 
32 #include "vtk_mpi.h"
33 
35 class vtkDataArray;
36 
37 namespace gio
38 {
39 class GenericIOReader;
40 class GenericIOWriter;
41 }
42 
44 {
45 
46 //==============================================================================
48 
51 inline std::string& ltrim(std::string& s)
52 {
53  s.erase(
54  s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
55  return s;
56 }
58 
59 //==============================================================================
61 
64 inline std::string& rtrim(std::string& s)
65 {
66  s.erase(
67  std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(),
68  s.end());
69  return s;
70 }
72 
73 //==============================================================================
77 inline std::string& trim(std::string& s)
78 {
79  return ltrim(rtrim(s));
80 }
81 
82 //==============================================================================
88 
89 //==============================================================================
95 vtkDataArray* GetVtkDataArray(std::string name, int type, void* rawBuffer, int N);
96 
97 //==============================================================================
103 vtkIdType GetIdFromRawBuffer(const int type, void* buffer, vtkIdType buffer_idx);
104 
105 //==============================================================================
111 double GetDoubleFromRawBuffer(const int type, void* buffer, vtkIdType buffer_idx);
112 
113 //==============================================================================
117 gio::GenericIOReader* GetReader(
118  MPI_Comm comm, bool posix, int distribution, const std::string& fileName);
119 
120 //==============================================================================
125 gio::GenericIOWriter* GetWriter(MPI_Comm comm, const std::string& fileName);
126 
127 //==============================================================================
129 
134 inline void SafeDeleteString(char*& str)
135 {
136  if (str != NULL)
137  {
138  delete[] str;
139  str = NULL;
140  }
141 }
143 }
144 
145 #endif /* vtkGenericIOUtilities_h */
146 // VTK-HeaderTest-Exclude: vtkGenericIOUtilities.h
void SafeDeleteString(char *&str)
If the pointer given is non-null this function deletes the string and set the pointer to NULL...
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.