Adaptagrams
commontypes.h
1 /*
2  * vim: ts=4 sw=4 et tw=0 wm=0
3  *
4  * libdialect - A library for computing DiAlEcT layouts:
5  * D = Decompose/Distribute
6  * A = Arrange
7  * E = Expand/Emend
8  * T = Transform
9  *
10  * Copyright (C) 2018 Monash University
11  *
12  * This library is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU Lesser General Public
14  * License as published by the Free Software Foundation; either
15  * version 2.1 of the License, or (at your option) any later version.
16  * See the file LICENSE.LGPL distributed with the library.
17  *
18  * This library is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21  *
22  * Author(s): Steve Kieffer <http://skieffer.info>
23 */
24 
25 #ifndef DIALECT_COMMONTYPES_H
26 #define DIALECT_COMMONTYPES_H
27 
28 #include <memory>
29 #include <map>
30 #include <utility>
31 #include <vector>
32 #include <functional>
33 
34 #include "libavoid/geomtypes.h"
35 
36 namespace dialect {
37 
38 class ACALayout;
39 struct Assignment;
40 struct ColaGraphRep;
41 class Edge;
42 struct EdgeSegment;
43 class ExpansionGoal;
44 class Face;
45 class FaceSet;
46 class GhostNode;
47 class Graph;
48 struct LineSegment;
49 struct Nbr;
50 class Nexus;
51 class Node;
52 class ProjSeq;
53 struct Quad;
54 struct SepPair;
55 class Side;
56 class Tree;
57 class TreePlacement;
58 
59 // Shared Pointers
60 typedef std::shared_ptr<ACALayout> ACALayout_SP;
61 typedef std::shared_ptr<Assignment> Assignment_SP;
62 typedef std::shared_ptr<ColaGraphRep> ColaGraphRep_SP;
63 typedef std::shared_ptr<Edge> Edge_SP;
64 typedef std::shared_ptr<ExpansionGoal> ExpansionGoal_SP;
65 typedef std::shared_ptr<Face> Face_SP;
66 typedef std::shared_ptr<FaceSet> FaceSet_SP;
67 typedef std::shared_ptr<GhostNode> GhostNode_SP;
68 typedef std::shared_ptr<Graph> Graph_SP;
69 typedef std::shared_ptr<LineSegment> LineSegment_SP;
70 typedef std::shared_ptr<Nbr> Nbr_SP;
71 typedef std::shared_ptr<Nexus> Nexus_SP;
72 typedef std::shared_ptr<Node> Node_SP;
73 typedef std::shared_ptr<ProjSeq> ProjSeq_SP;
74 typedef std::shared_ptr<Quad> Quad_SP;
75 typedef std::shared_ptr<SepPair> SepPair_SP;
76 typedef std::shared_ptr<Side> Side_SP;
77 typedef std::shared_ptr<Tree> Tree_SP;
78 typedef std::shared_ptr<TreePlacement> TreePlacement_SP;
79 
80 // Weak Pointers
81 typedef std::weak_ptr<Node> Node_WP;
82 
83 // Plurals (vectors of shared pointers)
84 typedef std::vector<Assignment_SP> Assignments;
85 typedef std::vector<Edge_SP> Edges;
86 typedef std::vector<ExpansionGoal_SP> ExpansionGoals;
87 typedef std::vector<Face_SP> Faces;
88 typedef std::vector<Graph_SP> Graphs;
89 typedef std::vector<LineSegment_SP> LineSegments;
90 typedef std::vector<Nbr_SP> Nbrs;
91 typedef std::vector<Nexus_SP> Nexes;
92 typedef std::vector<Node_SP> Nodes;
93 typedef std::vector<Quad_SP> Quads;
94 typedef std::vector<Side_SP> Sides;
95 typedef std::vector<Tree_SP> Trees;
96 typedef std::vector<TreePlacement_SP> TreePlacements;
97 
98 // Organisation by IDs
99 typedef unsigned id_type;
100 
101 typedef std::map<id_type, Node_SP> NodesById;
102 typedef std::map<id_type, Edge_SP> EdgesById;
103 typedef std::map<id_type, Face_SP> FacesById;
104 typedef std::map<id_type, Nexus_SP> NexesById;
105 
106 typedef std::pair<id_type, id_type> IdPair;
107 typedef std::pair<id_type, Node_SP> IdNodePair;
108 typedef std::pair<id_type, Edge_SP> IdEdgePair;
109 
110 typedef std::map<id_type, id_type> id_map;
111 
112 /* SparseIdMatrix2d
113  *
114  * Initially tried
115  * template <typename T>
116  * using SparseIdMatrix2d = std::map<id_type, std::map<id_type, T>>;
117  * taking advantage of the C++11 "alias declaration". Builds fine, but SWIG complains.
118  * Despite following the instructions here
119  * http://www.swig.org/Doc3.0/CPlusPlus11.html#CPlusPlus11_alias_templates
120  * and adding
121  * %template(MapIdMapIdUnsigned) std::map<id_type, std::map<id_type, unsigned>>;
122  * %template() SparseIdMatrix2d<unsigned>;
123  * to the interface file, SWIG still complains that SparseIdMatrix2d is not defined.
124  * So we instead fall back on the C++03 hack, with thanks to https://stackoverflow.com/a/2795024.
125  * Usage looks e.g. like:
126  * SparseIdMatrix2d<unsigned>::type mymatrix;
127  */
128 template <typename T>
129 struct SparseIdMatrix2d
130 {
131  typedef std::map<id_type, std::map<id_type, T>> type;
132 };
133 
134 // Misc
135 typedef std::pair<double, double> dimensions;
136 
137 typedef std::function<Avoid::Point(Avoid::Point)> PlaneMap;
138 typedef std::function<void(Avoid::Point&)> InplacePlaneMap;
139 
140 } // namespace dialect
141 
142 #endif // DIALECT_COMMONTYPES_H
libdialect: A library for computing human-like orthogonal network (DiAlEcT) layouts.
Definition: cola.h:44
std::pair< unsigned, unsigned > Edge
Edges are simply a pair of indices to entries in the Node vector.
Definition: cola.h:68
Contains the interface for various geometry types and classes.
std::vector< Node * > Nodes
A vector of pointers to Node objects.
Definition: topology_graph.h:82
std::vector< Edge * > Edges
A vector of pointers to Edge objects.
Definition: topology_graph.h:533