This file is indexed.

/usr/include/tulip/CSVGraphImport.h is in libtulip-dev 4.4.0dfsg2-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
/*
 *
 * This file is part of Tulip (www.tulip-software.org)
 *
 * Authors: David Auber and the Tulip development Team
 * from LaBRI, University of Bordeaux 1 and Inria Bordeaux - Sud Ouest
 *
 * Tulip is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation, either version 3
 * of the License, or (at your option) any later version.
 *
 * Tulip is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 */
///@cond DOXYGEN_HIDDEN

#ifndef CSVGRAPHIMPORT_H
#define CSVGRAPHIMPORT_H

#include <tulip/CSVContentHandler.h>
#include <tulip/Graph.h>
#include <tulip/tulipconf.h>

#include <QMessageBox>

namespace tlp {
class PropertyInterface;

/**
  * @brief Store import parameters for a CSV file column.
  *
  * Contains all the parameters defined by user for a given CSV column (the name of the column, its data type and if user want to import it).
  **/
class TLP_QT_SCOPE CSVColumn {
public:
  CSVColumn(const std::string& columnName="",bool isUsed=false,const std::string& columnType=""):name(columnName),used(isUsed),type(columnType) {

  }

  /**
    * @brief Get the name of the column.
    **/
  std::string columnName()const {
    return name;
  }

  /**
    * @brief Tells if the property marked for import.
    **/
  bool isUsed()const {
    return used;
  }
  /**
    * @brief Return the property data type.
    **/
  std::string columnDataType()const {
    return type;
  }

private:
  std::string name;
  bool used;
  std::string type;
};
/**
  * @brief Store all the advanced import parameters for the CSV file.
  *
  * Store the information about columns and rows to import.
  * Use this object to configure the import process of a CSVImportGraph object.
  **/
class TLP_QT_SCOPE CSVImportParameters {
public:
  CSVImportParameters(unsigned int fromLine=0,unsigned int toLine=UINT_MAX,const std::vector<CSVColumn>& columns = std::vector<CSVColumn>());
  virtual ~CSVImportParameters();

  /**
    * @brief Return the number of column.
    **/
  unsigned int columnNumber()const;

  /**
    * @brief return true if the column is marked for import.
    **/
  bool importColumn(unsigned int column)const;
  /**
    * @brief Get the column name.
    **/
  std::string getColumnName(unsigned int column)const;
  /**
    * @brief Get the column data type.
    **/
  std::string getColumnDataType(unsigned int column)const;

  /**
    * @brief Return the index of the first line to import.
    **/
  unsigned int getFirstLineIndex()const;
  /**
    * @brief Return the index of the last line to import.
    **/
  unsigned int getLastLineIndex()const;
  /**
    * @brief Return true if the given row is between the first row to import and the last row to import.
    **/
  bool importRow(unsigned int row)const;
private:
  unsigned int fromLine;
  unsigned int toLine;
  std::vector<CSVColumn> columns;
};

/**
  * @brief Interface to map CSV rows to graph elements.
  *
  * To build the mapping user had to parse the CSV file.
  * @code
  * CSVParser *parser;
  * CSVToGraphDataMapping *mapping;
  * parser->parse(mapping);
  * //Now the mapping has been built.
  * //Get the element for the first row.
  * pair<tlp::ElementType,unsigned int> element = mapping->getElementForRow(0);
  * @endcode
  **/
class TLP_QT_SCOPE CSVToGraphDataMapping {
public:
  virtual ~CSVToGraphDataMapping() {}
  virtual std::pair<tlp::ElementType,unsigned int> getElementForRow(const std::vector<std::string>& tokens)=0;
  virtual void init(unsigned int rowNumber)=0;
};

/**
  * @brief Abstract class handling node or edge mapping between a CSV column and a graph property.
  *
  * Be sure there is a property with the given name in the graph or an error will occur.
  * Automatically handle CSV file parsing just implements the buildIndexForRow function to fill the rowToGraphId map with the right graph element.
  **/
class TLP_QT_SCOPE AbstractCSVToGraphDataMapping : public CSVToGraphDataMapping {
public:
  AbstractCSVToGraphDataMapping(tlp::Graph* graph,tlp::ElementType type,unsigned int columnIndex,const std::string& propertyName);
  virtual ~AbstractCSVToGraphDataMapping() {}

