Visualization Library 2.1.0

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

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
Parser.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 VLXParser_INCLUDE_ONCE
33 #define VLXParser_INCLUDE_ONCE
34 
36 #include <vlX/Linker.hpp>
37 
38 namespace vlX
39 {
41  class Parser: public vl::Object
42  {
44 
45  public:
46 
47  virtual bool parseHeader() = 0;
48 
49  virtual bool parse() = 0;
50 
52  bool link()
53  {
54  Linker linker;
55 
56  for(size_t i=0; i<mStructures.size(); ++i)
57  linker.add(mStructures[i].get());
58 
59  return linker.link();
60  }
61 
64  {
65  mMetadata.clear();
66 
67  for(size_t i=0; i<mStructures.size(); ++i)
68  {
69  if (mStructures[i]->tag() == "<Metadata>")
70  {
71  const VLXStructure* st = mStructures[i].get();
72 
73  for(size_t ikey=0; ikey<st->value().size(); ++ikey)
74  mMetadata[st->value()[ikey].key()] = st->value()[ikey].value();
75 
76  mStructures.erase( mStructures.begin() + i );
77  }
78  }
79  }
80 
82  std::vector< vl::ref<VLXStructure> >& structures() { return mStructures; }
83 
85  const std::vector< vl::ref<VLXStructure> >& structures() const { return mStructures; }
86 
88  const std::map< std::string, VLXValue >& metadata() const { return mMetadata; }
89 
91  const std::string& encoding() const { return mEncoding; }
92 
94  unsigned short version() const { return mVersion;}
95 
96  protected:
97  std::string mEncoding;
98  unsigned short mVersion;
99  std::vector< vl::ref<VLXStructure> > mStructures;
100  std::map< std::string, VLXValue > mMetadata;
101  };
102 }
103 
104 #endif
Links several VLX hierachies also resolving IDs across them.
Definition: Linker.hpp:41
const std::vector< vl::ref< VLXStructure > > & structures() const
The imported structures.
Definition: Parser.hpp:85
std::vector< vl::ref< VLXStructure > > & structures()
The imported structures.
Definition: Parser.hpp:82
virtual bool parse()=0
void parseMetadata()
Moves the <Metadata> key/value pairs in the Metadata map for quick and easy access and removes the <M...
Definition: Parser.hpp:63
unsigned short mVersion
Definition: Parser.hpp:98
unsigned short version() const
The VLX language version.
Definition: Parser.hpp:94
std::string mEncoding
Definition: Parser.hpp:97
std::vector< vl::ref< VLXStructure > > mStructures
Definition: Parser.hpp:99
A list of key/VLXValue pairs, can also have a tag.
Definition: Value.hpp:541
The base class for all the reference counted objects.
Definition: Object.hpp:158
bool link()
Links the.
Definition: Parser.hpp:52
std::vector< KeyValue > & value()
Definition: Value.hpp:607
void add(VLXTaggedValue *module)
Definition: Linker.hpp:44
bool link()
Definition: Linker.hpp:49
#define VL_INSTRUMENT_ABSTRACT_CLASS(ClassName, BaseClass)
Definition: TypeInfo.hpp:145
Base class for VLX parsers.
Definition: Parser.hpp:41
const std::string & encoding() const
The encoding used to encode strings.
Definition: Parser.hpp:91
const std::map< std::string, VLXValue > & metadata() const
The imported metadata.
Definition: Parser.hpp:88
std::map< std::string, VLXValue > mMetadata
Definition: Parser.hpp:100
virtual bool parseHeader()=0