refactor: cancel the namespace Rust.
- all sub-functions are put into respective position.
This commit is contained in:
@ -29,7 +29,7 @@ In short words, this library use UTF8 encoding everywhere except some special ca
|
||||
\li Traditional format function in yycc::string::op.
|
||||
Traditional format function provide some overloads for ordinary string formatting.
|
||||
That's because this feature is so common to use in some cases.
|
||||
\li The message of Rust panic in yycc::rust::panic.
|
||||
\li The message of Rust panic in yycc::panic.
|
||||
Due to the limitation of \c std::format, we only can use ordinary string as its message content.
|
||||
\li The message of standard library exception.
|
||||
For the compatibility with C++ standard library exception,
|
||||
|
@ -15,7 +15,7 @@ PRIVATE
|
||||
yycc/string/op.cpp
|
||||
yycc/patch/fopen.cpp
|
||||
yycc/patch/stream.cpp
|
||||
yycc/rust/panic.cpp
|
||||
yycc/panic.cpp
|
||||
yycc/env.cpp
|
||||
yycc/windows/com.cpp
|
||||
yycc/windows/dialog.cpp
|
||||
@ -53,6 +53,7 @@ FILES
|
||||
yycc/macro/class_copy_move.hpp
|
||||
yycc/macro/printf_checker.hpp
|
||||
yycc/flag_enum.hpp
|
||||
yycc/string.hpp
|
||||
yycc/string/reinterpret.hpp
|
||||
yycc/string/op.hpp
|
||||
yycc/patch/ptr_pad.hpp
|
||||
@ -64,11 +65,11 @@ FILES
|
||||
yycc/num/safe_cast.hpp
|
||||
yycc/num/safe_op.hpp
|
||||
yycc/num/op.hpp
|
||||
yycc/rust/prelude.hpp
|
||||
yycc/rust/primitive.hpp
|
||||
yycc/rust/panic.hpp
|
||||
yycc/rust/option.hpp
|
||||
yycc/rust/result.hpp
|
||||
yycc/primitive.hpp
|
||||
yycc/option.hpp
|
||||
yycc/result.hpp
|
||||
yycc/prelude.hpp
|
||||
yycc/panic.hpp
|
||||
yycc/env.hpp
|
||||
yycc/windows/import_guard_head.hpp
|
||||
yycc/windows/import_guard_tail.hpp
|
||||
|
@ -7,7 +7,7 @@
|
||||
* This namespace reproduce Rust Option type, and its members Some and None in C++.
|
||||
* However Option is not important than Result, so its implementation is very casual.
|
||||
*/
|
||||
namespace yycc::rust::option {
|
||||
namespace yycc::option {
|
||||
|
||||
template<typename T>
|
||||
using Option = std::optional<T>;
|
||||
@ -22,4 +22,4 @@ namespace yycc::rust::option {
|
||||
return OptionType(std::nullopt);
|
||||
}
|
||||
|
||||
} // namespace yycc::rust::option
|
||||
} // namespace yycc::option
|
@ -1,6 +1,6 @@
|
||||
#include "panic.hpp"
|
||||
#include "../carton/termcolor.hpp"
|
||||
#include "../patch/stream.hpp"
|
||||
#include "carton/termcolor.hpp"
|
||||
#include "patch/stream.hpp"
|
||||
#include <cstdlib>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
@ -10,7 +10,7 @@
|
||||
|
||||
using namespace yycc::patch::stream;
|
||||
|
||||
namespace yycc::rust::panic {
|
||||
namespace yycc::panic {
|
||||
|
||||
void panic(const char* file, int line, const std::u8string_view& msg) {
|
||||
// Output message in stderr.
|
||||
@ -36,4 +36,4 @@ namespace yycc::rust::panic {
|
||||
std::abort();
|
||||
}
|
||||
|
||||
} // namespace yycc::rust::panic
|
||||
} // namespace yycc::panic
|
@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include "../patch/format.hpp"
|
||||
#include "patch/format.hpp"
|
||||
#include <string_view>
|
||||
#include <format>
|
||||
|
||||
@ -21,7 +21,7 @@
|
||||
* In this way, unexpected behavior in our code will cause the program to exit immediately, outputting error information and stack traces.
|
||||
* Standard library exceptions will also cause the program to exit, but without stack information.
|
||||
*/
|
||||
namespace yycc::rust::panic {
|
||||
namespace yycc::panic {
|
||||
|
||||
/**
|
||||
* @brief Immediately crashes the entire program like Rust's \c panic! macro.
|
||||
@ -31,7 +31,7 @@ namespace yycc::rust::panic {
|
||||
* However, this format function is specially modified that it can accept UTF8 format string and UTF8 string argument.
|
||||
* More preciously, it is "format" in \c yycc::patch::format namespace.
|
||||
*/
|
||||
#define RS_PANIC(msg, ...) ::yycc::rust::panic::panic(__FILE__, __LINE__, ::yycc::patch::format::format(msg __VA_OPT__(, ) __VA_ARGS__))
|
||||
#define RS_PANIC(msg, ...) ::yycc::panic::panic(__FILE__, __LINE__, ::yycc::patch::format::format(msg __VA_OPT__(, ) __VA_ARGS__))
|
||||
|
||||
/**
|
||||
* @brief Immediately crashes the entire program like Rust's \c panic! macro.
|
||||
@ -44,4 +44,4 @@ namespace yycc::rust::panic {
|
||||
*/
|
||||
[[noreturn]] void panic(const char* file, int line, const std::u8string_view& msg);
|
||||
|
||||
} // namespace yycc::rust::panic
|
||||
} // namespace yycc::panic
|
49
src/yycc/prelude.hpp
Normal file
49
src/yycc/prelude.hpp
Normal file
@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
// Rust prelude section
|
||||
#include "primitive.hpp"
|
||||
#include "result.hpp"
|
||||
#include "option.hpp"
|
||||
#include "panic.hpp"
|
||||
#include <vector>
|
||||
|
||||
namespace yycc::prelude {
|
||||
// Include primitive types
|
||||
|
||||
#define NS_YYCC_PRIMITIVE ::yycc::primitive
|
||||
|
||||
using i8 = NS_YYCC_PRIMITIVE::i8;
|
||||
using i16 = NS_YYCC_PRIMITIVE::i16;
|
||||
using i32 = NS_YYCC_PRIMITIVE::i32;
|
||||
using i64 = NS_YYCC_PRIMITIVE::i64;
|
||||
using u8 = NS_YYCC_PRIMITIVE::u8;
|
||||
using u16 = NS_YYCC_PRIMITIVE::u16;
|
||||
using u32 = NS_YYCC_PRIMITIVE::u32;
|
||||
using u64 = NS_YYCC_PRIMITIVE::u64;
|
||||
|
||||
using isize = NS_YYCC_PRIMITIVE::isize;
|
||||
using usize = NS_YYCC_PRIMITIVE::usize;
|
||||
|
||||
using f32 = NS_YYCC_PRIMITIVE::f32;
|
||||
using f64 = NS_YYCC_PRIMITIVE::f64;
|
||||
|
||||
using str = NS_YYCC_PRIMITIVE::str;
|
||||
|
||||
#undef NS_YYCC_PRIMITIVE
|
||||
|
||||
// Other types
|
||||
using String = std::u8string;
|
||||
template<typename T>
|
||||
using Vec = std::vector<T>;
|
||||
|
||||
// Expose Result and Option
|
||||
using namespace ::yycc::option;
|
||||
using namespace ::yycc::result;
|
||||
|
||||
// Panic are introduced by including header file
|
||||
// so we do not need re-expose it.
|
||||
|
||||
} // namespace yycc::prelude
|
||||
|
||||
// Expose all members
|
||||
using namespace ::yycc::prelude;
|
@ -3,7 +3,7 @@
|
||||
#include <cstddef>
|
||||
#include <string_view>
|
||||
|
||||
namespace yycc::rust::primitive {
|
||||
namespace yycc::primitive {
|
||||
|
||||
// `bool` is keyword so should not declare it anymore.
|
||||
// `char` is keyword so should not declare it anymore.
|
||||
@ -25,4 +25,3 @@ namespace yycc::rust::primitive {
|
||||
|
||||
using str = std::u8string_view;
|
||||
}
|
||||
|
@ -36,7 +36,7 @@
|
||||
* Similarly, when using \c std::cerr 's \c operator<< overload, you also need to write suitable adapters.
|
||||
* @remarks This namespace only work with environment supporting `std::expected` (i.e. C++ 23).
|
||||
*/
|
||||
namespace yycc::rust::result {
|
||||
namespace yycc::result {
|
||||
|
||||
/**
|
||||
* @brief Equivalent Rust \c Result in C++
|
||||
@ -74,4 +74,4 @@ namespace yycc::rust::result {
|
||||
return ResultType(std::unexpect, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
} // namespace yycc::rust::result
|
||||
} // namespace yycc::result
|
@ -1,49 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
// Rust prelude section
|
||||
#include "primitive.hpp"
|
||||
#include "result.hpp"
|
||||
#include "option.hpp"
|
||||
#include "panic.hpp"
|
||||
#include <vector>
|
||||
|
||||
namespace yycc::rust::prelude {
|
||||
// Include primitive types
|
||||
|
||||
#define NS_RUST_PRIMITIVE ::yycc::rust::primitive
|
||||
|
||||
using i8 = NS_RUST_PRIMITIVE::i8;
|
||||
using i16 = NS_RUST_PRIMITIVE::i16;
|
||||
using i32 = NS_RUST_PRIMITIVE::i32;
|
||||
using i64 = NS_RUST_PRIMITIVE::i64;
|
||||
using u8 = NS_RUST_PRIMITIVE::u8;
|
||||
using u16 = NS_RUST_PRIMITIVE::u16;
|
||||
using u32 = NS_RUST_PRIMITIVE::u32;
|
||||
using u64 = NS_RUST_PRIMITIVE::u64;
|
||||
|
||||
using isize = NS_RUST_PRIMITIVE::isize;
|
||||
using usize = NS_RUST_PRIMITIVE::usize;
|
||||
|
||||
using f32 = NS_RUST_PRIMITIVE::f32;
|
||||
using f64 = NS_RUST_PRIMITIVE::f64;
|
||||
|
||||
using str = NS_RUST_PRIMITIVE::str;
|
||||
|
||||
#undef NS_RUST_PRIMITIVE
|
||||
|
||||
// Other types
|
||||
using String = std::u8string;
|
||||
template<typename T>
|
||||
using Vec = std::vector<T>;
|
||||
|
||||
// Expose Result and Option
|
||||
using namespace ::yycc::rust::option;
|
||||
using namespace ::yycc::rust::result;
|
||||
|
||||
// Panic are introduced by including header file
|
||||
// so we do not need re-expose it.
|
||||
|
||||
} // namespace yycc::prelude::rust
|
||||
|
||||
// Expose all members
|
||||
using namespace ::yycc::rust::prelude;
|
9
src/yycc/string.hpp
Normal file
9
src/yycc/string.hpp
Normal file
@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
// TODO:
|
||||
// Add content safe, Rust-like string container "String"
|
||||
// and string view "str" in there.
|
||||
// Once we add it, all string process function can be migrated as their class member,
|
||||
// or keep them independendly but change the type of parameter into our string types.
|
||||
|
||||
namespace yycc::string {}
|
@ -2,7 +2,7 @@
|
||||
#include <yycc.hpp>
|
||||
#include <yycc/constraint.hpp>
|
||||
|
||||
#include <yycc/rust/prelude.hpp>
|
||||
#include <yycc/prelude.hpp>
|
||||
|
||||
#define CONSTRAINT ::yycc::constraint::Constraint
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include <yycc.hpp>
|
||||
#include <yycc/constraint/builder.hpp>
|
||||
|
||||
#include <yycc/rust/prelude.hpp>
|
||||
#include <yycc/prelude.hpp>
|
||||
|
||||
#define BUILDER ::yycc::constraint::builder
|
||||
using namespace std::literals::string_view_literals;
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include <yycc/flag_enum.hpp>
|
||||
#include <cinttypes>
|
||||
|
||||
#include <yycc/rust/prelude.hpp>
|
||||
#include <yycc/prelude.hpp>
|
||||
|
||||
#define FLAG_ENUM ::yycc::flag_enum
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include <yycc.hpp>
|
||||
#include <yycc/num/op.hpp>
|
||||
|
||||
#include <yycc/rust/prelude.hpp>
|
||||
#include <yycc/prelude.hpp>
|
||||
|
||||
#define OP ::yycc::num::op
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include <yycc.hpp>
|
||||
#include <yycc/num/parse.hpp>
|
||||
|
||||
#include <yycc/rust/prelude.hpp>
|
||||
#include <yycc/prelude.hpp>
|
||||
|
||||
#define PARSE ::yycc::num::parse
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include <yycc/num/safe_cast.hpp>
|
||||
#include <yycc/macro/ptr_size_detector.hpp>
|
||||
|
||||
#include <yycc/rust/prelude.hpp>
|
||||
#include <yycc/prelude.hpp>
|
||||
|
||||
#define CAST ::yycc::num::safe_cast
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
|
||||
#include <yycc/rust/prelude.hpp>
|
||||
#include <yycc/prelude.hpp>
|
||||
|
||||
#define OP ::yycc::num::safe_op
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include <yycc.hpp>
|
||||
#include <yycc/num/stringify.hpp>
|
||||
|
||||
#include <yycc/rust/prelude.hpp>
|
||||
#include <yycc/prelude.hpp>
|
||||
|
||||
#define STRINGIFY ::yycc::num::stringify
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include <yycc.hpp>
|
||||
#include <yycc/string/op.hpp>
|
||||
|
||||
#include <yycc/rust/prelude.hpp>
|
||||
#include <yycc/prelude.hpp>
|
||||
|
||||
#define OP ::yycc::string::op
|
||||
using namespace std::literals::string_view_literals;
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include <yycc.hpp>
|
||||
#include <yycc/string/reinterpret.hpp>
|
||||
|
||||
#include <yycc/rust/prelude.hpp>
|
||||
#include <yycc/prelude.hpp>
|
||||
|
||||
#define REINTERPRET ::yycc::string::reinterpret
|
||||
#define AS_UINT8(p) static_cast<u8>(p)
|
||||
|
Reference in New Issue
Block a user