[DEBUG] add missing uri
This commit is contained in:
parent
33604590c6
commit
232fb530db
104
etk/uri/uri.cpp
Normal file
104
etk/uri/uri.cpp
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
/** @file
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
* @copyright 2018, Edouard DUPIN, all right reserved
|
||||||
|
* @license MPL v2.0 (see license file)
|
||||||
|
*/
|
||||||
|
#include <etk/uri/provider/provider.hpp>
|
||||||
|
#include <etk/uri/provider/ProviderFile.hpp>
|
||||||
|
#include <etk/Map.hpp>
|
||||||
|
#include <etk/io/File.hpp>
|
||||||
|
#include <etk/uri/uri.hpp>
|
||||||
|
#include <etk/debug.hpp>
|
||||||
|
|
||||||
|
namespace etk {
|
||||||
|
namespace uri {
|
||||||
|
namespace provider {
|
||||||
|
etk::Map<etk::String, ememory::SharedPtr<etk::uri::provider::Interface>>& getProviders();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool etk::uri::exist(const etk::Uri& _uri) {
|
||||||
|
etk::String scheme = _uri.getScheme();
|
||||||
|
if (scheme.empty() == true) {
|
||||||
|
scheme = "RAW";
|
||||||
|
}
|
||||||
|
if (etk::uri::provider::getProviders().exist(scheme) == false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return etk::uri::provider::getProviders()[scheme]->exist(_uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
etk::Vector<etk::Uri> etk::uri::list(const etk::Uri& _uri) {
|
||||||
|
etk::String scheme = _uri.getScheme();
|
||||||
|
if (scheme.empty() == true) {
|
||||||
|
scheme = "RAW";
|
||||||
|
}
|
||||||
|
if (etk::uri::provider::getProviders().exist(scheme) == false) {
|
||||||
|
return etk::Vector<etk::Uri>();
|
||||||
|
}
|
||||||
|
return etk::uri::provider::getProviders()[scheme]->list(_uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
ememory::SharedPtr<etk::io::Interface> etk::uri::get(const etk::Uri& _uri) {
|
||||||
|
etk::String scheme = _uri.getScheme();
|
||||||
|
if (scheme.empty() == true) {
|
||||||
|
scheme = "RAW";
|
||||||
|
}
|
||||||
|
if (etk::uri::provider::getProviders().exist(scheme) == false) {
|
||||||
|
TK_ERROR("lklklk " << scheme << " " << _uri << " " << etk::uri::provider::getProviders().getKeys());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (_uri.getPath().getString().size() == 0) {
|
||||||
|
TK_WARNING("uri:" << _uri << " Have NO path");
|
||||||
|
}
|
||||||
|
return etk::uri::provider::getProviders()[scheme]->create(_uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool etk::uri::canMove(const etk::Uri& _uri) {
|
||||||
|
etk::String scheme = _uri.getScheme();
|
||||||
|
if (scheme.empty() == true) {
|
||||||
|
scheme = "RAW";
|
||||||
|
}
|
||||||
|
if (etk::uri::provider::getProviders().exist(scheme) == false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return etk::uri::provider::getProviders()[scheme]->canMove();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool etk::uri::move(const etk::Uri& _uriSource, const etk::Uri& _uriDestination) {
|
||||||
|
etk::String scheme = _uriSource.getScheme();
|
||||||
|
if (scheme.empty() == true) {
|
||||||
|
scheme = "RAW";
|
||||||
|
}
|
||||||
|
etk::String scheme2 = _uriDestination.getScheme();
|
||||||
|
if (scheme2.empty() == true) {
|
||||||
|
scheme2 = "RAW";
|
||||||
|
}
|
||||||
|
if (scheme != scheme2) {
|
||||||
|
TK_ERROR("Can not move 2 uri between 2 model of resource... " << _uriSource << " => " << _uriDestination);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (etk::uri::provider::getProviders().exist(scheme) == false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (etk::uri::provider::getProviders()[scheme]->canMove() == false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return etk::uri::provider::getProviders()[scheme]->move(_uriSource, _uriDestination);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool etk::uri::writeAll(const etk::Uri& _uri, const etk::String& _data) {
|
||||||
|
auto fileIo = etk::uri::get(_uri);
|
||||||
|
if (fileIo == null) {
|
||||||
|
TK_ERROR("Can not create the uri: " << _uri);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (fileIo->open(etk::io::OpenMode::Write) == false) {
|
||||||
|
TK_ERROR("Can not open (w) the file : " << _uri);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
fileIo->fileWriteAll(_data);
|
||||||
|
fileIo->close();
|
||||||
|
return true;
|
||||||
|
}
|
58
etk/uri/uri.hpp
Normal file
58
etk/uri/uri.hpp
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
/** @file
|
||||||
|
* @author Edouard DUPIN
|
||||||
|
* @copyright 2018, Edouard DUPIN, all right reserved
|
||||||
|
* @license MPL v2.0 (see license file)
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <etk/types.hpp>
|
||||||
|
|
||||||
|
#include <etk/String.hpp>
|
||||||
|
#include <etk/Map.hpp>
|
||||||
|
#include <etk/uri/Query.hpp>
|
||||||
|
#include <etk/path/Path.hpp>
|
||||||
|
#include <etk/uri/Uri.hpp>
|
||||||
|
#include <etk/uri/provider/provider.hpp>
|
||||||
|
|
||||||
|
namespace etk {
|
||||||
|
namespace uri {
|
||||||
|
/**
|
||||||
|
* @brief Check if an URI really exist.
|
||||||
|
* @param[in] _uri Uri to check.
|
||||||
|
* @return true if exist, false ortherwise
|
||||||
|
*/
|
||||||
|
bool exist(const etk::Uri& _uri);
|
||||||
|
/**
|
||||||
|
* @brief Get the list of sub-element in the Uri
|
||||||
|
* @param[in] _uri Uri requested as parent.
|
||||||
|
* @return list of sub-uri
|
||||||
|
*/
|
||||||
|
etk::Vector<etk::Uri> list(const etk::Uri& _uri);
|
||||||
|
/**
|
||||||
|
* @brief Get an IO interface with a specific URI
|
||||||
|
* @param[in] _uri Data interface requested
|
||||||
|
* @return The interface requested.
|
||||||
|
*/
|
||||||
|
ememory::SharedPtr<etk::io::Interface> get(const etk::Uri& _uri);
|
||||||
|
/**
|
||||||
|
* @brief Check if an URI Can be moved.
|
||||||
|
* @param[in] _uri Uri to check.
|
||||||
|
* @return true if it is possible, false ortherwise
|
||||||
|
*/
|
||||||
|
bool canMove(const etk::Uri& _uri);
|
||||||
|
/**
|
||||||
|
* @brief Move an element for a source to a destination.
|
||||||
|
* @param[in] _uriSource Source Uri.
|
||||||
|
* @param[in] _uriDestination Destination Uri.
|
||||||
|
* @return true if moved, false ortherwise
|
||||||
|
*/
|
||||||
|
bool move(const etk::Uri& _uriSource, const etk::Uri& _uriDestination);
|
||||||
|
/**
|
||||||
|
* @brief Write all a string in a uri (if possible)
|
||||||
|
* @param[in] _uri Uri destination.
|
||||||
|
* @param[in] _data Data to write.
|
||||||
|
* @return true All data are write, false otherwise.
|
||||||
|
*/
|
||||||
|
bool writeAll(const etk::Uri& _uri, const etk::String& _data);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user