コード例 #1
0
LfcCommandTable * Analyzer::Analyze(LogTable * logTable) {
    vector<Item *> * items = logTable->getMyList();
    LfcCommandTable * commandList = new LfcCommandTable();

    map<FunctionType, State *> objectMap = createStateMap();

    int index = -1;

    std::vector<Item *>::const_iterator iterator;
    for (iterator = items->begin(); iterator != items->end(); ++iterator) {
        Item * item = *iterator;
        index++;

        if (!item->IsAssigned()) {
            FunctionType functionName = item->GetCommand()->getName();
            if (objectMap.find(functionName) != objectMap.end()) {
                item->SetAssigned(true);
                this->currentState = objectMap.at(functionName);
                int addition = index + 3500;
                if (addition > items->size()) {
                    addition = items->size();
                }
                std::vector<Item *> subRows(items->begin() + index + 1, items->begin() + addition);
                std::vector<Item *>::const_iterator iterator = subRows.begin();
                
                LogTime * backUpEndTime = new LogTime(item->GetEndTime()->miliseconds());
                string backUpFilePath = item->GetFilePath();
                string backUpInformation = item->GetInformation();
                int backUpTid = item->GetTid(); 
                
                LfcCommand * command = currentState->NextState(iterator, subRows, item);
                if (command != NULL) {
                    commandList->add(command);
                    currentState->PrintMessage("ANALYZER: ADDED COMMAND " + command->GetStringName(), item);
                } else {
                    item->SetEndTime(backUpEndTime);
                    item->SetFilePath(backUpFilePath);
                    item->SetInformation(backUpInformation);
                    item->SetTid(backUpTid);
                    item->SetAssigned(false);
                    currentState->PrintMessage("ANALYZER: RETURNED NULL", item);
                }
            }
        }
    }

    int notAssigned = 0;
    std::vector<Item *>::const_iterator iterator2;
    for (iterator2 = items->begin(); iterator2 != items->end(); ++iterator2) {
        Item * item = *iterator2;
        if (!item->IsAssigned()) {
            notAssigned++;
        }
    }
    cout << "not assigned items to command: " << notAssigned << endl;

    return commandList;
}