本文整理汇总了C++中py::module::size方法的典型用法代码示例。如果您正苦于以下问题:C++ module::size方法的具体用法?C++ module::size怎么用?C++ module::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类py::module
的用法示例。
在下文中一共展示了module::size方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: python_export_filesystem
void python_export_filesystem(py::module &m) {
using namespace fs;
py::module fs_module =
m.def_submodule("filesystem", "Cross-platform filesystem support");
py::class_<path> path_class(fs_module, "path");
path_class
.def(py::init<>())
.def(py::init<const path &>())
.def(py::init<const std::string &>())
.def("__len__", &path::length)
.def("file_size", &path::file_size)
.def("empty", &path::empty)
.def("is_absolute", &path::is_absolute)
.def("make_absolute", &path::make_absolute)
.def("exists", &path::exists)
.def("is_directory", &path::is_directory)
.def("is_file", &path::is_file)
.def("extension", &path::extension)
.def("parent_path", &path::parent_path)
.def("remove_file", &path::remove_file)
.def("resize_file", &path::resize_file)
.def("str", [](const path &p) { return p.str(); })
.def("str", [](const path &p, path::path_type t) { return p.str(t); })
.def("set", [](path &p, const std::string &v, path::path_type t) { p.set(v, t); })
.def("set", [](path &p, const std::string &v) { p.set(v); })
.def(py::self / py::self)
.def("__repr__", [](const path &p) { return p.str(); })
.def_static("getcwd", &path::getcwd);
py::enum_<path::path_type>(path_class, "path_type")
.value("windows_path", path::windows_path)
.value("posix_path", path::posix_path)
.value("native_path", path::native_path)
.export_values();
py::class_<resolver>(fs_module, "resolver")
.def(py::init<>())
.def("__len__", &resolver::size)
.def("append", &resolver::append)
.def("prepend", &resolver::prepend)
.def("resolve", &resolver::resolve)
.def("__getitem__", [](const resolver &r, size_t i) {
if (i >= r.size())
throw py::index_error();
return r[i];
})
.def("__setitem__", [](resolver &r, size_t i, path &v) {
if (i >= r.size())
throw py::index_error();
r[i] = v;
})
.def("__delitem__", [](resolver &r, size_t i) {
if (i >= r.size())
throw py::index_error();
r.erase(r.begin() + i);
})
.def("__repr__", [](const resolver &r) {
std::ostringstream oss;
oss << r;
return oss.str();
});
py::class_<MemoryMappedFile>(fs_module, "MemoryMappedFile")
.def(py::init<fs::path, size_t>())
.def(py::init<fs::path, bool>())
.def(py::init<fs::path>())
.def("resize", &MemoryMappedFile::resize)
.def("__repr__", &MemoryMappedFile::toString)
.def("size", &MemoryMappedFile::size)
.def("filename", &MemoryMappedFile::filename)
.def("readOnly", &MemoryMappedFile::readOnly)
.def_static("createTemporary", &MemoryMappedFile::createTemporary)
.def_buffer([](MemoryMappedFile &m) -> py::buffer_info {
return py::buffer_info(
m.data(),
sizeof(uint8_t),
py::format_descriptor<uint8_t>::format(),
1,
{ (size_t) m.size() },
{ sizeof(uint8_t) }
);
});
py::implicitly_convertible<std::string, path>();
}