ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
StringNodeImpl.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 "StringNodeImpl.h"
29 #include "CheckedFile.h"
30 
31 namespace e57
32 {
34  NodeImpl( destImageFile ), value_( value )
35  {
36  // don't checkImageFileOpen, NodeImpl() will do it
37  }
38 
40  {
41  // don't checkImageFileOpen
42 
44  if ( ni->type() != E57_STRING )
45  {
46  return ( false );
47  }
48 
50 
52  return ( true );
53  }
54 
55  bool StringNodeImpl::isDefined( const ustring &pathName )
56  {
57  // don't checkImageFileOpen
58 
60  return pathName.empty();
61  }
62 
64  {
65  checkImageFileOpen( __FILE__, __LINE__, static_cast<const char *>( __FUNCTION__ ) );
66  return ( value_ );
67  }
68 
70  {
71  // don't checkImageFileOpen
72 
74  if ( pathNames.find( relativePathName( origin ) ) == pathNames.end() )
75  {
76  throw E57_EXCEPTION2( E57_ERROR_NO_BUFFER_FOR_ELEMENT, "this->pathName=" + this->pathName() );
77  }
78  }
79 
81  const char *forcedFieldName )
82  {
83  // don't checkImageFileOpen
84 
85  ustring fieldName;
86  if ( forcedFieldName != nullptr )
87  {
88  fieldName = forcedFieldName;
89  }
90  else
91  {
92  fieldName = elementName_;
93  }
94 
95  cf << space( indent ) << "<" << fieldName << " type=\"String\"";
96 
98  if ( value_.empty() )
99  {
100  cf << "/>\n";
101  }
102  else
103  {
104  cf << "><![CDATA[";
105 
106  size_t currentPosition = 0;
107  size_t len = value_.length();
108 
111  while ( currentPosition < len )
112  {
113  size_t found = value_.find( "]]>", currentPosition );
114 
115  if ( found == std::string::npos )
116  {
118  cf << value_.substr( currentPosition );
119  break;
120  }
121 
124  cf << value_.substr( currentPosition, found - currentPosition + 2 );
125 
127  cf << "]]><![CDATA[";
128 
130  currentPosition = found + 2;
131  }
132  cf << "]]></" << fieldName << ">\n";
133  }
134  }
135 
136 #ifdef E57_DEBUG
137  void StringNodeImpl::dump( int indent, std::ostream &os ) const
138  {
139  os << space( indent ) << "type: String"
140  << " (" << type() << ")" << std::endl;
141  NodeImpl::dump( indent, os );
142  os << space( indent ) << "value: '" << value_ << "'" << std::endl;
143  }
144 #endif
145 }
#define E57_EXCEPTION2(ecode, context)
Definition: Common.h:68
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
StringNodeImpl(ImageFileImplWeakPtr destImageFile, const ustring &value="")
void dump(int indent=0, std::ostream &os=std::cout) const override
bool isDefined(const ustring &pathName) override
bool isTypeEquivalent(NodeImplSharedPtr ni) override
void checkLeavesInSet(const StringSet &pathNames, NodeImplSharedPtr origin) override
NodeType type() const override
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_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_STRING
StringNode class.
Definition: E57Format.h:65
std::string space(size_t n)
Definition: Common.h:73