[問題] pure mvc notify 使用 tuple

作者: diabloevagto (wi)   2016-06-17 14:09:12
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
g++
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
none
問題(Question):
仿照 pure mvc 機制自己做了簡化的 mvc 架構
c++ array 不能塞入的資料都用不同型態,所以傳送 INotification 會有問題
pure mvc 目前是使用 void* 的方式傳送,接收方在強轉型別
目前的版本是使用 std::tuple 實現一個可以塞入不同行別的 array,接收方也可以直接
使用 std::get 取得型態跟資料不用強轉
但這樣的問題是在 MediatorBase 就不能用再做繼承使用 pure vurtual function
因為 NotifyParam 是一個 template class
請問是否有比較好的解決方式
程式碼(Code):(請善用置底文網頁, 記得排版)
https://ideone.com/lwdd2L
這個是單純只有 NotifyParam 的版本,是可以正常執行的
https://ideone.com/J0tR9O
將第 6 行開啟之後開啟 MediatorBase 部份會有編譯錯誤
補充說明(Supplement):
希望達成的功能就是在 NotifyParam 帶的 body 可以像 js 一樣多種型別的 array
↑ 使用 std::tuple
MediatorBase 定義了 virtual void doCommand(NotifyParam notifyParam) = 0;
讓其他的 Mediator 繼承後一定要實作 doCommand
作者: kevingwn (如雲如風的人生)   2016-06-19 18:53:00
你還是得實作對應各個型別的doCommand()並要知道NotifyParam是哪一種 例如https://ideone.com/NaLIih
作者: diabloevagto (wi)   2016-06-21 10:05:00
感謝建議,但目前 Mediator 會有多種型別,各個都實作會有一定程度的負擔...

Links booklink

Contact Us: admin [ a t ] ucptt.com