| 1 |
// Copyright (c) 2005-2009 Hartmut Kaiser |
|---|
| 2 |
// |
|---|
| 3 |
// Distributed under the Boost Software License, Version 1.0. (See accompanying |
|---|
| 4 |
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
|---|
| 5 |
|
|---|
| 6 |
#include <ctime> |
|---|
| 7 |
#include <iostream> |
|---|
| 8 |
|
|---|
| 9 |
#include <saga/saga/exception.hpp> |
|---|
| 10 |
#include <saga/saga/url.hpp> |
|---|
| 11 |
#include <saga/saga/adaptors/task.hpp> |
|---|
| 12 |
|
|---|
| 13 |
#include <saga/impl/config.hpp> |
|---|
| 14 |
|
|---|
| 15 |
#include "local_url.hpp" |
|---|
| 16 |
|
|---|
| 17 |
/////////////////////////////////////////////////////////////////////////////// |
|---|
| 18 |
namespace adaptors |
|---|
| 19 |
{ |
|---|
| 20 |
/////////////////////////////////////////////////////////////////////////// |
|---|
| 21 |
url_cpi_impl::url_cpi_impl (proxy* p, cpi_info const& info, |
|---|
| 22 |
saga::ini::ini const& glob_ini, saga::ini::ini const& adap_ini, |
|---|
| 23 |
TR1::shared_ptr<saga::adaptor> adaptor) |
|---|
| 24 |
: base_cpi(p, info, adaptor, cpi::Noflags) |
|---|
| 25 |
{ |
|---|
| 26 |
// first usage of this adaptor |
|---|
| 27 |
saga::url url; |
|---|
| 28 |
{ |
|---|
| 29 |
instance_data data (this); |
|---|
| 30 |
url = data->url_; |
|---|
| 31 |
} |
|---|
| 32 |
|
|---|
| 33 |
std::string scheme(url.get_scheme()); |
|---|
| 34 |
if (!scheme.empty() && scheme != "any" && scheme != "file") |
|---|
| 35 |
{ |
|---|
| 36 |
SAGA_OSSTREAM strm; |
|---|
| 37 |
strm << "Cannot handle schemes other than 'any' or 'file': " |
|---|
| 38 |
<< url.get_string(); |
|---|
| 39 |
SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::IncorrectURL); |
|---|
| 40 |
} |
|---|
| 41 |
} |
|---|
| 42 |
|
|---|
| 43 |
url_cpi_impl::~url_cpi_impl (void) |
|---|
| 44 |
{ |
|---|
| 45 |
} |
|---|
| 46 |
|
|---|
| 47 |
// SAGA API function |
|---|
| 48 |
void url_cpi_impl::sync_translate(saga::url& retval, std::string required_scheme) |
|---|
| 49 |
{ |
|---|
| 50 |
if (!required_scheme.empty() && required_scheme != "file") |
|---|
| 51 |
{ |
|---|
| 52 |
SAGA_OSSTREAM strm; |
|---|
| 53 |
strm << "Cannot convert to schemes other than 'file', " |
|---|
| 54 |
"requested scheme is: " << required_scheme; |
|---|
| 55 |
SAGA_ADAPTOR_THROW(SAGA_OSSTREAM_GETSTRING(strm), saga::BadParameter); |
|---|
| 56 |
} |
|---|
| 57 |
|
|---|
| 58 |
saga::url url; |
|---|
| 59 |
{ |
|---|
| 60 |
instance_data data (this); |
|---|
| 61 |
url = data->url_; |
|---|
| 62 |
} |
|---|
| 63 |
|
|---|
| 64 |
std::string scheme(url.get_scheme()); |
|---|
| 65 |
if (scheme.empty() || scheme == "any") |
|---|
| 66 |
url.set_scheme("file"); |
|---|
| 67 |
|
|---|
| 68 |
retval = url; |
|---|
| 69 |
} |
|---|
| 70 |
|
|---|
| 71 |
#if ! defined(SAGA_DEFAULT_URL_ADAPTOR_NO_ASYNCS) |
|---|
| 72 |
/////////////////////////////////////////////////////////////////////////// |
|---|
| 73 |
saga::task url_cpi_impl::async_translate(std::string scheme) |
|---|
| 74 |
{ |
|---|
| 75 |
return saga::adaptors::task("url_cpi_impl::sync_translate", |
|---|
| 76 |
shared_from_this(), &url_cpi_impl::sync_translate, scheme); |
|---|
| 77 |
} |
|---|
| 78 |
#endif |
|---|
| 79 |
|
|---|
| 80 |
/////////////////////////////////////////////////////////////////////////////// |
|---|
| 81 |
} |
|---|
| 82 |
|
|---|