-
Notifications
You must be signed in to change notification settings - Fork 562
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(resource_resolver): add class and unit test
- Loading branch information
Showing
3 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// Copyright RIME Developers | ||
// Distributed under the BSD License | ||
// | ||
|
||
#include <rime/resource_resolver.h> | ||
|
||
namespace rime { | ||
|
||
boost::filesystem::path ResourceResolver::ResolvePath(const string& resource_id) { | ||
return boost::filesystem::absolute( | ||
boost::filesystem::path(type_.prefix + resource_id + type_.suffix), | ||
root_path_); | ||
} | ||
|
||
} // namespace rime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// Copyright RIME Developers | ||
// Distributed under the BSD License | ||
// | ||
|
||
#ifndef RIME_RESOURCE_RESOLVER_H_ | ||
#define RIME_RESOURCE_RESOLVER_H_ | ||
|
||
#include <boost/filesystem.hpp> | ||
#include <rime/common.h> | ||
|
||
namespace rime { | ||
|
||
class ResourceResolver; | ||
|
||
struct ResourceType { | ||
string name; | ||
string prefix; | ||
string suffix; | ||
}; | ||
|
||
class ResourceResolver { | ||
public: | ||
explicit ResourceResolver(const ResourceType type) : type_(type) { | ||
} | ||
boost::filesystem::path ResolvePath(const string& resource_id); | ||
void set_root_path(const boost::filesystem::path& root_path) { | ||
root_path_ = root_path; | ||
} | ||
boost::filesystem::path root_path() const { | ||
return root_path_; | ||
} | ||
private: | ||
const ResourceType type_; | ||
boost::filesystem::path root_path_; | ||
}; | ||
|
||
} // namespace rime | ||
|
||
#endif // RIME_RESOURCE_RESOLVER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <gtest/gtest.h> | ||
#include <rime/resource_resolver.h> | ||
|
||
using namespace rime; | ||
|
||
TEST(RimeResourceResolverTest, ResolvePath) { | ||
const auto type = ResourceType{ | ||
"minerals", | ||
"not_", | ||
".minerals", | ||
}; | ||
the<ResourceResolver> rr(new ResourceResolver(type)); | ||
rr->set_root_path("/starcraft"); | ||
auto actual = rr->ResolvePath("enough"); | ||
boost::filesystem::path expected = "/starcraft/not_enough.minerals"; | ||
EXPECT_TRUE(expected == actual); | ||
} |