  void init(unsigned int rowNumber);
  std::pair<tlp::ElementType,unsigned int> getElementForRow(const std::vector<std::string>& tokens);
protected:
  /**
    * @brief Create a new element if no elements for the given row was found.
    * @return Return the graph element id or UINT_MAX if no new element is created.
    **/
  virtual unsigned int buildIndexForRow(unsigned int row,const std::string& indexKey,tlp::Graph* graph,tlp::PropertyInterface* keyProperty)=0;

protected:
  TLP_HASH_MAP<std::string,unsigned int> valueToId;
  tlp::Graph* graph;
  tlp::ElementType type;
  unsigned int columnIndex;
  tlp::PropertyInterface* keyProperty;
};
/**
  * @brief Map each row of the CSV file on a new node.
  **/
class TLP_QT_SCOPE CSVToNewNodeIdMapping: public CSVToGraphDataMapping {
public:
  CSVToNewNodeIdMapping(tlp::Graph* graph);
  void init(unsigned int rowNumber);
  std::pair<tlp::ElementType,unsigned int> getElementForRow(const std::vector<std::string>& tokens);
private:
  tlp::Graph* graph;
};

/**
  * @brief Try to map CSV file rows to nodes according to value between a CSV column and a graph property.
  *
  * Be sure there is a property with the given name in the graph before using it.
  **/
class TLP_QT_SCOPE CSVToGraphNodeIdMapping: public AbstractCSVToGraphDataMapping {
public:
  /**
    * @param graph The graph where the nodes will be searched.
    * @param columnIndex The index of the column with the ids in the CSV file.
    * @param propertyName The name of the property to search ids.
    * @param firstRow The first row to search ids.
    * @param lastRow The last row to search ids.
    * @param createNode If set to true if there is no node for an id in the CSV file a new node will be created for this id.
    **/
  CSVToGraphNodeIdMapping(tlp::Graph* graph,unsigned int columnIndex,const std::string& propertyName,bool createNode=false);
  void init(unsigned int rowNumber);
protected:
  unsigned int buildIndexForRow(unsigned int row,const std::string& indexKey,tlp::Graph* graph,tlp::PropertyInterface* keyProperty);
private:
  bool createMissingNodes;
};
/**
  * @brief Try to map CSV file rows to edges according to value between a CSV column and a graph property.
  *
  * Be sure there is a property with the given name in the graph before using it.
  **/
class TLP_QT_SCOPE CSVToGraphEdgeIdMapping: public AbstractCSVToGraphDataMapping {
public:
  /**
  * @param graph The graph where the edges will be searched.
  * @param columnIndex The index of the column with the ids in the CSV file.
  * @param propertyName The name of the property to search ids.
  * @param firstRow The first row to search ids.
  * @param lastRow The last row to search ids.
  **/
  CSVToGraphEdgeIdMapping(tlp::Graph* graph,unsigned int columnIndex,const std::string& propertyName);
protected:
  unsigned int buildIndexForRow(unsigned int row,const std::string& indexKey,tlp::Graph* graph,tlp::PropertyInterface* keyProperty);
};

/**
  * @brief Try to map CSV file rows to edges according to edge source and destination.
  *
  * For each row in the CSV file create an edge in the graph between source and destination nodes. Find source node by comparing id in the source CSV column and destination node by comparing id in the destination CSV column.
  **/
class TLP_QT_SCOPE CSVToGraphEdgeSrcTgtMapping: public CSVToGraphDataMapping {
public:
  /**
  * @param graph The graph where the edges will be searched.
  * @param srcColumnIndex The index of the column with the source node id in the CSV file.
  * @param tgtColumnIndex The index of the column with the taret node id in the CSV file.
  * @param srcPropertyName The name of the property to search source node id.
  * @param tgtPropertyName The name of the property to search target node id.
  * @param firstRow The first row to search ids.
  * @param lastRow The last row to search ids.
  * @param createMissinElements If true create source node, destination node if one of them is not found in the graph.
  **/
  CSVToGraphEdgeSrcTgtMapping(tlp::Graph* graph,unsigned int srcColumnIndex,unsigned int tgtColumnIndex,const std::string& propertyName,bool createMissinElements=false);
  std::pair<tlp::ElementType,unsigned int> getElementForRow(unsigned int row);
  void init(unsigned int lineNumbers);
  std::pair<tlp::ElementType,unsigned int> getElementForRow(const std::vector<std::string>& tokens);
private:
  tlp::Graph* graph;
  TLP_HASH_MAP<std::string,unsigned int> valueToId;
  unsigned int srcColumnIndex;
  unsigned int tgtColumnIndex;
  tlp::PropertyInterface* keyProperty;
  bool buildMissingElements;
};

/**
  * @brief Interface to perform mapping between CSV columns and graph properties during the CSV import process.
  *
  **/
class TLP_QT_SCOPE CSVImportColumnToGraphPropertyMapping {
public:
  virtual ~CSVImportColumnToGraphPropertyMapping() {}
  /**
    * @brief Return the property corresponding to the column index.
    * @param column The index of the column.
    * @param token The current token. May be needed to determine column data type.
    *
    * The token parameter is used to guess property type if needed.
    **/
  virtual tlp::PropertyInterface* getPropertyInterface(unsigned int column,const std::string& token)=0;
};

/**
  * @brief Proxy to handle all the properties operations like access, creation, data type detection during the CSV parsing process.
  *
  * Try to guess the type of the property in function of the first token if user don't tell which type the property is.
  **/
class TLP_QT_SCOPE CSVImportColumnToGraphPropertyMappingProxy : public CSVImportColumnToGraphPropertyMapping {
public:
  CSVImportColumnToGraphPropertyMappingProxy(tlp::Graph* graph,const CSVImportParameters& importParameters,QWidget* parent=NULL);
  virtual ~CSVImportColumnToGraphPropertyMappingProxy() {}
  tlp::PropertyInterface* getPropertyInterface(unsigned int column,const std::string& token);

private:

  tlp::Graph* graph;
  CSVImportParameters importParameters;
  TLP_HASH_MAP<unsigned int,tlp::PropertyInterface*>propertiesBuffer;
  QMessageBox::StandardButton overwritePropertiesButton;
  QWidget* parent;
};

/**
  * @brief Manage all the CSV import process. Use the mapping object to find the graph element in function of the row and the propertiesManager to find the property corresponding to the column.
  * The import parameters are used to filter the rows and the columns to import.
  **/
class TLP_QT_SCOPE CSVGraphImport : public tlp::CSVContentHandler {
public:
  CSVGraphImport(CSVToGraphDataMapping* mapping,CSVImportColumnToGraphPropertyMapping* propertiesManager,const CSVImportParameters& importParameters);
  virtual ~CSVGraphImport();
  void begin();
  void line(unsigned int row,const std::vector<std::string>& lineTokens);
  void end(unsigned int rowNumber, unsigned int columnNumber);
protected:

  CSVToGraphDataMapping* mapping;
  CSVImportColumnToGraphPropertyMapping* propertiesManager;
  CSVImportParameters importParameters;
};

}
#endif // CSVGRAPHIMPORT_H
///@endcond