<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          推薦一個開源輔助網(wǎng)站programcreek

          共 2259字,需瀏覽 5分鐘

           ·

          2021-11-04 14:44

          關(guān)注、星標(biāo)公眾號,直達(dá)精彩內(nèi)容

          來源:技術(shù)讓夢想更偉大

          作者:李肖遙


          開發(fā)中經(jīng)常遇到api如何使用,或者省略時間可以直接使用一些開源的代碼,programcreek很好的解決這個問題,這個網(wǎng)站可以提供最簡單的demo,快速獲知一個API的使用,開發(fā)中讓我們事半功倍,大家可以用用。

          網(wǎng)站地址:https://www.programcreek.com/

          首頁界面:

          我們看看c++ code Examples

          我們搜索一下state machine,看到找到了4 個與“狀態(tài)機”相關(guān)的 C++ 代碼示例,看看代碼寫的怎么樣 很多例子寫的很好,甚至可以直接使用。

          void?ReplicationThread::CallbacksStateMachine::ConnEventCB(
          ????bufferevent?*bev,?int16_t?events,?void?*state_machine_ptr)?{
          ??if?(events?&?BEV_EVENT_CONNECTED)?{
          ????//?call?write_cb?when?connected
          ????bufferevent_data_cb?write_cb;
          ????bufferevent_getcb(bev,?nullptr,?&write_cb,?nullptr,?nullptr);
          ????if?(write_cb)?write_cb(bev,?state_machine_ptr);
          ????return;
          ??}
          ??if?(events?&?(BEV_EVENT_ERROR?|?BEV_EVENT_EOF))?{
          ????LOG(ERROR)?<"[replication]?connection?error/eof,?reconnect?the?master";
          ????//?Wait?a?bit?and?reconnect
          ????auto?state_m?=?static_cast(state_machine_ptr);
          ????state_m->repl_->repl_state_?=?kReplConnecting;
          ????std::this_thread::sleep_for(std::chrono::seconds(1));
          ????state_m->Stop();
          ????state_m->Start();
          ??}
          }?

          再看看C++ open source Projects

          我們搜索一下state machine,看到有4個相關(guān)項目,還有分層有限狀態(tài)機框架HFSM2和高性能分層有限狀態(tài)機框架HFSM2。

          我們點開HSFM

          Basic?Usage
          //?1.?Include?HFSM?header:
          #include?

          //?2.?Define?interface?class?between?the?FSM?and?its?owner
          //????(also?ok?to?use?the?owner?object?itself):
          struct?Context?{?/*?...?*/?};

          //?3.?(Optional)?Typedef?hfsm::Machine?for?convenience:
          using?M?=?hfsm::Machine;

          //?4.?Define?states:
          struct?MyState1?:?M::Bare?{
          ????//?5.?Override?some?of?the?following?state?functions:
          ????void?enter(Context&?_);
          ????void?update(Context&?_);
          ????void?transition(Control&?c,?Context&?_);
          ????void?leave(Context&?_);
          };

          struct?MyState2?:?M::Bare?{?/*?..?*/?};
          struct?MySubState1?:?M::Bare?{?/*?..?*/?};
          struct?MySubState2?:?M::Bare?{?/*?..?*/?};

          struct?MyState3?:?M::Bare?{?/*?..?*/?};
          struct?MyOrthogonalState1?:?M::Bare?{?/*?..?*/?};
          struct?MyOrthogonalState2?:?M::Bare?{?/*?..?*/?};

          //?6.?Declare?state?machine?structure:
          using?MyFSM?=?M::PeerRoot<
          ????MyState1,
          ????M::Composite????????MySubState1,
          ????????MySubState2,
          ????>,
          ????M::Orthogonal????????MyOrthogonalState1,
          ????????MyOrthogonalState2,
          ????>
          >;

          int?main()?{
          ????//?7.?Create?context?and?state?machine?instances:
          ????Context?context;
          ????MyFSM?fsm(context);

          ????//?8.?Kick?off?periodic?updates:
          ????bool?running?=?true;
          ????while?(running)
          ????????fsm.update();

          ????return?0;
          }

          總的來說,這個programcreek很不錯,發(fā)現(xiàn)一些好的工具或者網(wǎng)站可以使我們開發(fā)效率提高,這也是我們站在巨人的肩膀上的意義。

          ???????????????? ?END ?????????????????

          關(guān)注我的微信公眾號,回復(fù)“加群”按規(guī)則加入技術(shù)交流群。

          歡迎關(guān)注我的視頻號:


          點擊“閱讀原文”查看更多分享,歡迎點分享、收藏、點贊、在看。

          瀏覽 77
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  午夜精品一区二区三区视频免费看 | 精品夜夜澡人妻无码AV | 直接看黄色电影 | 91麻豆国产福利 | 色五月婷婷丁香五月婷婷 |