From 8f88355f36f2f1db3953557e7e24662047408ea2 Mon Sep 17 00:00:00 2001 From: kpl Date: Mon, 23 Mar 2020 10:52:04 -0400 Subject: [PATCH] main.cpp : Updates to include uiTest() and more variadic template experiments. --- main.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/main.cpp b/main.cpp index d4491d8..6b75a57 100644 --- a/main.cpp +++ b/main.cpp @@ -5,17 +5,19 @@ #include "cwFileSys.h" #include "cwTextBuf.h" #include "cwLex.h" +#include "cwText.h" #include "cwNumericConvert.h" #include "cwObject.h" #include "cwThread.h" -#include "cwText.h" #include "cwWebSock.h" #include "cwWebSockSvr.h" #include "cwSerialPort.h" #include "cwSerialPortSrv.h" #include "cwSocket.h" -#include "cwMidi.h" +#include "cwUi.h" +#include "cwUiTest.h" #include "cwTime.h" +#include "cwMidi.h" #include "cwMidiPort.h" #include "cwAudioDevice.h" #include "cwAudioDeviceTest.h" @@ -61,6 +63,43 @@ template } +template< typename T0 > + unsigned fmt_data( char* buf, unsigned n, T0 t0 ) +{ + return cw::toText(buf, n, t0); +} + +template<> + unsigned fmt_data( char* buf, unsigned n, const char* v ) +{ + return cw::toText(buf,n,v); +} + +unsigned to_text_base(char*, unsigned n, unsigned i ) +{ return i; } + +template + unsigned to_text_base( char* buf, unsigned n, unsigned i, T0 t0, T1 t1, ARGS&&... args) +{ + i += fmt_data(buf+i, n-i, t0); + i += fmt_data(buf+i, n-i, t1); + + if( i >= n ) + return i; + + return to_text_base(buf,n,i,std::forward(args)...); +} + +template< typename... ARGS> + unsigned to_text(const char* prefix, char* buf, unsigned n, ARGS&&... args) +{ + unsigned i = cw::toText(buf, n, prefix ); + + return to_text_base(buf,n,i,std::forward(args)...); +} + + + using namespace std; @@ -73,6 +112,12 @@ void variadicTplTest( cw::object_t* cfg, int argc, const char* argv[] ) printf("get: %i %i %i",v0,v1,v2); printf("\n"); + + const int bufN = 32; + char buf[bufN]; + buf[0] = '\0'; + unsigned n = to_text("prefix: ",buf,bufN,"a",1,"b",3.2,"hi","ho"); + printf("%i : %s\n",n,buf); } @@ -252,6 +297,11 @@ void sockMgrTest( cw::object_t* cfg, int argc, const char* argv[] ) return; } +void uiTest( cw::object_t* cfg, int argc, const char* argv[] ) +{ + cw::ui::test(); +} + void socketMdnsTest( cw::object_t* cfg, int argc, const char* argv[] ) { cw::net::mdns::test(); @@ -338,7 +388,7 @@ int main( int argc, const char* argv[] ) { "socketSrvUdp", socketSrvUdpTest }, { "socketSrvTcp", socketSrvTcpTest }, { "sockMgrTest", sockMgrTest }, - + { "uiTest", uiTest }, { "socketMdns", socketMdnsTest }, { "dnssd", dnsSdTest }, { "eucon", euConTest },