ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
vtkStringList.cxx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ParaView
4  Module: vtkStringList.cxx
5 
6  Copyright (c) Kitware, Inc.
7  All rights reserved.
8  See Copyright.txt or http://www.paraview.org/HTML/Copyright.html 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 =========================================================================*/
15 #include "vtkStringList.h"
16 
17 #include "vtkObjectFactory.h"
18 
19 #include <algorithm>
20 #include <iterator>
21 #include <stdarg.h>
22 #include <vector>
23 
24 class vtkStringList::vtkInternals
25 {
26 public:
27  std::vector<std::string> Strings;
28 };
29 
30 //----------------------------------------------------------------------------
32 
33 //----------------------------------------------------------------------------
35  : Internals(new vtkStringList::vtkInternals())
36 {
37 }
38 
39 //----------------------------------------------------------------------------
41 {
42 }
43 
44 //----------------------------------------------------------------------------
46 {
47  this->Internals->Strings.clear();
48 }
49 
50 //----------------------------------------------------------------------------
51 int vtkStringList::GetIndex(const char* str)
52 {
53  if (!str)
54  {
55  return -1;
56  }
57  const auto& internals = (*this->Internals);
58  auto iter = std::find(internals.Strings.begin(), internals.Strings.end(), std::string(str));
59  return (iter == internals.Strings.end() ? -1 : static_cast<int>(
60  std::distance(internals.Strings.begin(), iter)));
61 }
62 
63 //----------------------------------------------------------------------------
64 const char* vtkStringList::GetString(int idx)
65 {
66  const auto& internals = (*this->Internals);
67  if (idx < 0 || idx >= static_cast<int>(internals.Strings.size()))
68  {
69  return NULL;
70  }
71 
72  return internals.Strings[idx].c_str();
73 }
74 
75 //----------------------------------------------------------------------------
76 void vtkStringList::AddString(const char* str)
77 {
78  if (!str)
79  {
80  return;
81  }
82 
83  auto& internals = (*this->Internals);
84  internals.Strings.push_back(str);
85 }
86 
87 //----------------------------------------------------------------------------
88 void vtkStringList::AddUniqueString(const char* str)
89 {
90  if (this->GetIndex(str) >= 0)
91  {
92  return;
93  }
94  this->AddString(str);
95 }
96 
97 //----------------------------------------------------------------------------
99 {
100  static char event[16000];
101 
102  va_list var_args;
103  va_start(var_args, format);
104  vsprintf(event, format, var_args);
105  va_end(var_args);
106 
107  this->AddString(event);
108 }
109 
110 //----------------------------------------------------------------------------
111 void vtkStringList::SetString(int idx, const char* str)
112 {
113  if (str == nullptr)
114  {
115  return;
116  }
117 
118  auto& internals = (*this->Internals);
119  if (idx >= static_cast<int>(internals.Strings.size()))
120  {
121  internals.Strings.resize(idx + 1);
122  }
123  internals.Strings[idx] = str;
124 }
125 
126 //----------------------------------------------------------------------------
128 {
129  const auto& internals = (*this->Internals);
130  return static_cast<int>(internals.Strings.size());
131 }
132 
133 //----------------------------------------------------------------------------
134 void vtkStringList::PrintSelf(ostream& os, vtkIndent indent)
135 {
136  int idx, num;
137 
138  this->Superclass::PrintSelf(os, indent);
139  num = this->GetNumberOfStrings();
140  os << indent << "NumberOfStrings: " << num << endl;
141  for (idx = 0; idx < num; ++idx)
142  {
143  os << idx << ": " << this->GetString(idx) << endl;
144  }
145 }
MouseEvent event
filament::Texture::InternalFormat format
#define NULL
void RemoveAllItems()
int GetNumberOfStrings()
void PrintSelf(ostream &os, vtkIndent indent) override
void SetString(int idx, const char *str)
void AddFormattedString(const char *EventString,...)
const char * GetString(int idx)
~vtkStringList() override
void AddString(const char *str)
int GetIndex(const char *str)
void AddUniqueString(const char *str)
QTextStream & endl(QTextStream &stream)
Definition: QtCompat.h:718
static double distance(T *pot1, T *pot2)
Definition: utils.h:111
vtkStandardNewMacro(vtkStringList)