Essentia  2.1-beta6-dev
networkparser.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2021 Music Technology Group - Universitat Pompeu Fabra
3  *
4  * This file is part of Essentia
5  *
6  * Essentia is free software: you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License as published by the Free
8  * Software Foundation (FSF), either version 3 of the License, or (at your
9  * option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the Affero GNU General Public License
17  * version 3 along with this program. If not, see http://www.gnu.org/licenses/
18  */
19 
20 #ifndef ESSENTIA_SCHEDULER_NETWORKPARSER_H
21 #define ESSENTIA_SCHEDULER_NETWORKPARSER_H
22 
23 #include "network.h"
24 #include "../utils/asciidagparser.h"
25 
26 namespace essentia {
27 namespace scheduler {
28 
30  public:
31  // NB: template is only used so that ARRAY_SIZE can work, we only want const char*[] here
32  // if createConnections is false, only the NetworkNodes will be connected according to
33  // the topology, not the underlying algorithms. This is useful for unittesting when we have
34  // diamond shapes, which can appear in the execution network but not in the visible network
35  template <typename NetworkType>
36  NetworkParser(const NetworkType& network, bool createConnections = true) : _graph(network) {
38  }
39 
41  // no need to delete algorithms that have been instantiated as those are being
42  // taken care of by the Network, which was created with takeOwnership = true.
43  delete _network;
44  }
45 
46  const std::vector<std::string>& algorithms() const { return _graph.nodes(); }
47  const std::vector<std::pair<int, int> >& connections() const { return _graph.edges(); }
48  const std::vector<std::pair<std::string, std::string> >& namedConnections() const { return _graph.namedEdges(); }
49 
50  Network* network() { return _network; }
51 
52  protected:
55 
56  // from the parsed DAG, create the corresponding algorithms and connect them.
57  void createNetwork(bool createConnections = true);
59 
60  // algos that have been instantiated
61  std::vector<streaming::Algorithm*> _algos;
62 
63 };
64 
65 } // namespace scheduler
66 } // namespace essentia
67 
68 #endif // ESSENTIA_SCHEDULER_NETWORKPARSER_H
Definition: asciidagparser.h:28
const std::vector< std::pair< int, int > > & edges() const
Definition: asciidagparser.h:59
const std::vector< std::string > & nodes() const
Definition: asciidagparser.h:48
const std::vector< std::pair< std::string, std::string > > & namedEdges() const
Definition: asciidagparser.h:54
Definition: networkparser.h:29
~NetworkParser()
Definition: networkparser.h:40
NetworkParser(const NetworkType &network, bool createConnections=true)
Definition: networkparser.h:36
std::vector< streaming::Algorithm * > _algos
Definition: networkparser.h:61
const std::vector< std::pair< int, int > > & connections() const
Definition: networkparser.h:47
void createNetwork(bool createConnections=true)
const std::vector< std::pair< std::string, std::string > > & namedConnections() const
Definition: networkparser.h:48
Network * _network
Definition: networkparser.h:54
const std::vector< std::string > & algorithms() const
Definition: networkparser.h:46
AsciiDAGParser _graph
Definition: networkparser.h:53
Network * network()
Definition: networkparser.h:50
Definition: network.h:98
Definition: algorithm.h:28