class textquery{
public:
typedef std::vector<std::string>::size_type line_no;
void read_file(std::ifstream &is)
{
store_file(is);
build_map();
}
std::set<line_no>run_query(const std::string &) const;
std::string text_line(line_no ) const;
private:
void story_file(std::ifstream &);
void build_map();
std::vector<std::string>lines_of_text;
std::map<std::string,std::set<line_no>> word_map;
}
void story_file(std::ifstream &in)
{
}
void textquery::build_map()
{
for(line_no line_num=0;line_num!=lines_of_text.size();line_num++)
{
istringstream line(lines_of_text[line_num]);
string word;
while(line>>word)
word_map[word].insert(line_num);
}
}
set<textquery::line_no> textquery::run_query(const string &query_word) const
{
map<string,set<line_no>> ::const_iterator it=word_map.find(query_word);
if(it==word_map.end())
return set<line_no>();
else
return it->second;
}
string textquery::text_line(line_no line)
{
if(line<lines_of_text.size())
return lines_of_text[line];
}
class screen{
public :screen& move(index r,index c);
screen & set(char);
screen & display() const;
typedef char (screen::*callback)(int);
}
screen &screen::set(char c)
{
///
return *this;//static函数没有this 指针
}
screen & screen::display()
{
//
callback call;
call=classa::funcb;
obj_screen.(*call)(3);// 实际回调funcb
return *this; // 这个this指针是一个const screen* 型的
// 这样的话:m_objscreen.display().set(' ');错误的display() 返回 const引用,不能嵌入到长表达式
}
class screen{
friend class window;//友元类
friend window::relocate(window::index,screen &);//友元函数
private:
static int x;// static 可以私有
public :
static int y;//相当于全局变量,
static void display();//不能声明为const 型: 承诺不修改 它所在类所属的对象
}
window::relocate(window::index,screen &);//友元函数//可以引用screen 中的私有成员
class window {
window(screen & s); //可以引用screen 中的私有成员
}
class Message
{
public :
Message(const std::string str=" "):content(str){}
Message(const Message &);
Message &operator=(const Message &);
~Message();
void save(Folder &);
void remove(Folder &);
private :
std:string content;
std::set<Folder*>folder;
void put_msg_in_fold(const set<Folder*>&);
void remove_msg_from_fold();
};
Message &Message ::operator=(const Message &rhs)
{
if(&rhs!=this)
{
remove_msg_from_fold();
contents=rhs.content;
folder=rhs.folder;
put_msg_in_fold(folder);
}
}
Message ::Message(const Message &m):content(m.content),folder(m.folder)
{
put_msg_in_fold(folder);
}
Message ::Message(const std::string &str=" "):content(str) //隐式的将folder 初始化为空
{
}
void Message::put_msg_in_fold(const set<Folder*> &rhs)
{
for(std::set<Folder*>::const_iterator beg=rhs.begin();beg!=rhs.end();++beg)
(*beg)->addmessage(this);
}
Message::~Message()
{
remove_msg_from_fold(); //清除folder,系统自动调用string 析构掉content 自动调用set 析构清除用于保存folder成员的内存
}
public:
typedef std::vector<std::string>::size_type line_no;
void read_file(std::ifstream &is)
{
store_file(is);
build_map();
}
std::set<line_no>run_query(const std::string &) const;
std::string text_line(line_no ) const;
private:
void story_file(std::ifstream &);
void build_map();
std::vector<std::string>lines_of_text;
std::map<std::string,std::set<line_no>> word_map;
}
void story_file(std::ifstream &in)
{
}
void textquery::build_map()
{
for(line_no line_num=0;line_num!=lines_of_text.size();line_num++)
{
istringstream line(lines_of_text[line_num]);
string word;
while(line>>word)
word_map[word].insert(line_num);
}
}
set<textquery::line_no> textquery::run_query(const string &query_word) const
{
map<string,set<line_no>> ::const_iterator it=word_map.find(query_word);
if(it==word_map.end())
return set<line_no>();
else
return it->second;
}
string textquery::text_line(line_no line)
{
if(line<lines_of_text.size())
return lines_of_text[line];
}
class screen{
public :screen& move(index r,index c);
screen & set(char);
screen & display() const;
typedef char (screen::*callback)(int);
}
screen &screen::set(char c)
{
///
return *this;//static函数没有this 指针
}
screen & screen::display()
{
//
callback call;
call=classa::funcb;
obj_screen.(*call)(3);// 实际回调funcb
return *this; // 这个this指针是一个const screen* 型的
// 这样的话:m_objscreen.display().set(' ');错误的display() 返回 const引用,不能嵌入到长表达式
}
class screen{
friend class window;//友元类
friend window::relocate(window::index,screen &);//友元函数
private:
static int x;// static 可以私有
public :
static int y;//相当于全局变量,
static void display();//不能声明为const 型: 承诺不修改 它所在类所属的对象
}
window::relocate(window::index,screen &);//友元函数//可以引用screen 中的私有成员
class window {
window(screen & s); //可以引用screen 中的私有成员
}
class Message
{
public :
Message(const std::string str=" "):content(str){}
Message(const Message &);
Message &operator=(const Message &);
~Message();
void save(Folder &);
void remove(Folder &);
private :
std:string content;
std::set<Folder*>folder;
void put_msg_in_fold(const set<Folder*>&);
void remove_msg_from_fold();
};
Message &Message ::operator=(const Message &rhs)
{
if(&rhs!=this)
{
remove_msg_from_fold();
contents=rhs.content;
folder=rhs.folder;
put_msg_in_fold(folder);
}
}
Message ::Message(const Message &m):content(m.content),folder(m.folder)
{
put_msg_in_fold(folder);
}
Message ::Message(const std::string &str=" "):content(str) //隐式的将folder 初始化为空
{
}
void Message::put_msg_in_fold(const set<Folder*> &rhs)
{
for(std::set<Folder*>::const_iterator beg=rhs.begin();beg!=rhs.end();++beg)
(*beg)->addmessage(this);
}
Message::~Message()
{
remove_msg_from_fold(); //清除folder,系统自动调用string 析构掉content 自动调用set 析构清除用于保存folder成员的内存
}