void EuphonyPlayer::updateParser() { for (bool loop = true; loop;) { uint8 cmd = _musicPos[0]; if (cmd == 0xff || cmd == 0xf7) { proceedToNextEvent(); } else if (cmd < 0x90) { _endOfTrack = true; clearHangingNotes(); loop = false; } else if (_parseToBar > _bar) { loop = false; } else { if (_parseToBar == _bar) { uint16 parseToBeat = ((_musicPos[3] << 8) | ((_musicPos[2] << 1) & 0xff)) >> 1; if (parseToBeat > _beat) loop = false; } if (loop) { if (parseEvent()) loop = false; } } }
void sageDisplayManager::mainLoop() { while(!rcvEnd) { sageEvent *newEvent = shared->eventQueue->getEvent(); //std::cout << "get the event " << newEvent->eventType << std::endl; parseEvent(newEvent); } }
void Watcher::monitor() { struct inotify_event *event; event = (inotify_event*)malloc(sizeof(struct inotify_event) + NAME_MAX + 1); while(true) { read(watchfile, event, sizeof(struct inotify_event) + NAME_MAX + 1); parseEvent(event); } free(event); }
void AsteriskManager::read() { while(m_tcpSocket->canReadLine()) { QString message = QString::fromUtf8(m_tcpSocket->readLine()); if (m_isSignedIn == false) { QString msg = message.trimmed(); if (msg.contains("Asterisk Call Manager")) setAsteriskVersion(msg); if (msg == "Message: Authentication accepted") { m_isSignedIn = true; m_autoConnectingOnError = false; m_timer.stop(); setState(CONNECTED); } else if(msg == "Message: Authentication failed") { m_timer.stop(); m_tcpSocket->abort(); m_isSignedIn = false; m_autoConnectingOnError = false; setState(AUTHENTICATION_FAILED); } } else { if (message != "\r\n") { m_eventData.append(message); } else if (!m_eventData.isEmpty()) { if (m_currentVersion == VERSION_13) { parseEvent(m_eventData); } else if (m_currentVersion == VERSION_11) { asterisk_11_eventHandler(m_eventData); } m_eventData.clear(); } } emit messageReceived(message.trimmed()); } }
const QStringList WarframeDataGrabber::parseAllEvents() const { QStringList eventsReturn; if(eventList.isEmpty()) { eventsReturn.append(QString("(%1) No available events at the moment.").arg( WarframeInfo::platformString(platformEnum).toUpper())); return eventsReturn; } else { for(const StructsWarframe::Event &eventInfo: eventList.values()) { eventsReturn.append(parseEvent(eventInfo)); } } return eventsReturn; }
bool PerfConfigEventsModel::setData(const QModelIndex &dataIndex, const QVariant &value, int role) { if (role != Qt::EditRole) return false; const int row = dataIndex.row(); const int column = dataIndex.column(); QStringList events = m_settings->events(); EventDescription description = parseEvent(events[row]); switch (column) { case ColumnEventType: description.eventType = qvariant_cast<EventType>(value); break; case ColumnSubType: switch (description.eventType) { case EventTypeHardware: case EventTypeSoftware: case EventTypeCache: description.subType = qvariant_cast<SubType>(value); break; case EventTypeRaw: description.numericEvent = value.toULongLong(); break; case EventTypeBreakpoint: description.numericEvent = value.toULongLong(); break; case EventTypeCustom: description.customEvent = value.toString(); break; default: break; } break; case ColumnOperation: description.operation = value.toInt(); break; case ColumnResult: description.result = qvariant_cast<Result>(value); break; } events[row] = generateEvent(description); m_settings->setEvents(events); emit dataChanged(index(row, ColumnEventType), index(row, ColumnResult)); return true; }
bool MD_MFTrack::getNextEvent(MD_MIDIFile *mf, uint16_t tickCount) // track_event = <time:v> + [<midi_event> | <meta_event> | <sysex_event>] { uint32_t deltaT; // is there anything to process? if (_endOfTrack) return(false); // move the file pointer to where we left off mf->_fd.seekSet(_startOffset+_currOffset); // Work out new total elapsed ticks - include the overshoot from // last event. _elapsedTicks += tickCount; // Get the DeltaT from the file in order to see if enough ticks have // passed for the event to be active. deltaT = readVarLen(&mf->_fd); // If not enough ticks, just return without saving the file pointer and // we will go back to the same spot next time. if (_elapsedTicks < deltaT) return(false); // Adjust the total elapsed time to the error against actual DeltaT to avoid // accumulation of errors, as we only check for _elapsedTicks being >= ticks, // giving positive biased errors every time. _elapsedTicks -= deltaT; DUMP("\ndT: ", deltaT); DUMP(" + ", _elapsedTicks); DUMPS("\t"); parseEvent(mf); // remember the offset for next time _currOffset = mf->_fd.curPosition() - _startOffset; // catch end of track when there is no META event _endOfTrack = _endOfTrack || (_currOffset >= _length); if (_endOfTrack) DUMPS(" - OUT OF TRACK"); return(true); }
void XDesktopContainer::eventLoop() { XEvent ev; #ifdef HAVE_STARTUP_NOTIFICATION sn_context = NULL; sn_display = NULL; sn_bool_t retval; sn_display = sn_display_new (display, error_trap_push, error_trap_pop); #endif /* HAVE_STARTUP_NOTIFICATION */ for(;;) { if( !XPending( display ) && timer){ if(!bg->IsOneShot()){ timer->Update(); } } else { XNextEvent(display, &ev); #ifdef HAVE_STARTUP_NOTIFICATION if (sn_display != NULL){ sn_display_process_event (sn_display, &ev); } #endif /* HAVE_STARTUP_NOTIFICATION */ event = ev; parseEvent(); } } #ifdef HAVE_STARTUP_NOTIFICATION sn_launcher_context_unref (sn_context); if (sn_display) { sn_display_unref (sn_display); } #endif /* HAVE_STARTUP_NOTIFICATION */ }
void sJarvisNode::parsePacket(QString& packet) { // qDebug() << "Packet:" << packet; QStringList args; args = packet.split(P_PACKETSEPARATOR); if(args.count() < 2) return; // qDebug() << "Packet:" << args; if (args[0] != M_JARVISMSG) return; args.removeFirst(); QString arg = args[0]; args.removeFirst(); if (arg == C_ID) { if(args.count() == 1) m_id = args[0]; }else if(arg == C_PONG) { pong(); }else if(arg == C_COMPONENT) { parseComponent(args); // }else if(arg == C_SENSOR) // { // parseSensor(args); }else if(arg == C_SENSORS) { parseSensors(args); }else if(arg == E_EVENT) { parseEvent(args); }else { qDebug() << "[sJarvisNode::parsePacket]daFuckIsThis:"<< args; } }
bool LogFile::getCurrentEvent() { if (coursor_ == timeVector_.end()) return false; logReader_.rdPtr(coursor_->second); logReader_.parseEventHeader(event_.header.fixed_header); while (!validEvent()) { ++coursor_; if (coursor_ == timeVector_.end()) { return false; } logReader_.rdPtr(coursor_->second); logReader_.parseEventHeader(event_.header.fixed_header); } parseEvent(); return true; }
void CEngine::exec() { print_debug(DEBUG_ANALYZER, "in main cycle"); QTime t; t.start(); if (eventPipe.isEmpty()) return; print_debug(DEBUG_ANALYZER, "trying to dequeue the pipe ..."); event = eventPipe.getEvent(); print_debug(DEBUG_ANALYZER, "preparing to call the event parser..."); parseEvent(); print_debug(DEBUG_ANALYZER, "updating regions"); updateRegions(); print_debug(DEBUG_ANALYZER, "done. Time elapsed %d ms", t.elapsed()); return; }
void sJarvisNode::parseComponent(QStringList args) { if(m_initDone) return; m_initTimer.start(200); m_components.append(new sJarvisNodeComponent(this,args)); connect(this,SIGNAL(incomingEvent(QString,jarvisEvents,QStringList)),m_components.last(),SLOT(parseEvent(QString,jarvisEvents,QStringList))); emit newComponent(m_components.last()); }
void main() { uint8_t guid[16]; char buf[512]; int i,j,k; int rv; printf("GUID test 1\n"); const char *strGUID0 = ""; memset( guid, 0xff, 16 ); rv = parseGuid( strGUID0, NULL, guid ); if ( rv ) printf("GUID="" fail\n"); for ( i=0; i<16; i++ ) { if ( 0 != guid[i] ) { printf("GUID="" fail. Index=%d\n", i); } } printf("GUID test 2\n"); const char *strGUID1 = "-"; memset( guid, 0xff, 16 ); rv = parseGuid( strGUID1, NULL, guid ); if ( rv ) printf("GUID='-' fail\n"); for ( int i=0; i<16; i++ ) { if ( 0 != guid[i] ) { printf("GUID='-' fail. Index=%d\n", i); } } printf("GUID test 3\n"); const char *strGUID2 = "00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF"; const uint8_t GUID2_array[] = {0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xAA,0xBB,0xCC,0xDD,0xEE,0xFF}; memset( guid, 0xff, 16 ); rv = parseGuid( strGUID2, NULL, guid ); if ( VSCP_ERROR_SUCCESS != rv ) printf("GUID='00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF' parser return fail\n"); for ( i=0; i<16; i++ ) { if ( GUID2_array[i] != guid[i] ) { printf("GUID='00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF' fail. Index=%d\n", i); } } printf("GUID test 4\n"); const char *strGUID3 = "00:11:22:33:44:55:66:77:88:99:AA:BB:CC:"; const uint8_t GUID3_array[] = {0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xAA,0xBB,0xCC,0x00,0x00,0x00}; memset( guid, 0xff, 16 ); rv = parseGuid( strGUID3, NULL, guid ); if ( VSCP_ERROR_SUCCESS != rv ) printf("GUID='00:11:22:33:44:55:66:77:88:99:AA:BB:CC:' parser return fail\n"); for ( i=0; i<16; i++ ) { if ( GUID3_array[i] != guid[i] ) { printf("GUID='00:11:22:33:44:55:66:77:88:99:AA:BB:CC:' fail. Index=%d\n", i); } } printf("GUID test 5\n"); const char *strGUID4 = "00:11:22:33:44:55:66:77:88:99:AA:BB:CC"; const uint8_t GUID4_array[] = {0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xAA,0xBB,0xCC,0x00,0x00,0x00}; memset( guid, 0xff, 16 ); rv = parseGuid( strGUID4, NULL, guid ); if ( VSCP_ERROR_SUCCESS != rv ) printf("GUID='00:11:22:33:44:55:66:77:88:99:AA:BB:CC' parser return fail\n"); for ( i=0; i<16; i++ ) { if ( GUID4_array[i] != guid[i] ) { printf("GUID='00:11:22:33:44:55:66:77:88:99:AA:BB:CC' fail. Index=%d\n", i); } } printf("GUID test 6\n"); const char *strGUID5 = "00:11:22:33:44:YW:66:77:88:99:AA:BB:CC:01:02:03"; const uint8_t GUID5_array[] = {0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xAA,0xBB,0xCC,0x01,0x02,0x03}; memset( guid, 0xff, 16 ); rv = parseGuid( strGUID5, NULL, guid ); if ( VSCP_ERROR_SUCCESS == rv ) printf("GUID='00:11:22:33:44:YW:66:77:88:99:AA:BB:CC:01:02:03' parser return success but should have returned failure.\n"); printf("GUID test 7\n"); const char *strGUID6 = "00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF,11,22,33,44,55"; const uint8_t GUID6_array[] = {0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x88,0x99,0xAA,0xBB,0xCC,0xDD,0xEE,0xFF}; memset( guid, 0xff, 16 ); rv = parseGuid( strGUID6, NULL, guid ); if ( VSCP_ERROR_SUCCESS != rv ) printf("GUID='00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF,11,22,33,44,55' parser return fail\n"); for ( i=0; i<16; i++ ) { if ( GUID6_array[i] != guid[i] ) { printf("GUID='00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF,11,22,33,44,55' fail. Index=%d\n", i); } } // ------------------------------------------------------------------------ printf("Filter test 1 (filter)\n"); vscpEventFilter evfilter; memset( &evfilter, 0, sizeof(vscpEventFilter) ); if ( VSCP_ERROR_SUCCESS != parseFilter( "2,0x20,6,00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF", &evfilter ) ) { printf("Failed on filter test 1\n"); } if ( evfilter.filter_priority != 2 ) printf("Filter test 1 - filter_priority fail.\n"); if ( evfilter.filter_class != 32 ) printf("Filter test 1 - filter_class fail.\n"); if ( evfilter.filter_type != 6 ) printf("Filter test 1 - filter_type fail.\n"); for ( i=0; i<16; i++ ) { if ( GUID2_array[i] != evfilter.filter_GUID[i] ) { printf("Filter test 1 GUID='00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF' fail. Index=%d\n", i); } } // ------------------------------------------------------------------------ printf("Filter test 2 (mask)\n"); memset( &evfilter, 0, sizeof(vscpEventFilter) ); if ( VSCP_ERROR_SUCCESS != parseMask( "0x22,1,077,00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF", &evfilter ) ) { printf("Failed on filter test 2\n"); } if ( evfilter.mask_priority != 34 ) printf("Filter test 2 - mask_priority fail.\n"); if ( evfilter.mask_class != 1 ) printf("Filter test 2 - mask_class fail.\n"); if ( evfilter.mask_type != 63 ) printf("Filter test 2 - mask_type fail.\n"); for ( i=0; i<16; i++ ) { if ( GUID2_array[i] != evfilter.mask_GUID[i] ) { printf("Filter test 1 GUID='00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF' fail. Index=%d\n", i); } } // ------------------------------------------------------------------------ printf("Event test 1 (standard)\n"); vscpEvent ev; memset( &ev, 0, sizeof(vscpEvent) ); if ( VSCP_ERROR_SUCCESS != parseEvent( "1,0x21,3,1234567,2062-11-17T19:32:44,7654321,00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF,11,0x22,33,0x44,55", &ev ) ) { printf("Failed on event test 1\n"); } if ( ev.head != 1 ) printf("Event test 1, head failed.\n"); if ( ev.vscp_class != 0x21 ) printf("Event test 1, vscp_class failed.\n"); if ( ev.vscp_type != 3 ) printf("Event test 1, vscp_type failed.\n"); if ( ev.obid != 1234567 ) printf("Event test 1, obid failed.\n"); if ( ev.year != 2062 ) printf("Event test 1, year failed.\n"); if ( ev.month != 11 ) printf("Event test 1, month failed.\n"); if ( ev.day != 17 ) printf("Event test 1, day failed.\n"); if ( ev.hour != 19 ) printf("Event test 1, hour failed.\n"); if ( ev.minute != 32 ) printf("Event test 1, minute failed.\n"); if ( ev.second != 44 ) printf("Event test 1, second failed.\n"); if ( ev.timestamp != 7654321 ) printf("Event test 1, timestamp failed.\n"); if ( ev.sizeData != 5 ) printf("Event test 1, sizeData failed (%d).\n", (int)ev.sizeData ); for ( i=0; i<16; i++ ) { if ( GUID2_array[i] != ev.GUID[i] ) { printf("Event test 1, GUID='00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF' fail. Index=%d\n", i); } } if ( NULL == ev.pdata ) { printf("Event test 1, pdata == NULL, Failure\n"); } else { if ( ev.pdata[0] != 11 ) printf("Event test 1, Data byte 0 failed.\n"); if ( ev.pdata[1] != 0x22 ) printf("Event test 1, Data byte 1 failed.\n"); if ( ev.pdata[2] != 33 ) printf("Event test 1, Data byte 2 failed.\n"); if ( ev.pdata[3] != 0x44 ) printf("Event test 1, Data byte 3 failed.\n"); if ( ev.pdata[4] != 55 ) printf("Event test 1, Data byte 4 failed.\n"); } // ------------------------------------------------------------------------ printf("Event test 2 (standard)\n"); memset( &ev, 0, sizeof(vscpEvent) ); if ( VSCP_ERROR_SUCCESS != parseEvent( "1,0x21,3,,,,00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF,11,0x22,33,0x44,55", &ev ) ) { printf("Failed on event test 2\n"); } if ( ev.head != 1 ) printf("Event test 2, head failed.\n"); if ( ev.vscp_class != 0x21 ) printf("Event test 2, vscp_class failed.\n"); if ( ev.vscp_type != 3 ) printf("Event test 2, vscp_type failed.\n"); if ( ev.obid != 0 ) printf("Event test 2, obid failed.\n"); if ( ev.year != 0 ) printf("Event test 2, year failed.\n"); if ( ev.month != 0 ) printf("Event test 2, month failed.\n"); if ( ev.day != 0 ) printf("Event test 2, day failed.\n"); if ( ev.hour != 0 ) printf("Event test 2, hour failed.\n"); if ( ev.minute != 0 ) printf("Event test 2, minute failed.\n"); if ( ev.second != 0 ) printf("Event test 2, second failed.\n"); if ( ev.timestamp != 0 ) printf("Event test 2, timestamp failed.\n"); if ( ev.sizeData != 5 ) printf("Event test 2, sizeData failed (%d).\n", (int)ev.sizeData ); for ( i=0; i<16; i++ ) { if ( GUID2_array[i] != ev.GUID[i] ) { printf("Event test 2, GUID='00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF' fail. Index=%d\n", i); } } if ( NULL == ev.pdata ) { printf("Event test 2, pdata == NULL, Failure\n"); } else { if ( ev.pdata[0] != 11 ) printf("Event test 2, Data byte 0 failed.\n"); if ( ev.pdata[1] != 0x22 ) printf("Event test 2, Data byte 1 failed.\n"); if ( ev.pdata[2] != 33 ) printf("Event test 2, Data byte 2 failed.\n"); if ( ev.pdata[3] != 0x44 ) printf("Event test 2, Data byte 3 failed.\n"); if ( ev.pdata[4] != 55 ) printf("Event test 2, Data byte 4 failed.\n"); } // ------------------------------------------------------------------------ printf("EventEx test 1 (extended)\n"); vscpEventEx evex; memset( &evex, 0, sizeof(vscpEventEx) ); if ( VSCP_ERROR_SUCCESS != parseEventEx( "1,0x21,3,1234567,2062-11-17T19:32:44,7654321,00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF,11,0x22,33,0x44,55", &evex ) ) { printf("Failed on eventex test 1\n"); } if ( evex.head != 1 ) printf("EventEx test 1, head failed.\n"); if ( evex.vscp_class != 0x21 ) printf("EventEx test 1, vscp_class failed.\n"); if ( evex.vscp_type != 3 ) printf("EventEx test 1, vscp_type failed.\n"); if ( evex.obid != 1234567 ) printf("EventEx test 1, obid failed.\n"); if ( evex.year != 2062 ) printf("EventEx test 1, year failed.\n"); if ( evex.month != 11 ) printf("EventEx test 1, month failed.\n"); if ( evex.day != 17 ) printf("EventEx test 1, day failed.\n"); if ( evex.hour != 19 ) printf("EventEx test 1, hour failed.\n"); if ( evex.minute != 32 ) printf("EventEx test 1, minute failed.\n"); if ( evex.second != 44 ) printf("EventEx test 1, second failed.\n"); if ( evex.timestamp != 7654321 ) printf("EventEx test 1, timestamp failed.\n"); if ( evex.sizeData != 5 ) printf("EventEx test 1, sizeData failed (%d).\n", (int)evex.sizeData ); for ( i=0; i<16; i++ ) { if ( GUID2_array[i] != evex.GUID[i] ) { printf("EventEx test 1, GUID='00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF' fail. Index=%d\n", i); } } if ( evex.data[0] != 11 ) printf("EventEx test 1, Data byte 0 failed.\n"); if ( evex.data[1] != 0x22 ) printf("EventEx test 1, Data byte 1 failed.\n"); if ( evex.data[2] != 33 ) printf("EventEx test 1, Data byte 2 failed.\n"); if ( evex.data[3] != 0x44 ) printf("EventEx test 1, Data byte 3 failed.\n"); if ( evex.data[4] != 55 ) printf("EventEx test 1, Data byte 4 failed.\n"); // ------------------------------------------------------------------------ printf("Event to string test\n"); if ( VSCP_ERROR_SUCCESS != parseEvent( "1,0x21,3,1234567,2062-11-17T19:32:44,7654321,00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF,011,0x22,33,0x44,55", &ev ) ) { printf("Event to string test failed creating event\n"); } if ( VSCP_ERROR_SUCCESS != eventToString( &ev, buf, sizeof( buf ) ) ) { printf("Failed to convert event to string\n"); } else { printf("IN :%s\n", "1,0x21,3,1234567,2062-11-17T19:32:44,7654321,00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF,011,0x22,33,0x44,55" ); printf("OUT:%s\n", buf ); } }
QVariant PerfConfigEventsModel::data(const QModelIndex &index, int role) const { switch (role) { case Qt::DisplayRole: case Qt::EditRole: break; // Retrieve the actual value default: return QVariant(); // ignore } QString event = m_settings->events().value(index.row()); const EventDescription description = parseEvent(event); switch (index.column()) { case ColumnEventType: { if (role == Qt::DisplayRole) { if (description.eventType == EventTypeInvalid) return QVariant(); auto meta = QMetaEnum::fromType<EventType>(); return QString::fromLatin1(meta.valueToKey(description.eventType)) .mid(static_cast<int>(strlen("EventType"))).toLower(); } return description.eventType; } case ColumnSubType: { switch (description.eventType) { case EventTypeHardware: case EventTypeSoftware: case EventTypeCache: if (role == Qt::DisplayRole) return subTypeString(description.eventType, description.subType); return description.subType; case EventTypeRaw: if (role == Qt::DisplayRole) return QString("r%1").arg(description.numericEvent, 3, 16, QLatin1Char('0')); else return description.numericEvent; case EventTypeBreakpoint: if (role == Qt::DisplayRole) return QString("0x%1").arg(description.numericEvent, 16, 16, QLatin1Char('0')); else return description.numericEvent; case EventTypeCustom: return description.customEvent; default: return QVariant(); } } case ColumnOperation: if (role == Qt::DisplayRole) { if (description.eventType == EventTypeBreakpoint) { QString result; if (description.operation & OperationLoad) result += 'r'; if (description.operation & OperationStore) result += 'w'; if (description.operation & OperationExecute) result += 'x'; return result; } if (description.eventType == EventTypeCache) { if (description.operation == OperationInvalid) return QVariant(); auto meta = QMetaEnum::fromType<Operation>(); return QString::fromLatin1(meta.valueToKey(description.operation)).mid( static_cast<int>(strlen("Operation"))).toLower(); } return QVariant(); } return description.operation; case ColumnResult: if (role == Qt::DisplayRole) { if (description.result == ResultInvalid) return QVariant(); auto meta = QMetaEnum::fromType<Result>(); return QString::fromLatin1(meta.valueToKey(description.result)).mid( static_cast<int>(strlen("Result"))).toLower(); } return description.result; default: return QVariant(); } }
void WizardsPlugin::CreateClass(const NewClassInfo &info) { // Start by finding the best choice for tabs/spaces. // Use the preference for the target VirtualDir, not the active project, in case the user perversely adds to an inactive one. OptionsConfigPtr options = EditorConfigST::Get()->GetOptions(); // Globals first wxString TargetProj = info.virtualDirectory.BeforeFirst(wxT(':')); if (!TargetProj.empty()) { LocalWorkspaceST::Get()->GetOptions(options, TargetProj); // Then override with any local ones } wxString separator(wxT("\t")); if (!options->GetIndentUsesTabs()) { separator = wxString(wxT(' '), wxMax(1, options->GetTabWidth())); } wxString macro(info.blockGuard); if( macro.IsEmpty() ) { // use the name instead macro = info.name; macro.MakeUpper(); macro << (info.hppHeader ? wxT("_HPP") : wxT("_H")); } wxString headerExt = (info.hppHeader ? wxT(".hpp") : wxT(".h")); wxString srcFile; srcFile << info.path << wxFileName::GetPathSeparator() << info.fileName << wxT(".cpp"); wxString hdrFile; hdrFile << info.path << wxFileName::GetPathSeparator() << info.fileName << headerExt; //create cpp + h file wxString cpp; wxString header; //---------------------------------------------------- // header file //---------------------------------------------------- header << wxT("#ifndef ") << macro << wxT("\n"); header << wxT("#define ") << macro << wxT("\n"); header << wxT("\n"); wxString closeMethod; if (info.isInline) closeMethod << wxT('\n') << separator << wxT("{\n") << separator << wxT("}\n"); else closeMethod = wxT(";\n"); // Add include for base classes if (info.parents.empty() == false) { for (size_t i=0; i< info.parents.size(); i++) { ClassParentInfo pi = info.parents.at(i); // Include the header name only (no paths) wxFileName includeFileName(pi.fileName); header << wxT("#include \"") << includeFileName.GetFullName() << wxT("\" // Base class: ") << pi.name << wxT("\n"); } header << wxT("\n"); } // Open namespace if (!info.namespacesList.IsEmpty()) { WriteNamespacesDeclaration (info.namespacesList, header); } header << wxT("class ") << info.name; if (info.parents.empty() == false) { header << wxT(" : "); for (size_t i=0; i< info.parents.size(); i++) { ClassParentInfo pi = info.parents.at(i); header << pi.access << wxT(" ") << pi.name << wxT(", "); } header = header.BeforeLast(wxT(',')); } header << wxT("\n{\n"); if (info.isSingleton) { header << separator << wxT("static ") << info.name << wxT("* ms_instance;\n\n"); } if (info.isAssingable == false) { //declare copy constructor & assingment operator as private header << wxT("private:\n"); header << separator << info.name << wxT("(const ") << info.name << wxT("& rhs)") << closeMethod; header << separator << info.name << wxT("& operator=(const ") << info.name << wxT("& rhs)") << closeMethod; header << wxT("\n"); } if (info.isSingleton) { header << wxT("public:\n"); header << separator << wxT("static ") << info.name << wxT("* Instance();\n"); header << separator << wxT("static void Release();\n\n"); header << wxT("private:\n"); header << separator << info.name << wxT("();\n"); if (info.isVirtualDtor) { header << separator << wxT("virtual ~") << info.name << wxT("();\n\n"); } else { header << separator << wxT('~') << info.name << wxT("();\n\n"); } } else { header << wxT("public:\n"); header << separator << info.name << wxT("()") << closeMethod; if (info.isVirtualDtor) { header << separator << wxT("virtual ~") << info.name << wxT("()") << closeMethod << wxT("\n"); } else { header << separator << wxT('~') << info.name << wxT("()") << closeMethod << wxT("\n"); } } //add virtual function declaration wxString v_decl = DoGetVirtualFuncDecl(info, separator); if (v_decl.IsEmpty() == false) { header << wxT("public:\n"); header << v_decl; } header << wxT("};\n\n"); // Close namespaces for (unsigned int i = 0; i < info.namespacesList.Count(); i++) { header << wxT("}\n\n"); } header << wxT("#endif // ") << macro << wxT("\n"); wxFFile file; file.Open(hdrFile, wxT("w+b")); file.Write(header); file.Close(); //if we have a selected virtual folder, add the files to it wxArrayString paths; paths.Add(hdrFile); //---------------------------------------------------- // source file //---------------------------------------------------- if (!info.isInline) { cpp << wxT("#include \"") << info.fileName << headerExt << wxT("\"\n\n"); // Open namespace if (!info.namespacesList.IsEmpty()) { WriteNamespacesDeclaration (info.namespacesList, cpp); } if (info.isSingleton) { cpp << info.name << wxT("* ") << info.name << wxT("::ms_instance = 0;\n\n"); } //ctor/dtor cpp << info.name << wxT("::") << info.name << wxT("()\n"); cpp << wxT("{\n}\n\n"); cpp << info.name << wxT("::~") << info.name << wxT("()\n"); cpp << wxT("{\n}\n\n"); if (info.isSingleton) { cpp << info.name << wxT("* ") << info.name << wxT("::Instance()\n"); cpp << wxT("{\n"); cpp << separator << wxT("if (ms_instance == 0) {\n"); cpp << separator << separator << wxT("ms_instance = new ") << info.name << wxT("();\n"); cpp << separator << wxT("}\n"); cpp << separator << wxT("return ms_instance;\n"); cpp << wxT("}\n\n"); cpp << wxT("void ") << info.name << wxT("::Release()\n"); cpp << wxT("{\n"); cpp << separator << wxT("if (ms_instance) {\n"); cpp << separator << separator << wxT("delete ms_instance;\n"); cpp << separator << wxT("}\n"); cpp << separator << wxT("ms_instance = 0;\n"); cpp << wxT("}\n\n"); } cpp << DoGetVirtualFuncImpl(info); // Close namespaces if (info.namespacesList.Count()) { cpp << wxT('\n'); // Thow in an initial \n to separate the first namespace '}' from the previous function's one } for (unsigned int i = 0; i < info.namespacesList.Count(); i++) { cpp << wxT("}\n\n"); } file.Open(srcFile, wxT("w+b")); file.Write(cpp); file.Close(); paths.Add(srcFile); } // We have a .cpp and an .h file, and there may well be a :src and an :include folder available // So try to place the files appropriately. If that fails, dump both in the selected folder bool smartAddFiles = EditorConfigST::Get()->GetOptions()->GetOptions() & OptionsConfig::Opt_SmartAddFiles; if (!smartAddFiles || ! m_mgr->AddFilesToVirtualFolderIntelligently(info.virtualDirectory, paths) ) m_mgr->AddFilesToVirtualFolder(info.virtualDirectory, paths); // Open the newly created classes in codelite for(size_t i=0; i<paths.GetCount(); i++) { m_mgr->OpenFile(paths.Item(i)); } // Notify codelite to parse the files wxCommandEvent parseEvent(wxEVT_COMMAND_MENU_SELECTED, XRCID("retag_workspace")); EventNotifier::Get()->TopFrame()->GetEventHandler()->AddPendingEvent(parseEvent); }