Commit 37c122fe authored by Rashad Kanavath's avatar Rashad Kanavath

ENH: move FindFileHandle struct to seperate file

parent eca0056e
......@@ -58,6 +58,9 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/ossim)
file(GLOB_RECURSE ossimplugins_gdal_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/gdal/*.cpp")
file(GLOB_RECURSE ossimplugins_ossim_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/ossim/*.cpp")
if(NOT WIN32)
list(REMOVE_ITEM ossimplugins_ossim_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/ossim/ossimWin32FindFileHandle.cpp")
endif()
set(ossimplugins_SOURCES
${ossimplugins_gdal_SRCS}
${ossimplugins_ossim_SRCS}
......
......@@ -20,6 +20,10 @@
#include <iostream>
#include <cassert>
#if defined(_MSC_VER)
#include "ossimWin32FindFileHandle.h"
#endif
#if defined(USE_BOOST_TIME)
using boost::posix_time::microseconds;
using boost::posix_time::seconds;
......@@ -516,7 +520,7 @@ namespace ossimplugins
#if defined(_MSC_VER)
strm << file.path() << pathsep << d << pathsep << "*" << ext;
FindFileHandle handle(strm.str());
ossimWin32FindFileHandle handle(strm.str());
if (handle.is_valid()) {
do {
result.push_back(handle.crt_filename());
......
......@@ -33,37 +33,6 @@
class OSSIMDLLEXPORT ossimXmlNode;
class OSSIMDLLEXPORT ossimString;
#if defined(_MSC_VER)
#include <windows.h>
struct FindFileHandle {
explicit FindFileHandle(std::string const& path) {
memset(&m_search_data, 0, sizeof(WIN32_FIND_DATA));
m_h = FindFirstFile(path.c_str(), &m_search_data);
if (!is_valid() && (GetLastError() != ERROR_FILE_NOT_FOUND)) {
char err_msg[1024];
ossimplugins::s_printf(err_msg, "ossimSentinel1Model: cannot list file in directory '%s' : '%d'", path, GetLastError());
throw std::runtime_error( err_msg );
}
}
bool is_valid() const { return m_h != INVALID_HANDLE_VALUE; }
~FindFileHandle() { if (is_valid()) FindClose(m_h); }
bool next() {
assert(is_valid());
return (FindNextFile(m_h, &m_search_data) == true);
}
std::string crt_filename() const { return m_search_data.cFileName; }
private:
HANDLE m_h;
WIN32_FIND_DATA m_search_data;
};
#endif
namespace ossimplugins
{
......
#include <cassert>
#include "ossimStringUtilities.h"
#include "ossimWin32FindFileHandle.h"
namespace ossimplugins {
ossimWin32FindFileHandle::ossimWin32FindFileHandle(std::string const& path)
{
memset(&m_search_data, 0, sizeof(WIN32_FIND_DATA));
m_h = FindFirstFile(path.c_str(), &m_search_data);
if (!is_valid() && (GetLastError() != ERROR_FILE_NOT_FOUND))
{
char err_msg[1024];
s_printf(err_msg, "ossimSentinel1Model: cannot list file in directory '%s' : '%d'", path, GetLastError());
throw std::runtime_error( err_msg );
}
}
bool ossimWin32FindFileHandle::is_valid() const
{
return m_h != INVALID_HANDLE_VALUE;
}
ossimWin32FindFileHandle::~ossimWin32FindFileHandle()
{
if (is_valid())
FindClose(m_h);
}
bool ossimWin32FindFileHandle::next()
{
assert(is_valid());
return (FindNextFile(m_h, &m_search_data) == true);
}
std::string ossimWin32FindFileHandle::crt_filename() const
{
return m_search_data.cFileName;
}
}
\ No newline at end of file
#ifndef ossimWin32FindFileHandle_HEADER
#define ossimWin32FindFileHandle_HEADER
#include <windows.h>
#include <string>
namespace ossimplugins {
struct ossimWin32FindFileHandle {
explicit ossimWin32FindFileHandle(std::string const& path);
bool is_valid() const;
~ossimWin32FindFileHandle();
bool next();
std::string crt_filename() const;
private:
HANDLE m_h;
WIN32_FIND_DATA m_search_data;
};
}
#endif
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment