File: vtkADIOSDirTree.cxx

package info (click to toggle)
vtk7 7.1.1%2Bdfsg1-12
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 125,776 kB
  • sloc: cpp: 1,539,582; ansic: 106,521; python: 78,038; tcl: 47,013; xml: 8,142; yacc: 5,040; java: 4,439; perl: 3,132; lex: 1,926; sh: 1,500; makefile: 122; objc: 83
file content (212 lines) | stat: -rw-r--r-- 6,310 bytes parent folder | download | duplicates (2)
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkADIOSDirTree.cxx

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
#include <map>
#include <stdexcept>

#include "vtkADIOSDirTree.h"

//----------------------------------------------------------------------------
namespace {
void Tokenize(const std::string& str, std::vector<std::string> &tok,
  char d = '/')
{
  tok.clear();
  if(str.empty())
  {
    return;
  }

  size_t posPrev;
  for(posPrev = -1; str[posPrev+1] == d; ++posPrev); // Ignore leading delims
  size_t posCur;
  while((posCur = str.find(d, posPrev+1)) != std::string::npos)
  {
      if(posCur - posPrev > 1) // Only acknowledge non-empty path components
      {
        tok.push_back(str.substr(posPrev+1, posCur-posPrev-1));
      }
      posPrev = posCur;
  }

  if(posPrev != str.size()-1) // Only add teh last component if it's non-empty
  {
    tok.push_back(str.substr(posPrev+1, str.size()-posPrev-1));
  }
}
}

//----------------------------------------------------------------------------
void vtkADIOSDirTree::PrintSelf(std::ostream& os, vtkIndent indent) const
{
  vtkIndent indent2 = indent.GetNextIndent();

  os << indent << '"' << this->GetName() << '"' << std::endl;
  std::map<std::string, const ADIOS::Scalar*>::const_iterator s;
  for(s = this->Scalars.begin(); s != this->Scalars.end(); ++s)
  {
    os << indent2 << "S: " << s->first << std::endl;
  }

  std::map<std::string, const ADIOS::VarInfo*>::const_iterator a;
  for(a = this->Arrays.begin(); a != this->Arrays.end(); ++a)
  {
    os << indent2 << "A: " << a->first << std::endl;
  }

  std::map<std::string, vtkADIOSDirTree*>::const_iterator d;
  for(d = this->SubDirs.begin(); d != this->SubDirs.end(); ++d)
  {
    d->second->PrintSelf(os, indent2);
  }
}

//----------------------------------------------------------------------------
vtkADIOSDirTree::vtkADIOSDirTree(const std::string& name)
: Name(name)
{
}

//----------------------------------------------------------------------------
vtkADIOSDirTree::vtkADIOSDirTree(const ADIOS::Reader &reader)
: Name("")
{
  // Populate scalars
  std::vector<const ADIOS::Scalar*>::const_iterator s;
  const std::vector<const ADIOS::Scalar*>& scalars = reader.GetScalars();
  for(s = scalars.begin(); s != scalars.end(); ++s)
  {
    std::vector<std::string> path;
    Tokenize((*s)->GetName(), path);

    vtkADIOSDirTree *d = this->BuildPath(path, 0, path.size()-1);
    d->Scalars[*path.rbegin()] = *s;
    const_cast<ADIOS::Scalar*>(*s)->SetName(*path.rbegin());
  }

  // Populate arrays
  std::vector<const ADIOS::VarInfo*>::const_iterator a;
  const std::vector<const ADIOS::VarInfo*>& arrays = reader.GetArrays();
  for(a = arrays.begin(); a != arrays.end(); ++a)
  {
    std::vector<std::string> path;
    Tokenize((*a)->GetName(), path);

    vtkADIOSDirTree *d = this->BuildPath(path, 0, path.size()-1);
    d->Arrays[*path.rbegin()] = *a;
    const_cast<ADIOS::VarInfo*>(*a)->SetName(*path.rbegin());
  }
}

//----------------------------------------------------------------------------
vtkADIOSDirTree::~vtkADIOSDirTree()
{
  std::map<std::string, vtkADIOSDirTree*>::iterator d;
  for(d = this->SubDirs.begin(); d != this->SubDirs.end(); ++d)
  {
    delete d->second;
  }
}

//----------------------------------------------------------------------------
const vtkADIOSDirTree* vtkADIOSDirTree::GetDir(
  const std::string& dirName) const
{
  std::vector<std::string> path;
  Tokenize(dirName, path);

  return path.size() == 0 ? this : this->GetDir(path, 0);
}

//----------------------------------------------------------------------------
const vtkADIOSDirTree* vtkADIOSDirTree::GetDir(
  const std::vector<std::string>& path, size_t pIdx) const
{
  if(pIdx == path.size())
  {
    return this;
  }
  else
  {
    std::map<std::string, vtkADIOSDirTree*>::const_iterator i =
      this->SubDirs.find(path[pIdx]);

    return i == this->SubDirs.end() ? NULL : i->second->GetDir(path, pIdx+1);
  }
}

//----------------------------------------------------------------------------
const ADIOS::VarInfo* vtkADIOSDirTree::GetArray(
  const std::string& varName) const
{
  std::map<std::string, const ADIOS::VarInfo*>::const_iterator i =
    this->Arrays.find(varName);

  return i == this->Arrays.end() ? NULL : i->second;
}

//----------------------------------------------------------------------------
const ADIOS::Scalar* vtkADIOSDirTree::GetScalar(
  const std::string& varName) const
{
  std::map<std::string, const ADIOS::Scalar*>::const_iterator i =
    this->Scalars.find(varName);

  return i == this->Scalars.end() ? NULL : i->second;
}

//----------------------------------------------------------------------------
void vtkADIOSDirTree::GetScalars(
  std::vector<const ADIOS::Scalar*>& vars) const
{
  vars.clear();
  vars.reserve(this->Scalars.size());
  std::map<std::string, const ADIOS::Scalar*>::const_iterator i;
  for(i = this->Scalars.begin(); i != this->Scalars.end(); ++i)
  {
    vars.push_back(i->second);
  }
}

//----------------------------------------------------------------------------
void vtkADIOSDirTree::GetArrays(
  std::vector<const ADIOS::VarInfo*>& vars) const
{
  vars.clear();
  vars.reserve(this->Arrays.size());
  std::map<std::string, const ADIOS::VarInfo*>::const_iterator i;
  for(i = this->Arrays.begin(); i != this->Arrays.end(); ++i)
  {
    vars.push_back(i->second);
  }
}

//----------------------------------------------------------------------------
vtkADIOSDirTree* vtkADIOSDirTree::BuildPath(
  const std::vector<std::string>& path, size_t startIdx,
  size_t numComponents)
{
  if(numComponents == 0)
  {
    return this;
  }

  const std::string& name = path[startIdx];
  vtkADIOSDirTree*& d = this->SubDirs[name];
  if(!d)
  {
    d = new vtkADIOSDirTree(name);
  }
  return d->BuildPath(path, startIdx+1, numComponents-1);
}