c++ - Vector of a list of class objects and comparisons -
i have vector looks this:
vector<list<entry> > index;
entry class containing string key , vector of ints line key found in file read in. overloading == operator of class compare key string input, , if matches insert line int vector. if not match insert key , line found. far i've tried work! operator overload looks far:
bool index_table::operator==(string key, vector<list<entry> > index) const { ......code...... }
i can't seem figure out set in operator. utilize vector this:
index[i[j.key]]
i've tried , researched on stack overflow, haven't seem found reply yet.
edit: here class. key string, , has potentially multiple lines associated it. taken care of in entry struct.
class index_table { private: struct entry { string word; vector<list <int> > line; }; vector<list<entry> > index; vector<string>::iterator it; public: index_table(); void insert(string &key, int value); vector<int> & find(string & key) const; bool operator==(string, vector<list<entry> >) const; }; class text_filter { public: text_filter() //sets valid chars { valid = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz_-0123456789"; } void map_to_valid_chars(string&); private: string valid; }; void text_filter::map_to_valid_chars(string& line) //takes line , replaces invalid chars spaces { (int = 0; < line.size(); i++) { if( valid.find(line[i]) == string::npos) { line[i] = ' '; } } } int main(int argc, char **argv) { index_table table; string word, uword; //altered word , unaltered word stringstream ss; vector<string> unaltword; // unaltered words parsed stringstream vector<string> altword; //altered words modified map_to_valid_chars fellow member function text_filter textfilt; int linenum = 0; string searchterm, line; vector<string> lines; ifstream inputfile; string findline; //this finding word in line if (argv[1]) inputfile.open(argv[1]); else { cout << "usage: ./indexfile filename" << endl; exit(1); } //parse words , lines while (getline (inputfile, line)) { while (ss >> uword) { unaltword.push_back(uword); } } altword = unaltword; (int = 0; < altword.size(); i++) { textfilt.map_to_valid_chars(altword[i]); } //insert words , lines index table (int = 0; < lines.size(); i++) { findline = lines[i]; (int j = 0; j < altword.size(); j++) { if (findline.find(altword[j]) != string::npos) table.insert(altword[j], line[i]); } } homecoming 0; }
c++ class object vector
No comments:
Post a Comment