Add mj_containsFileVFS and mj_containsBufferVFS functions.
PiperOrigin-RevId: 903785790 Change-Id: I013b37a177284f8440179c4ae5c6221e0f572b49
This commit is contained in:
committed by
Copybara-Service
parent
c3fddf5dc1
commit
4cfebcc32b
@@ -236,6 +236,24 @@ VFS::Status VFS::Unmount(const FilePath& path) {
|
||||
return kInvalidResourceProvider;
|
||||
}
|
||||
|
||||
bool VFS::ContainsBuffer(const char* name) {
|
||||
if (name == nullptr) {
|
||||
return false;
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
return mounts_.contains(name);
|
||||
}
|
||||
|
||||
bool VFS::ContainsFile(const char* directory, const char* filename) {
|
||||
if (filename == nullptr) {
|
||||
return false;
|
||||
}
|
||||
mujoco::user::FilePath path(directory ? directory : "", filename);
|
||||
std::string key = path.StripPath().Lower().Str();
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
return mounts_.contains(key);
|
||||
}
|
||||
|
||||
int VFS::Read(mjResource* resource, const void** buffer) {
|
||||
if (resource && resource->provider && resource->provider->read) {
|
||||
return resource->provider->read(resource, buffer);
|
||||
@@ -498,3 +516,22 @@ int mj_deleteFileVFS(mjVFS* vfs, const char* filename) {
|
||||
}
|
||||
return mujoco::user::VFS::kSuccess;
|
||||
}
|
||||
|
||||
int mj_containsBufferVFS(mjVFS* vfs, const char* name) {
|
||||
mujoco::user::VFS* impl = mujoco::user::VFS::Upcast(vfs);
|
||||
if (impl == nullptr) {
|
||||
mju_error("mjVFS is null.");
|
||||
return -1;
|
||||
}
|
||||
return impl->ContainsBuffer(name);
|
||||
}
|
||||
|
||||
int mj_containsFileVFS(mjVFS* vfs, const char* directory, const char* filename) {
|
||||
mujoco::user::VFS* impl = mujoco::user::VFS::Upcast(vfs);
|
||||
if (impl == nullptr) {
|
||||
mju_error("mjVFS is null.");
|
||||
return -1;
|
||||
}
|
||||
return impl->ContainsFile(directory, filename);
|
||||
}
|
||||
|
||||
|
||||
@@ -90,6 +90,12 @@ class VFS {
|
||||
// Unmounts the ResourceProvider from the given path.
|
||||
Status Unmount(const FilePath& path);
|
||||
|
||||
// Returns true if the VFS contains a buffer with the given name.
|
||||
bool ContainsBuffer(const char* name);
|
||||
|
||||
// Returns true if the VFS contains a file with the given name.
|
||||
bool ContainsFile(const char* directory, const char* filename);
|
||||
|
||||
// Sets a destructor to be called when the VFS has no more open resources.
|
||||
// Assumes that `destructor` will delete `this`.
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user