[Liblas-commits] hg: 3 new changesets
liblas-commits at liblas.org
liblas-commits at liblas.org
Thu Dec 23 13:41:04 EST 2010
changeset 8ae8487eaa18 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=8ae8487eaa18
summary: note about release id
changeset 1b06a665cce8 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=1b06a665cce8
summary: add a liblas_error, and a few other derived exceptions, all based on std::runtime_error
changeset c6a03c45ec13 in /Volumes/Data/www/liblas.org/hg
details: http://hg.liblas.orghg?cmd=changeset;node=c6a03c45ec13
summary: modify liblas::Schema::GetDimension to return boost::optional< Dimension const& >
diffstat:
HOWTORELEASE.txt | 4 +++
include/liblas/exception.hpp | 28 ++++++++++++++++++++++
include/liblas/schema.hpp | 5 ++-
src/header.cpp | 19 ++++++++++----
src/point.cpp | 56 ++++++++++++++++++++++----------------------
src/schema.cpp | 21 ++++++++++------
src/transform.cpp | 9 +++---
test/unit/point_test.cpp | 4 +-
8 files changed, 96 insertions(+), 50 deletions(-)
diffs (truncated from 332 to 300 lines):
diff -r 96d4bc513ec7 -r c6a03c45ec13 HOWTORELEASE.txt
--- a/HOWTORELEASE.txt Thu Dec 23 11:46:48 2010 -0600
+++ b/HOWTORELEASE.txt Thu Dec 23 12:40:52 2010 -0600
@@ -37,6 +37,10 @@
- python/setup.py
+ - src/header.cpp
+
+ char const* const Header::SoftwareIdentifier = "libLAS 1.6.0b2";
+
2) Update README to include any relevant info about the release that
might have changed.
diff -r 96d4bc513ec7 -r c6a03c45ec13 include/liblas/exception.hpp
--- a/include/liblas/exception.hpp Thu Dec 23 11:46:48 2010 -0600
+++ b/include/liblas/exception.hpp Thu Dec 23 12:40:52 2010 -0600
@@ -71,6 +71,34 @@
unsigned int m_who;
};
+class liblas_error : public std::runtime_error
+{
+public:
+
+ liblas_error(std::string const& msg)
+ : std::runtime_error(msg)
+ {}
+};
+
+class invalid_expression : public liblas_error
+{
+public:
+
+ invalid_expression(std::string const& msg)
+ : liblas_error(msg)
+ {}
+};
+
+class invalid_format : public liblas_error
+{
+public:
+
+ invalid_format(std::string const& msg)
+ : liblas_error(msg)
+ {}
+};
+
+
} // namespace liblas
#endif // LIBLAS_EXCEPTION_HPP_INCLUDED
diff -r 96d4bc513ec7 -r c6a03c45ec13 include/liblas/schema.hpp
--- a/include/liblas/schema.hpp Thu Dec 23 11:46:48 2010 -0600
+++ b/include/liblas/schema.hpp Thu Dec 23 12:40:52 2010 -0600
@@ -54,6 +54,7 @@
#include <boost/shared_ptr.hpp>
#include <boost/foreach.hpp>
#include <boost/array.hpp>
+#include <boost/optional.hpp>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/member.hpp>
@@ -126,8 +127,8 @@
void SetDataFormatId(PointFormatName const& value);
void AddDimension(Dimension const& dim);
- Dimension const& GetDimension(std::string const& n) const;
- Dimension const& GetDimension(index_by_index::size_type t) const;
+ boost::optional< Dimension const& > GetDimension(std::string const& n) const;
+ boost::optional< Dimension const& > GetDimension(index_by_index::size_type t) const;
// DimensionPtr GetDimension(std::size_t index) const;
void RemoveDimension(Dimension const& dim);
diff -r 96d4bc513ec7 -r c6a03c45ec13 src/header.cpp
--- a/src/header.cpp Thu Dec 23 11:46:48 2010 -0600
+++ b/src/header.cpp Thu Dec 23 12:40:52 2010 -0600
@@ -692,23 +692,30 @@
m_schema = format;
- Dimension x = m_schema.GetDimension("X");
+ // Reset the X, Y, Z dimensions with offset and scale values
+ boost::optional< Dimension const& > x_c = m_schema.GetDimension("X");
+ if (!x_c)
+ throw liblas_error("X dimension not on schema, you\'ve got big problems!");
+ liblas::Dimension x(*x_c);
x.SetScale(m_scales.x);
x.IsFinitePrecision(true);
x.SetOffset(m_offsets.x);
- m_schema.SetDimension(x);
+ m_schema.AddDimension(x);
- Dimension y = m_schema.GetDimension("Y");
+ boost::optional< Dimension const& > y_c = m_schema.GetDimension("Y");
+ liblas::Dimension y(*y_c);
y.SetScale(m_scales.y);
y.IsFinitePrecision(true);
y.SetOffset(m_offsets.y);
- m_schema.SetDimension(y);
+ m_schema.AddDimension(y);
- Dimension z = m_schema.GetDimension("Z");
+ boost::optional< Dimension const& > z_c = m_schema.GetDimension("Z");
+
+ liblas::Dimension z(*z_c);
z.SetScale(m_scales.z);
z.IsFinitePrecision(true);
z.SetOffset(m_offsets.z);
- m_schema.SetDimension(z);
+ m_schema.AddDimension(z);
}
diff -r 96d4bc513ec7 -r c6a03c45ec13 src/point.cpp
--- a/src/point.cpp Thu Dec 23 11:46:48 2010 -0600
+++ b/src/point.cpp Thu Dec 23 12:40:52 2010 -0600
@@ -190,10 +190,17 @@
{
boost::uint16_t wanted_length;
- if (header.get())
+ const liblas::Schema* schema;
+ if (header.get()) {
wanted_length = header->GetDataRecordLength();
+ schema = &header->GetSchema();
+
+ }
else
+ {
wanted_length = m_default_header.GetDataRecordLength();
+ schema = &m_default_header.GetSchema();
+ }
// This is hopefully faster than copying everything if we don't have
// any data set and nothing to worry about.
@@ -233,21 +240,13 @@
SetUserData(p.GetUserData());
SetPointSourceID(p.GetPointSourceID());
- try
- {
+ boost::optional< Dimension const& > t = schema->GetDimension("Time");
+ if (t)
SetTime(p.GetTime());
- }
- catch (std::runtime_error const&)
- {
- }
-
- try
- {
+
+ boost::optional< Dimension const& > c = schema->GetDimension("Red");
+ if (c)
SetColor(p.GetColor());
- }
- catch (std::runtime_error const&)
- {
- }
// FIXME: copy other custom dimensions here? resetting the
// headerptr can be catastrophic in a lot of cases.
@@ -792,7 +791,7 @@
std::ostringstream msg;
msg << "Point::SetTime - Unable to set time for ePointFormat0 or ePointFormat2, "
<< "no Time dimension exists on this format";
- throw std::runtime_error(msg.str());
+ throw liblas::invalid_format(msg.str());
}
// std::vector<boost::uint8_t>::size_type pos = GetDimensionBytePosition(index_pos);
@@ -849,10 +848,6 @@
}
if ( f == ePointFormat0 || f == ePointFormat1 ) {
- // std::ostringstream msg;
- // msg << "Point::GetColor - Unable to set color for ePointFormat0 or ePointFormat1, "
- // << "no Color dimension exists on this format";
- // throw std::runtime_error(msg.str());
return Color(0, 0, 0);
}
@@ -899,14 +894,14 @@
std::ostringstream msg;
msg << "Point::SetColor - Unable to set color for ePointFormat0 or ePointFormat1, "
<< "no Color dimension exists on this format";
- throw std::runtime_error(msg.str());
+ throw liblas::invalid_format(msg.str());
}
if ( m_data.size() == ePointFormat0 || f == ePointFormat1 ) {
std::ostringstream msg;
msg << "Point::SetColor - Unable to set color for ePointFormat0 or ePointFormat1, "
<< "no Color dimension exists on this format";
- throw std::runtime_error(msg.str());
+ throw liblas::invalid_format(msg.str());
}
using liblas::detail::intToBits;
@@ -931,15 +926,20 @@
std::vector<boost::uint8_t>::size_type Point::GetDimensionBytePosition(std::size_t dim_pos) const
{
- std::size_t output = 0;
+ boost::optional<Dimension const&> d;
if (m_header) {
- Dimension const& d = m_header->GetSchema().GetDimension(dim_pos);
- output = d.GetByteOffset();
+ d = m_header->GetSchema().GetDimension(dim_pos);
} else {
- Dimension const& d = m_default_header.GetSchema().GetDimension(dim_pos);
- output = d.GetByteOffset();
- }
- return output;
+ d= m_default_header.GetSchema().GetDimension(dim_pos);
+ }
+
+ if (!d)
+ {
+ std::ostringstream oss;
+ oss <<"Dimension at position " << dim_pos << " not found";
+ throw liblas_error(oss.str());
+ }
+ return d->GetByteOffset();
}
boost::any Point::GetValue(Dimension const& d) const
diff -r 96d4bc513ec7 -r c6a03c45ec13 src/schema.cpp
--- a/src/schema.cpp Thu Dec 23 11:46:48 2010 -0600
+++ b/src/schema.cpp Thu Dec 23 12:40:52 2010 -0600
@@ -690,25 +690,30 @@
CalculateSizes();
}
-Dimension const& Schema::GetDimension(std::string const& n) const
+
+
+boost::optional< Dimension const& > Schema::GetDimension(std::string const& n) const
{
index_by_name::const_iterator it = m_index.get<name>().find(n);
if (it != m_index.get<name>().end())
{
- return *it;
+ liblas::Dimension const& d = *it;
+ return boost::optional<liblas::Dimension const&>(d);
}
-
- std::ostringstream oss;
- oss << "Dimension with name '" << n << "' not found.";
- throw std::runtime_error(oss.str());
+
+ return boost::optional< Dimension const& >();
}
-Dimension const& Schema::GetDimension(index_by_index::size_type t) const
+boost::optional< Dimension const& > Schema::GetDimension(index_by_index::size_type t) const
{
index_by_index const& idx = m_index.get<index>();
- return idx.at(t);
+
+ if (t <= idx.size())
+ return boost::optional<liblas::Dimension const&>(idx.at(t));
+ else
+ return boost::optional<liblas::Dimension const&>();
}
void Schema::SetDimension(Dimension const& dim)
diff -r 96d4bc513ec7 -r c6a03c45ec13 src/transform.cpp
--- a/src/transform.cpp Thu Dec 23 11:46:48 2010 -0600
+++ b/src/transform.cpp Thu Dec 23 12:40:52 2010 -0600
@@ -40,6 +40,7 @@
****************************************************************************/
#include <liblas/transform.hpp>
+#include <liblas/exception.hpp>
#include <liblas/header.hpp>
// boost
#include <boost/concept_check.hpp>
@@ -194,7 +195,7 @@
if (expr.find(x) == std::string::npos &&
expr.find(y) == std::string::npos &&
expr.find(z) == std::string::npos)
- throw std::runtime_error("expression is invalid -- use x, y, or z to define a dimension. No 'x', 'y', or 'z' was found");
+ throw liblas::invalid_expression("expression is invalid -- use x, y, or z to define a dimension. No 'x', 'y', or 'z' was found");
operation output("X");
@@ -215,7 +216,7 @@
if (found_x != std::string::npos &&
found_y != std::string::npos &&
found_z != std::string::npos)
- throw std::runtime_error("expression is invalid");
+ throw liblas::invalid_expression("expression is invalid");
std::string::size_type op_pos=std::string::npos;
if (found_x != std::string::npos)
@@ -240,7 +241,7 @@
More information about the Liblas-commits
mailing list