1 /******************************************************************************
2 * Copyright (c) 2018, Kyle Mann (kyle@hobu.co)
3 *
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following
8 * conditions are met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided
15 * with the distribution.
16 * * Neither the name of Hobu, Inc. or Flaxen Geo Consulting nor the
17 * names of its contributors may be used to endorse or promote
18 * products derived from this software without specific prior
19 * written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 * OF SUCH DAMAGE.
33 ****************************************************************************/
34 #pragma once
35
36 #include <sstream>
37 #include <stdexcept>
38
39 #include <pdal/JsonFwd.hpp>
40
41 namespace lepcc
42 {
43 struct Point3D;
44 struct RGB_t;
45 }
46
47 namespace pdal
48 {
49 namespace i3s
50 {
51
52 class Version
53 {
54 private:
55 int major = 0;
56 int minor = 0;
57 int patch = 0;
58
59 public:
Version()60 Version()
61 {}
62
Version(std::string vString)63 Version(std::string vString)
64 {
65 std::istringstream iss(vString);
66 std::string token;
67 if(std::getline(iss, token, '.'))
68 if(!token.empty())
69 major = std::stoi(token);
70 if(std::getline(iss, token, '.'))
71 if(!token.empty())
72 minor = std::stoi(token);
73 if(std::getline(iss, token, '.'))
74 if(!token.empty())
75 patch = std::stoi(token);
76 }
77
operator <(const Version & other)78 bool operator<(const Version& other)
79 {
80 if(this->major < other.major)
81 return true;
82 if(this->minor < other.minor && this->major == other.major)
83 return true;
84 if(this->patch < other.patch &&
85 this->major == other.major &&
86 this->minor == other.minor)
87 return true;
88 return false;
89 }
operator ==(const Version & other)90 bool operator==(const Version& other)
91 {
92 return (this->patch == other.patch && this->major == other.major &&
93 this->minor == other.minor);
94 }
operator <=(const Version & other)95 bool operator <=(const Version& other)
96 { return *this < other || *this == other; }
operator >=(const Version & other)97 bool operator >=(const Version& other)
98 { return !(*this < other); }
operator >(const Version & other)99 bool operator > (const Version& other)
100 { return !(*this < other) && !(*this == other); }
101
102 friend std::ostream& operator<<(std::ostream& out, const Version & v);
103 };
operator <<(std::ostream & out,const Version & v)104 inline std::ostream& operator<<(std::ostream& out, const Version & v)
105 {
106 out << v.major << "." << v.minor << "." << v.patch;
107 return out;
108 }
109
110 class EsriError : public std::runtime_error
111 {
112 public:
EsriError(const std::string txt)113 EsriError(const std::string txt) : std::runtime_error(txt)
114 {}
115 };
116
117 NL::json parse(const std::string& data, const std::string& error);
118 std::vector<lepcc::Point3D> decompressXYZ(std::vector<char>* compData);
119 std::vector<lepcc::RGB_t> decompressRGB(std::vector<char>* compData);
120 std::vector<uint16_t> decompressIntensity(std::vector<char>* compData);
121
122 } // namespace i3s
123 } // namespace pdal
124