65,211
社区成员
发帖
与我相关
我的任务
分享
FRAMEMAP::const_iterator pos;
pos = FrmMap.begin()+1;
(pos+1)->first........
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
typedef struct
{
double len_Ratio; // parameters within this frame
double angle; //
}
FRAMEINFO;
typedef unsigned int UNIN;
int main()
{
typedef map<UNIN,FRAMEINFO> FRAME;
FRAME coll;
FRAME::iterator pos; // 请注意这里!!!
FRAMEINFO temp;
temp.angle = 80;
temp.len_Ratio = 0.36;
coll[1]=temp;
temp.angle = 360;
temp.len_Ratio = 0.46;
coll[2]=temp;
temp.angle = 270;
temp.len_Ratio = 0.66;
coll[3]=temp;
pos = coll.find (3); // logarithmic complexity
if (pos != coll.end())
{
cout << pos->first << ": "
<< pos->second.angle << " :"
<< pos->second.len_Ratio
<< endl;
}
for (pos = coll.begin(); pos != coll.end(); ++pos)
{
cout << ' '
<< pos->first << ": " << endl
<< "Angle: "<< pos->second.angle << "-"
<< "Length Ratio: "<< pos->second.len_Ratio
<< endl;
}
cout << endl;
temp.angle = 60;
temp.len_Ratio = 0.96;
coll[2]=temp;
for (pos = coll.begin(); pos != coll.end(); ++pos)
{
cout << ' '
<< pos->first << ": " << endl
<< "Angle: "<< pos->second.angle << "-"
<< "Length Ratio: "<< pos->second.len_Ratio
<< endl;
}
cout << endl;
return 0;
}
#ifndef FRAME_H_
#define FRAME_H_
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
#define NULL 0;
typedef struct
{
double len_Ratio; // parameters within this frame
int angle; //
}
FRAMEINFO;
typedef map<unsigned int,FRAMEINFO> FRAMEMAP;
class Frame
{
private:
FRAMEINFO frminfo;
FRAMEMAP FrmMap;
FRAMEMAP::const_iterator curpos;
public:
Frame();
~Frame();
const FRAMEINFO * GetFrame(unsigned int) const;
void RemoveFrame(unsigned int);
void AddFrame(unsigned int, FRAMEINFO &);
void UpdateFrmInfo(unsigned int, FRAMEINFO &);
void PrintAll();
};
#endif
#include "Frame.h"
Frame::Frame()
{
}
Frame::~Frame()
{
}
const FRAMEINFO * Frame::GetFrame(unsigned int num) const
{
FRAMEMAP::const_iterator pos = FrmMap.find(num); // 请注意这里!! 如果这里没有加const_,即与上一个程序写法一致,那么
// 所有关于pos的赋值和比较操作都将被报错。
if (pos != FrmMap.end())
{
return &(pos->second);
}
else
return NULL;
}
void Frame::AddFrame(unsigned int num, FRAMEINFO & fi)
{
FRAMEINFO temp = fi;
FrmMap[num]=temp;
}
void Frame::RemoveFrame(unsigned int num)
{
FrmMap.erase(num);
}
void Frame::UpdateFrmInfo(unsigned int num, FRAMEINFO & fi)
{
FrmMap[num]=fi;
}
void Frame::PrintAll()
{
FRAMEMAP::const_iterator pos;
for(pos=FrmMap.begin();pos!=FrmMap.end();pos++)
{
cout << "angle: " << pos->second.angle << endl
<< "leng ratio: " << pos->second.len_Ratio << endl;
}
}
#include "Frame.h"
int main()
{
FRAMEINFO fi_1;
FRAMEINFO fi_2;
FRAMEINFO fi_3;
FRAMEINFO fi_4;
FRAMEINFO fi_5;
FRAMEINFO fi_6;
FRAMEINFO fi_7;
FRAMEINFO fi_temp;
fi_1.angle = 23;
fi_1.len_Ratio = 0.21;
fi_2.angle = 24;
fi_2.len_Ratio = 0.22;
fi_3.angle = 25;
fi_3.len_Ratio = 0.23;
fi_4.angle = 26;
fi_4.len_Ratio = 0.24;
fi_5.angle = 27;
fi_5.len_Ratio = 0.25;
fi_6.angle = 28;
fi_6.len_Ratio = 0.26;
fi_7.angle = 29;
fi_7.len_Ratio = 0.27;
Frame f;
f.AddFrame(24, fi_1);
f.AddFrame(48, fi_2);
f.AddFrame(56, fi_3);
f.AddFrame(60, fi_4);
f.AddFrame(78, fi_5);
f.AddFrame(102, fi_6);
f.AddFrame(112, fi_7);
f.PrintAll();
fi_temp = * (f.GetFrame(60));
cout << fi_temp.angle << endl
<< fi_temp.len_Ratio << endl;
FRAMEINFO fi_temp_2;
fi_temp_2.angle = 340;
fi_temp_2.len_Ratio = 2.0;
f.UpdateFrmInfo(60, fi_temp_2);
fi_temp = * (f.GetFrame(60));
cout << fi_temp.angle << endl
<< fi_temp.len_Ratio << endl;
f.RemoveFrame(60);
f.PrintAll();
return 0;
}
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
typedef struct
{
double len_Ratio; // parameters within this frame
double angle; //
}
FRAMEINFO;
typedef unsigned int UNIN;
int main()
{
typedef map<UNIN,FRAMEINFO> FRAME;
FRAME coll;
FRAME::iterator pos;
FRAMEINFO temp;
temp.angle = 80;
temp.len_Ratio = 0.36;
coll[1]=temp;
temp.angle = 360;
temp.len_Ratio = 0.46;
coll[2]=temp;
temp.angle = 270;
temp.len_Ratio = 0.66;
coll[3]=temp;
pos = coll.find (3); // logarithmic complexity
if (pos != coll.end())
{
cout << pos->first << ": "
<< pos->second.angle << " :"
<< pos->second.len_Ratio
<< endl;
}
for (pos = coll.begin(); pos != coll.end(); ++pos)
{
cout << ' '
<< pos->first << ": " << endl
<< "Angle: "<< pos->second.angle << "-"
<< "Length Ratio: "<< pos->second.len_Ratio
<< endl;
}
cout << endl;
temp.angle = 60;
temp.len_Ratio = 0.96;
coll[2]=temp;
for (pos = coll.begin(); pos != coll.end(); ++pos)
{
cout << ' '
<< pos->first << ": " << endl
<< "Angle: "<< pos->second.angle << "-"
<< "Length Ratio: "<< pos->second.len_Ratio
<< endl;
}
cout << endl;
return 0;
}
#ifndef FRAME_H_
#define FRAME_H_
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
#define NULL 0;
typedef struct
{
double len_Ratio; // parameters within this frame
int angle; //
}
FRAMEINFO;
typedef map<unsigned int,FRAMEINFO> FRAMEMAP;
class Frame
{
private:
FRAMEINFO frminfo;
FRAMEMAP FrmMap;
FRAMEMAP::iterator curpos;
public:
Frame();
~Frame();
FRAMEINFO * GetFrame(unsigned int) const;
void RemoveFrame(unsigned int);
void AddFrame(unsigned int, FRAMEINFO &);
void UpdateFrmInfo(unsigned int, FRAMEINFO &);
};
#endif
#include <algorithm>
#include "Frame.h"
Frame::Frame()
{
}
Frame::~Frame()
{
}
FRAMEINFO * Frame::GetFrame(unsigned int num) const
{
using std::map;
FRAMEMAP::iterator pos;
pos = FrmMap.find(num);
if (pos != FrmMap.end())
{
return &(pos->second);
}
else
return NULL;
}
void Frame::AddFrame(unsigned int num, FRAMEINFO & fi)
{
FRAMEINFO temp = fi;
FrmMap[num]=temp;
}
void Frame::RemoveFrame(unsigned int num)
{
FrmMap.erase(num);
}
void Frame::UpdateFrmInfo(unsigned int num, FRAMEINFO & fi)
{
FrmMap[num]=fi;
}
#ifndef FRAME_H_
#define FRAME_H_
#include <list>
#include <algorithm>
#include <functional>
using namespace std;
typedef struct
{
unsigned long int num; // number of frame
double len_Ratio; // parameters within this frame
double angle; //
/*
static bool is_the_frame(const int & the_num)
{
return (num == the_num);
}
*/
}
FRAME;
struct Function : public unary_function <FRAME, bool>
{
Function(unsigned long n)
{
num = n;
}
bool operator()( FRAME& right) const
{
return num == right.num;
}
unsigned long num;
};
bool less_num(const FRAME & f1, const FRAME & f2)
{
return (f1.num < f2.num);
}
/*
bool is_the_frame(const FRAME & the_frame, const int & the_num)
{
return (the_frame.num == the_num);
}
class IsFrame
{
private:
FRAME frm;
public:
IsFrame(const FRAME & f) : frm(f) {}
static bool Equ(const unsigned long & num) { return frm.num == num; }
};
*/
class FrameInfo
{
private:
unsigned long int num_temp;
FRAME FRMtemp;
list<FRAME> FrmList;
list<FRAME>::iterator pos;
//FRAME * pos;
public:
FrameInfo();
~FrameInfo();
FRAME & GetFrame(unsigned long int) const;
void RemoveFrame(unsigned long int);
void SortFrame();
void AddFrame(FRAME & frame);
void FillStateArr() const;
};
#endif
#include "Frame.h"
FrameInfo::FrameInfo()
{
}
FrameInfo::~FrameInfo()
{
}
FRAME & FrameInfo::GetFrame(unsigned long the_num) const
{
//pos = find_if(FrmList.begin(), FrmList.end(), bind2nd(is_the_frame(), the_num));
/*
if(! FrmList.empty())
{
pos = find_if(FrmList.begin(), FrmList.end(), Function(the_num));
}
return * pos;
*/
for(pos = FrmList.begin(); pos = FrmList.end(); ++pos)
{
if(pos->num == the_num)
{
return *pos;
}
}
return NULL;
}
void FrameInfo::RemoveFrame(unsigned long int the_num)
{
//pos = find_if(FrmList.begin(), FrmList.end(), bind2nd(is_the_frame(), the_num));
//FrmList.erase (pos);
FrmList.remove_if ( Function(the_num) );
}
void FrameInfo::SortFrame()
{
sort(FrmList.begin(), FrmList.end(), less_num);
}
void FrameInfo::AddFrame(FRAME & frame)
{
FrmList.push_back(frame);
}