ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
IntegerNodeImpl.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 "IntegerNodeImpl.h"
29 #include "CheckedFile.h"
30 
31 namespace e57
32 {
33  IntegerNodeImpl::IntegerNodeImpl( ImageFileImplWeakPtr destImageFile, int64_t value, int64_t minimum,
34  int64_t maximum ) :
35  NodeImpl( destImageFile ), value_( value ), minimum_( minimum ), maximum_( maximum )
36  {
37  // don't checkImageFileOpen, NodeImpl() will do it
38 
40  if ( value < minimum || maximum < value )
41  {
43  "this->pathName=" + this->pathName() + " value=" + toString( value ) +
44  " minimum=" + toString( minimum ) + " maximum=" + toString( maximum ) );
45  }
46  }
47 
49  {
50  // don't checkImageFileOpen
51 
53  if ( ni->type() != E57_INTEGER )
54  {
55  return ( false );
56  }
57 
59  std::shared_ptr<IntegerNodeImpl> ii( std::static_pointer_cast<IntegerNodeImpl>( ni ) );
60 
62  if ( minimum_ != ii->minimum_ )
63  {
64  return ( false );
65  }
66 
68  if ( maximum_ != ii->maximum_ )
69  {
70  return ( false );
71  }
72 
74 
76  return ( true );
77  }
78 
79  bool IntegerNodeImpl::isDefined( const ustring &pathName )
80  {
81  // don't checkImageFileOpen
82 
84  return pathName.empty();
85  }
86 
88  {
89  checkImageFileOpen( __FILE__, __LINE__, static_cast<const char *>( __FUNCTION__ ) );
90  return ( value_ );
91  }
92 
94  {
95  checkImageFileOpen( __FILE__, __LINE__, static_cast<const char *>( __FUNCTION__ ) );
96  return ( minimum_ );
97  }
98 
100  {
101  checkImageFileOpen( __FILE__, __LINE__, static_cast<const char *>( __FUNCTION__ ) );
102  return ( maximum_ );
103  }
104 
106  {
107  // don't checkImageFileOpen
108 
110  if ( pathNames.find( relativePathName( origin ) ) == pathNames.end() )
111  {
112  throw E57_EXCEPTION2( E57_ERROR_NO_BUFFER_FOR_ELEMENT, "this->pathName=" + this->pathName() );
113  }
114  }
115 
117  const char *forcedFieldName )
118  {
119  // don't checkImageFileOpen
120 
121  ustring fieldName;
122  if ( forcedFieldName != nullptr )
123  {
124  fieldName = forcedFieldName;
125  }
126  else
127  {
128  fieldName = elementName_;
129  }
130 
131  cf << space( indent ) << "<" << fieldName << " type=\"Integer\"";
132 
134  if ( minimum_ != E57_INT64_MIN )
135  {
136  cf << " minimum=\"" << minimum_ << "\"";
137  }
138  if ( maximum_ != E57_INT64_MAX )
139  {
140  cf << " maximum=\"" << maximum_ << "\"";
141  }
142 
144  if ( value_ != 0 )
145  {
146  cf << ">" << value_ << "</" << fieldName << ">\n";
147  }
148  else
149  {
150  cf << "/>\n";
151  }
152  }
153 
154 #ifdef E57_DEBUG
155  void IntegerNodeImpl::dump( int indent, std::ostream &os ) const
156  {
157  // don't checkImageFileOpen
158  os << space( indent ) << "type: Integer"
159  << " (" << type() << ")" << std::endl;
160  NodeImpl::dump( indent, os );
161  os << space( indent ) << "value: " << value_ << std::endl;
162  os << space( indent ) << "minimum: " << minimum_ << std::endl;
163  os << space( indent ) << "maximum: " << maximum_ << std::endl;
164  }
165 #endif
166 }
#define E57_EXCEPTION2(ecode, context)
Definition: Common.h:68
void checkLeavesInSet(const StringSet &pathNames, NodeImplSharedPtr origin) override
void writeXml(ImageFileImplSharedPtr imf, CheckedFile &cf, int indent, const char *forcedFieldName=nullptr) override
NodeType type() const override
IntegerNodeImpl(ImageFileImplWeakPtr destImageFile, int64_t value=0, int64_t minimum=0, int64_t maximum=0)
bool isDefined(const ustring &pathName) override
void dump(int indent=0, std::ostream &os=std::cout) const override
bool isTypeEquivalent(NodeImplSharedPtr ni) override
ustring elementName_
Definition: NodeImpl.h:96
ustring relativePathName(const NodeImplSharedPtr &origin, ustring childPathName=ustring()) const
Definition: NodeImpl.cpp:93
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
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_VALUE_OUT_OF_BOUNDS
element value out of min/max bounds
Definition: E57Exception.h:81
@ E57_ERROR_NO_BUFFER_FOR_ELEMENT
Definition: E57Exception.h:69
std::string ustring
UTF-8 encodeded Unicode string.
Definition: E57Format.h:54
std::set< std::string > StringSet
Definition: Common.h:194
@ E57_INTEGER
IntegerNode class.
Definition: E57Format.h:62
std::string toString(T x)
Definition: Common.h:80
std::string space(size_t n)
Definition: Common.h:73