1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkBoostSplitTableField.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 =========================================================================*/
15 /**
16  * @class   vtkBoostSplitTableField
17  * @brief   "Splits" one-or-more table fields by duplicating rows containing delimited data.
18  *
19  *
20  * Assume the following table:
21  *
22  * Author                Year     Title
23  * Brian; Jeff; Tim      2007     Foo
24  * Tim                   2003     Bar
25  *
26  * If we produce a graph relating authors to the year in which they publish, the string
27  * "Brian; Jeff; Tim" will be treated (incorrectly) as a single author associated with
28  * the year 2007.  vtkBoostSplitTableField addresses this by splitting one-or-more fields into
29  * "subvalues" using a configurable delimiter and placing each subvalue on its own row
30  * (the other fields in the original row are copied).  Using the above example, splitting
31  * the "Author" field with a ";" (semicolon) delimiter produces:
32  *
33  * Author                Year     Title
34  * Brian                 2007     Foo
35  * Jeff                  2007     Foo
36  * Tim                   2007     Foo
37  * Tim                   2003     Bar
38  *
39  * When this table is converted to a graph, each author (correctly) becomes a separate node.
40  *
41  * Usage:
42  *
43  * Use AddField() to specify the field(s) to be split.  If no fields have been specified,
44  * vtkBoostSplitTableField will act as a passthrough.  By default, no fields are specified.
45  *
46  * The second argument to AddField() is a string containing zero-to-many single character
47  * delimiters (multi-character delimiters are not supported).
48  *
49  * If the input table is missing a field specified by AddField(), it is an error.
50  * If no fields are specified, no splitting is performed.
51  * If the delimiter for a field is an empty string, no splitting is performed on that field.
52 */
53 
54 #ifndef vtkBoostSplitTableField_h
55 #define vtkBoostSplitTableField_h
56 
57 #include "vtkInfovisBoostGraphAlgorithmsModule.h" // For export macro
58 #include "vtkTableAlgorithm.h"
59 
60 class vtkStringArray;
61 
62 class VTKINFOVISBOOSTGRAPHALGORITHMS_EXPORT vtkBoostSplitTableField : public vtkTableAlgorithm
63 {
64 public:
65   static vtkBoostSplitTableField* New();
66   vtkTypeMacro(vtkBoostSplitTableField, vtkTableAlgorithm);
67   void PrintSelf(ostream& os, vtkIndent indent) override;
68 
69   void ClearFields();
70   void AddField(const char* field, const char* delimiters);
71 
72 protected:
73   vtkBoostSplitTableField();
74   ~vtkBoostSplitTableField();
75 
76   int RequestData(
77     vtkInformation*,
78     vtkInformationVector**,
79     vtkInformationVector*) override;
80 
81   vtkStringArray* Fields;
82   vtkStringArray* Delimiters;
83 
84 private:
85 
86   class implementation;
87 
88   vtkBoostSplitTableField(const vtkBoostSplitTableField&) = delete;
89   void operator=(const vtkBoostSplitTableField&) = delete;
90 };
91 
92 #endif
93