int main(int argc, char *argv[]) { log_t *log; log = open_log(_T("-"), _T("json")); if(log == NULL) { puts("Failed."); } open_section(log, _T("compile")); open_item(log); add_value(log, _T("date"), _T(__DATE__)); add_value(log, _T("time"), _T(__TIME__)); close_item(log); open_item(log); add_value(log, _T("file"), _T(__FILE__)); add_value(log, _T("timestamp"), _T(__TIMESTAMP__)); close_item(log); close_section(log); open_section(log, _T("test")); open_item(log); add_value(log, _T("test"), _T("field")); close_item(log); close_section(log); close_log(log); return 0; }
//============================================================================= CubitInstrumentation::~CubitInstrumentation() { // close the token file if (tokenUsageStream) { close_section(); tokenUsageStream->close(); delete tokenUsageStream; } thisInstance = NULL; }
//============================================================================= CubitInstrumentation::SectionState CubitInstrumentation::open_section(SectionState state) { close_section(); if (state == Command) *tokenUsageStream << "<command>" << std::endl; else if (state == GUI) *tokenUsageStream << "<gui>" << std::endl; else if (state == Keyword) *tokenUsageStream << "<keyword>" << std::endl; else return Unknown; return state; }
//============================================================================= void CubitInstrumentation::write_all_words() { if (tokenUsageStream && !keywordMap.empty()) { if (outputState != Keyword) { outputState = open_section(Keyword); } std::map<std::string, int>::iterator it = keywordMap.begin(); std::map<std::string, int>::iterator end = keywordMap.end(); *tokenUsageStream << keywordMap.size() << std::endl; *tokenUsageStream << (*it).first; ++it; for ( ; it != end; it++) { *tokenUsageStream << "," << (*it).first; } close_section(); tokenUsageStream->flush(); } }