ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
VectorNodeImpl.cpp
Go to the documentation of this file.
1 /*
2  * Original work Copyright 2009 - 2010 Kevin Ackley (kackley@gwi.net)
3  * Modified work Copyright 2018 - 2020 Andy Maloney <asmaloney@gmail.com>
4  *
5  * Permission is hereby granted, free of charge, to any person or organization
6  * obtaining a copy of the software and accompanying documentation covered by
7  * this license (the "Software") to use, reproduce, display, distribute,
8  * execute, and transmit the Software, and to prepare derivative works of the
9  * Software, and to permit third-parties to whom the Software is furnished to
10  * do so, all subject to the following:
11  *
12  * The copyright notices in the Software and this entire statement, including
13  * the above license grant, this restriction and the following disclaimer,
14  * must be included in all copies of the Software, in whole or in part, and
15  * all derivative works of the Software, unless such copies or derivative
16  * works are solely in the form of machine-executable object code generated by
17  * a source language processor.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  * FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
22  * SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
23  * FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
24  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25  * DEALINGS IN THE SOFTWARE.
26  */
27 
28 #include "VectorNodeImpl.h"
29 #include "CheckedFile.h"
30 
31 namespace e57
32 {
33  VectorNodeImpl::VectorNodeImpl( ImageFileImplWeakPtr destImageFile, bool allowHeteroChildren ) :
34  StructureNodeImpl( destImageFile ), allowHeteroChildren_( allowHeteroChildren )
35  {
37  }
38 
40  {
42 
44  if ( ni->type() != E57_VECTOR )
45  {
46  return ( false );
47  }
48 
49  std::shared_ptr<VectorNodeImpl> ai( std::static_pointer_cast<VectorNodeImpl>( ni ) );
50 
52  if ( allowHeteroChildren_ != ai->allowHeteroChildren_ )
53  {
54  return ( false );
55  }
56 
58  if ( childCount() != ai->childCount() )
59  {
60  return ( false );
61  }
62 
64  for ( unsigned i = 0; i < childCount(); i++ )
65  {
66  if ( !children_.at( i )->isTypeEquivalent( ai->children_.at( i ) ) )
67  {
68  return ( false );
69  }
70  }
71 
73  return ( true );
74  }
75 
77  {
78  checkImageFileOpen( __FILE__, __LINE__, static_cast<const char *>( __FUNCTION__ ) );
79  return allowHeteroChildren_;
80  }
81 
82  void VectorNodeImpl::set( int64_t index64, NodeImplSharedPtr ni )
83  {
84  checkImageFileOpen( __FILE__, __LINE__, static_cast<const char *>( __FUNCTION__ ) );
85  if ( !allowHeteroChildren_ )
86  {
88  for ( auto &child : children_ )
89  {
90  if ( !child->isTypeEquivalent( ni ) )
91  {
92  throw E57_EXCEPTION2( E57_ERROR_HOMOGENEOUS_VIOLATION, "this->pathName=" + this->pathName() );
93  }
94  }
95  }
96 
98  StructureNodeImpl::set( index64, ni );
99  }
100 
101  void VectorNodeImpl::writeXml( ImageFileImplSharedPtr imf, CheckedFile &cf, int indent, const char *forcedFieldName )
102  {
104 
105  ustring fieldName;
106  if ( forcedFieldName != nullptr )
107  {
108  fieldName = forcedFieldName;
109  }
110  else
111  {
112  fieldName = elementName_;
113  }
114 
115  cf << space( indent ) << "<" << fieldName << " type=\"Vector\" allowHeterogeneousChildren=\""
116  << static_cast<int64_t>( allowHeteroChildren_ ) << "\">\n";
117  for ( auto &child : children_ )
118  {
119  child->writeXml( imf, cf, indent + 2, "vectorChild" );
120  }
121  cf << space( indent ) << "</" << fieldName << ">\n";
122  }
123 
124 #ifdef E57_DEBUG
125  void VectorNodeImpl::dump( int indent, std::ostream &os ) const
126  {
128  os << space( indent ) << "type: Vector"
129  << " (" << type() << ")" << std::endl;
130  NodeImpl::dump( indent, os );
131  os << space( indent ) << "allowHeteroChildren: " << allowHeteroChildren() << std::endl;
132  for ( unsigned i = 0; i < children_.size(); i++ )
133  {
134  os << space( indent ) << "child[" << i << "]:" << std::endl;
135  children_.at( i )->dump( indent + 2, os );
136  }
137  }
138 #endif
139 }
#define E57_EXCEPTION2(ecode, context)
Definition: Common.h:68
ustring elementName_
Definition: NodeImpl.h:96
void checkImageFileOpen(const char *srcFileName, int srcLineNumber, const char *srcFunctionName) const
Definition: NodeImpl.cpp:41
virtual void dump(int indent=0, std::ostream &os=std::cout) const
Definition: NodeImpl.cpp:372
ustring pathName() const
Definition: NodeImpl.cpp:74
virtual void set(int64_t index, NodeImplSharedPtr ni)
std::vector< NodeImplSharedPtr > children_
virtual int64_t childCount() const
NodeType type() const override
bool allowHeteroChildren() const
void dump(int indent=0, std::ostream &os=std::cout) const override
bool isTypeEquivalent(NodeImplSharedPtr ni) override
void set(int64_t index, NodeImplSharedPtr ni) override
VectorNodeImpl(ImageFileImplWeakPtr destImageFile, bool allowHeteroChildren)
void writeXml(ImageFileImplSharedPtr imf, CheckedFile &cf, int indent, const char *forcedFieldName=nullptr) override
QTextStream & endl(QTextStream &stream)
Definition: QtCompat.h:718
std::shared_ptr< class NodeImpl > NodeImplSharedPtr
Definition: Common.h:190
std::weak_ptr< class ImageFileImpl > ImageFileImplWeakPtr
Definition: Common.h:189
std::shared_ptr< class ImageFileImpl > ImageFileImplSharedPtr
Definition: Common.h:188
@ E57_ERROR_HOMOGENEOUS_VIOLATION
Definition: E57Exception.h:48
std::string ustring
UTF-8 encodeded Unicode string.
Definition: E57Format.h:54
@ E57_VECTOR
VectorNode class.
Definition: E57Format.h:60
std::string space(size_t n)
Definition: Common.h:73