Evoplex  0.2.1
nodes_p.h
1 /* Evoplex <https://evoplex.org>
2  * Copyright (C) 2016-present - Marcos Cardinot <marcos@cardinot.net>
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef NODES_P_H
18 #define NODES_P_H
19 
20 #include <functional>
21 #include <unordered_map>
22 
23 #include "attributerange.h"
24 #include "enum.h"
25 #include "nodes.h"
26 
27 namespace evoplex {
28 
33 {
34 public:
35  // Expected commands:
36  // - same mode for all attributes:
37  // '*integer;[min|max|rand_seed]'
38  // - specific mode for each attribute:
39  // '#integer;attrName_[min|max|rand_seed|value_val];...'
40  static Nodes fromCmd(const QString& cmd, const AttributesScope& attrsScope,
41  const GraphType& graphType, QString& error,
42  std::function<void(int)> progress = [](int){});
43 
44  // Read a set of nodes from a csv file
45  // Return empty if something goes wrong
46  static Nodes fromFile(const QString& filePath, const AttributesScope& attrsScope,
47  const GraphType& graphType, QString& error,
48  std::function<void(int)> progress = [](int){});
49 
50  // Export set of nodes to a csv file
51  // Return true if successful
52  static bool saveToFile(const Nodes& nodes, QString filepath,
53  std::function<void(int)> progress = [](int){});
54 
55  // clone a Nodes container
56  static Nodes clone(const Nodes& nodes);
57 
58 private:
59  // Checks if the header is in comma-separated format,
60  // don't have duplicates, has (or not) 2d coordinates ('x' and 'y')
61  // and has all the required attributes (attrsScope)
62  static QStringList validateHeader(const QString& header,
63  const AttributesScope& attrsScope, QString& error);
64 
65  static Node readRow(const int row, const QStringList& header,
66  const QStringList& values, const AttributesScope& attrsScope,
67  const bool isDirected, QString& error);
68 };
69 
70 } // evoplex
71 #endif // NODES_P_H
It wraps a std::shared_ptr<BaseNode>.
Definition: node.h:35
A collection of utility functions for creating and saving nodes.
Definition: nodes_p.h:32
A Node container.
Definition: nodes.h:32
Definition: abstractgraph.h:29