SnailCore: 开发实例
[NOTE] Updated October 15, 2020. This article may have outdated content or subject matter.
项目结构
.
├── CMakeLists.txt
└── main.cpp
0 directories, 2 files
CMakeLists.txt
########################################################
snail_add_bin(test main.cpp)
snail_bin_dep(test util shell)
main.cpp
#include <shell/main.hpp>
#include <util/calendar.hpp>
#include <util/log.hpp>
using namespace snail;
using namespace std;
class playground_t: public snail::Main
{
public:
using base_t = snail::Main;
using base_t::base_t;
playground_t() {};
~playground_t() {};
const char* name() const override { return "playground_t"; };
bool do_init() override;
void run() override;
};
bool playground_t::do_init()
{
if (!base_t::do_init()) return false;
return true;
}
void playground_t::run()
{
base_t::run();
for (auto& td : _calendar.trading_days())
{
cout << "night:" << td.night << ", day:" << td.day << endl;
}
if (_calendar.has_session(microtime::now()))
{
cout << "has session:" << microtime::now().to_zgc_str() << endl;
}
}
int main(int argc, char* argv[])
{
playground_t pl;
return pl.main(argc, argv);
}
注意事项
在
bool do_init() override;
的最后,一定要返回return true;
,否则会默认false
,导致后面面的run
不会再继续运行。bool playground_t::do_init() { if (!base_t::do_init()) return false; return true; // 需要加上 }
在
run
继承的时候,最好加上base_t::run();
以保证可以调用其他的参数void playground_t::run() { base_t::run(); // 需要加上 for (auto& td : _calendar.trading_days()) { cout << "night:" << td.night << ", day:" << td.day << endl; } if (_calendar.has_session(microtime::now())) { cout << "has session:" << microtime::now().to_zgc_str() << endl; } }
Author William
LastMod 2020-10-15