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]
VisitorCountIDs.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 VLXVisitorCountIDs_INCLUDE_ONCE
33 #define VLXVisitorCountIDs_INCLUDE_ONCE
34 
35 #include <vlX/Visitor.hpp>
36 #include <vlX/Value.hpp>
37 #include <vlCore/Log.hpp>
38 #include <vlCore/Say.hpp>
39 
40 namespace vlX
41 {
43  class VisitorIDCounter: public Visitor
44  {
45  VL_INSTRUMENT_CLASS(vlX::VisitorCountIDs, Visitor)
46 
47  public:
48  VisitorIDCounter(): mIDSet(NULL) {}
49 
50  virtual void visitStructure(VLXStructure* obj)
51  {
52  if(!obj->uid().empty() && obj->uid() != "#NULL")
53  (*mIDSet)[obj->uid()]++;
54 
55  if (isVisited(obj))
56  return;
57 
58  for(size_t i=0; i<obj->value().size(); ++i)
59  {
60  VLXStructure::KeyValue& keyval = obj->value()[i];
61  if (keyval.value().type() == VLXValue::Structure)
62  keyval.value().getStructure()->acceptVisitor(this);
63  else
64  if (keyval.value().type() == VLXValue::List)
65  keyval.value().getList()->acceptVisitor(this);
66  else
67  /*
68  if (keyval.value().type() == VLXValue::ArrayID)
69  keyval.value().getArrayID()->acceptVisitor(this);
70  else
71  */
72  if (keyval.value().type() == VLXValue::ID)
73  (*mIDSet)[keyval.value().getID()]++;
74  }
75  }
76 
77  virtual void visitList(VLXList* list)
78  {
79  // this should happen only if the user manually creates loops
80  if (isVisited(list))
81  {
82  vl::Log::warning("VisitorIDCounter: cycle detected on VLXList.\n");
83  return;
84  }
85 
86  for(size_t i=0; i<list->value().size(); ++i)
87  {
88  if (list->value()[i].type() == VLXValue::Structure)
89  list->value()[i].getStructure()->acceptVisitor(this);
90  if (list->value()[i].type() == VLXValue::List)
91  list->value()[i].getList()->acceptVisitor(this);
92  else
93  /*
94  if (list->value()[i].type() == VLXValue::ArrayID)
95  list->value()[i].getArrayID()->acceptVisitor(this);
96  else
97  */
98  if (list->value()[i].type() == VLXValue::ID)
99  (*mIDSet)[list->value()[i].getID()]++;
100  }
101  }
102 
103  /*
104  virtual void visitArray(VLXArrayString*) {}
105 
106  virtual void visitArray(VLXArrayID* arr)
107  {
108  // retrieves the assigned Structure
109  for(size_t i=0 ;i<arr->value().size(); ++i)
110  (*mIDSet)[arr->value()[i].uid()]++;
111  }
112 
113  virtual void visitArray(VLXArrayIdentifier*) {}
114  */
115 
116  virtual void visitArray(VLXArrayInteger*) {}
117 
118  virtual void visitArray(VLXArrayReal*) {}
119 
120  void setIDSet(std::map< std::string, int >* uids) { mIDSet = uids; }
121 
122  std::map< std::string, int >* uidSet() { return mIDSet; }
123 
124  const std::map< std::string, int >* uidSet() const { return mIDSet; }
125 
126  private:
127  std::map< std::string, int >* mIDSet;
128  };
129 }
130 
131 #endif
virtual void visitStructure(VLXStructure *obj)
static void warning(const String &message)
Use this function to provide information about situations that might lead to errors or loss of data...
Definition: Log.cpp:155
Counts the number of occurrencies of each ID.
vlX::VLXValue & value()
Definition: Value.hpp:594
Key/value pair used by VLXStructure.
Definition: Value.hpp:582
VLXList * getList()
Definition: Value.hpp:410
virtual void visitList(VLXList *list)
An array of 64 bits floating point numbers, can also have a tag.
Definition: Value.hpp:144
const std::string & getID() const
Definition: Value.hpp:484
virtual void acceptVisitor(Visitor *v)
Definition: Value.hpp:650
VLXStructure * getStructure()
Definition: Value.hpp:402
#define VL_INSTRUMENT_CLASS(ClassName, BaseClass)
Definition: TypeInfo.hpp:122
std::vector< VLXValue > & value()
Definition: Value.hpp:652
A list of key/VLXValue pairs, can also have a tag.
Definition: Value.hpp:541
std::map< std::string, int > * uidSet()
A simple sequence of VLXValue objects, can also have a tag.
Definition: Value.hpp:634
virtual void visitArray(VLXArrayReal *)
virtual void acceptVisitor(Visitor *v)
Definition: Value.hpp:566
std::vector< KeyValue > & value()
Definition: Value.hpp:607
virtual void visitArray(VLXArrayInteger *)
#define NULL
Definition: OpenGLDefs.hpp:81
void setIDSet(std::map< std::string, int > *uids)
An array of 64 bits integers, can also have a tag.
Definition: Value.hpp:133
Base class for all visitors visiting a VLX hierarchy.
Definition: Visitor.hpp:53
const std::string & uid() const
Definition: Value.hpp:605
const std::map< std::string, int > * uidSet() const
EType type() const
Definition: Value.hpp:396
bool isVisited(void *node)
Definition: Visitor.hpp:69