map 学习

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成员的内存
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值