Visualization Library 2.0.0

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
Linker.hpp
Go to the documentation of this file.
1 /**************************************************************************************/
2 /* */
3 /* Visualization Library */
4 /* http://visualizationlibrary.org */
5 /* */
6 /* Copyright (c) 2005-2020, Michele Bosi */
7 /* All rights reserved. */
8 /* */
9 /* Redistribution and use in source and binary forms, with or without modification, */
10 /* are permitted provided that the following conditions are met: */
11 /* */
12 /* - Redistributions of source code must retain the above copyright notice, this */
13 /* list of conditions and the following disclaimer. */
14 /* */
15 /* - Redistributions in binary form must reproduce the above copyright notice, this */
16 /* list of conditions and the following disclaimer in the documentation and/or */
17 /* other materials provided with the distribution. */
18 /* */
19 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */
20 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */
21 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
22 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */
23 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
24 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
25 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
26 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
27 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
28 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
29 /* */
30 /**************************************************************************************/
31 
32 #ifndef VLXLinker_INCLUDE_ONCE
33 #define VLXLinker_INCLUDE_ONCE
34 
35 #include <vlX/VisitorLinker.hpp>
37 
38 namespace vlX
39 {
41  class Linker
42  {
43  public:
44  void add(VLXTaggedValue* module)
45  {
46  mModules.push_back(module);
47  }
48 
49  bool link()
50  {
51  std::map< std::string, vl::ref<VLXStructure> > link_map;
52 
53  // map all the IDs to the appropriate VLXStructures
54  VisitorLinkMapper link_mapper(&link_map);
55  for(size_t i=0; i<mModules.size(); ++i)
56  mModules[i]->acceptVisitor(&link_mapper);
57 
58  if (link_mapper.error())
59  return false;
60 
61  // link all the IDs to the associated VLXStructure
62  VisitorLinker linker(&link_map);
63  for(size_t i=0; i<mModules.size(); ++i)
64  mModules[i]->acceptVisitor(&linker);
65 
66  if (linker.error())
67  return false;
68 
69  return true;
70  }
71 
72  std::vector< vl::ref<VLXTaggedValue> >& modules() { return mModules; }
73 
74  const std::vector< vl::ref<VLXTaggedValue> >& modules() const { return mModules; }
75 
76  public:
77  std::vector< vl::ref<VLXTaggedValue> > mModules;
78  };
79 }
80 
81 #endif
Links several VLX hierachies also resolving IDs across them.
Definition: Linker.hpp:41
const std::vector< vl::ref< VLXTaggedValue > > & modules() const
Definition: Linker.hpp:74
EError error() const
std::vector< vl::ref< VLXTaggedValue > > & modules()
Definition: Linker.hpp:72
std::vector< vl::ref< VLXTaggedValue > > mModules
Definition: Linker.hpp:77
Substitutes IDs into VLXStructures using the provided link map.
void add(VLXTaggedValue *module)
Definition: Linker.hpp:44
bool link()
Definition: Linker.hpp:49
Base class for VLX values with a tag.
Definition: Value.hpp:42