Esempio n. 1
0
void NoteReader::go(FILE* inputStream) {
    
    NoteStore noteStore;
    
    std::string command;
    
    while (!feof(inputStream)) {
        command = Util::readNextLine(inputStream);
        
        if (strcmp(command.c_str(), "CREATE") == 0 || strcmp(command.c_str(), "UPDATE") == 0) {
            Note note = Util::readXml(inputStream, "</note>");
            noteStore.updateNote(note);
        }
        if (strcmp(command.c_str(), "DELETE") == 0) {
            std::string guid = Util::readNextLine(inputStream);
            noteStore.deleteNote(guid);
        }
        if (strcmp(command.c_str(), "SEARCH") == 0) {
            std::string term = Util::readNextLine(inputStream);
            NoteCollection noteCollection = noteStore.search(term);
            std::vector<Note> notes = noteCollection.getNotes();
            if (notes.size() == 0) {
                std::cout << "\n";
            } else {
                std::string results = "";
                for (std::vector<Note>::iterator note = notes.begin() ; note != notes.end(); ++note) {
                    results += note->getGuid() + ",";
                }
                std::string output = results.substr(0,results.length()-1);
                std::cout << output << "\n";
            }
            
        }
        
    }
}
Esempio n. 2
0
void NoteStore::updateNote(Note note) {
    this->noteDatabase[note.getGuid()] = note;
};