Medial Code Documentation
Loading...
Searching...
No Matches
uri_spec.h
Go to the documentation of this file.
1
9#ifndef DMLC_IO_URI_SPEC_H_
10#define DMLC_IO_URI_SPEC_H_
11
12#include <dmlc/common.h>
13#include <string>
14#include <sstream>
15#include <map>
16#include <vector>
17#include <utility>
18
19namespace dmlc {
20namespace io {
28class URISpec {
29 public:
31 std::string uri;
33 std::map<std::string, std::string> args;
35 std::string cache_file;
42 explicit URISpec(const std::string& uri,
43 unsigned part_index,
44 unsigned num_parts) {
45 std::vector<std::string> name_cache = Split(uri, '#');
46
47 if (name_cache.size() == 2) {
48 std::ostringstream os;
49 os << name_cache[1];
50 if (num_parts != 1) {
51 os << ".split" << num_parts << ".part" << part_index;
52 }
53 this->cache_file = os.str();
54 } else {
55 CHECK_EQ(name_cache.size(), 1U)
56 << "only one `#` is allowed in file path for cachefile specification";
57 }
58 std::vector<std::string> name_args = Split(name_cache[0], '?');
59 if (name_args.size() == 2) {
60 std::vector<std::string> arg_list = Split(name_args[1], '&');
61 for (size_t i = 0; i < arg_list.size(); ++i) {
62 std::istringstream is(arg_list[i]);
63 std::pair<std::string, std::string> kv;
64 CHECK(std::getline(is, kv.first, '=')) << "Invalid uri argument format"
65 << " for key in arg " << i + 1;
66 CHECK(std::getline(is, kv.second)) << "Invalid uri argument format"
67 << " for value in arg " << i + 1;
68 this->args.insert(kv);
69 }
70 } else {
71 CHECK_EQ(name_args.size(), 1U)
72 << "only one `#` is allowed in file path for cachefile specification";
73 }
74 this->uri = name_args[0];
75 }
76};
77} // namespace io
78} // namespace dmlc
79#endif // DMLC_IO_URI_SPEC_H_
some super set of URI that allows sugars to be passed around Example:
Definition uri_spec.h:28
std::string cache_file
the path to cache file
Definition uri_spec.h:35
std::map< std::string, std::string > args
arguments in the URL
Definition uri_spec.h:33
URISpec(const std::string &uri, unsigned part_index, unsigned num_parts)
constructor.
Definition uri_spec.h:42
std::string uri
the real URI
Definition uri_spec.h:31
namespace for dmlc
Definition array_view.h:12
std::vector< std::string > Split(const std::string &s, char delim)
Split a string by delimiter.
Definition common.h:23
defines some common utility function.