1 #ifndef gra_IdentityPoints_H__
2 #define gra_IdentityPoints_H__
5 #include "../math/Vector.h"
6 #include "../oo/ObjBase.h"
20 template<
class ID,
class Scalar>
35 Myself(Myself
const& m): points_(m.points_), dimension_(m.dimension_) {
53 self(b.self,
Self<Myself>::COPY_FROM) {
82 self()->points_.clear();
89 return self->points_.size();
96 return (
size() == 0u);
103 return (self->points_.find(
id) !=
self->points_.end());
110 return self->dimension_;
117 self()->dimension_ = dim;
125 size_t dimension(
size_t dim, Scalar
const& init_value) {
126 self()->dimension_ = dim;
128 it =
self()->points_.begin(); it !=
self()->points_.end(); ++it) {
129 it.second.dimension(dim, init_value);
138 return self->points_;
163 for (
typename std::set<ID>::const_iterator
164 it = ids.begin(); it != ids.end(); ++it) {
201 self()->points_.erase(
id);
208 return self()->points_[
id];
222 bool write(FILE* f,
bool bin,
unsigned int fg)
const {
225 if (fwrite(&(dim =
dimension()),
sizeof(dim), 1, f) < 1)
return false;
226 if (fwrite(&(ct =
size()),
sizeof(ct), 1, f) < 1)
return false;
231 if (fwrite(&(tmp = it->first),
sizeof(tmp), 1, f) < 1)
return false;
232 for (
long i = 0; i < dim; ++i) {
233 if (fwrite(&(tmp = it->second(i)),
sizeof(tmp), 1, f) < 1)
239 if (fprintf(f,
"%ld %lu\n",
dimension(),
size()) < 1)
return false;
243 if (fprintf(f,
"%f ", (
double)it->first) < 1)
return false;
244 for (
long i = 0, I =
dimension(); i < I; ++i) {
245 if (fprintf(f,
"%f ", (
double)it->second(i)) < 1)
return false;
257 bool read(FILE* f,
bool bin,
unsigned int fg) {
260 if (fread(&dim,
sizeof(dim), 1, f) < 1)
return false;
262 if (fread(&ct,
sizeof(ct), 1, f) < 1)
return false;
265 for (
int i = 0; i < ct; ++i) {
266 if (fread(&
id,
sizeof(
id), 1, f) < 1)
return false;
267 for (
size_t j = 0, J = dim; j < J; ++j) {
268 if (fread(&tt,
sizeof(tt), 1, f) < 1)
return false;
275 if (fscanf(f,
"%ld %ld", &dim, &ct) < 2)
return false;
279 for (
int i = 0; i < ct; ++i) {
280 if (fscanf(f,
"%lf", &
id) < 1)
return false;
281 for (
int j = 0, J = dim; j < J; ++j) {
282 if (fscanf(f,
"%lf", &tt) < 1)
return false;
317 return typeid(*this).name();
325 return std::string(
ctype());
331 #endif // gra_IdentityPoints_H__
std::string type() const
回傳class的type
size_t dimension() const
return dimension
size_t dimension(size_t dim)
設定dimension, 並且清空資料
ObjBase * create() const
new一個自己
Vector< Scalar > & identityPointGet(ID const &id)
取得一個identity point, non-constant reference
bool read(FILE *f, bool bin, unsigned int fg)
將資料讀入
bool empty() const
回傳是否沒有identity points
IdentityPointsMap const & identityPoints(IdentityPointsMap const &points)
設定所有identity points
ObjBase * copyFrom(ObjBase const *b)
複製資料
把一個 std::map<ID,Vector<Scalar> > 包起來
char const * ctype() const
回傳class的type
IdentityPoints & copyFrom(IdentityPoints const &b)
複製資料
size_t size() const
回傳有幾個identity points
IdentityPoints & referenceFrom(IdentityPoints const &b)
參照
bool exist(ID const &id) const
檢查某id是否有使用
void identityPointDel(ID const &id)
刪除一個identity point
void clear()
清除一切identity points
Vector< Scalar > identityPointAdd(ID const &id, Vector< Scalar > const &b)
新增一個identity point
IdentityPoints(IdentityPoints const &b)
constructor, 並且複製資料
std::map< ID, Vector< Scalar > > IdentityPointsMap
一切物件的Base, 並要求每個物件都要有read, write, create, ... 等功能
IdentityPoints()
constructor
IdentityPointsMap const & identityPoints() const
取得所有identity points
size_t dimension() const
回傳dimension
IdentityPoints & operator=(IdentityPoints const &b)
same as copyFrom(b)
size_t dimension(size_t dim, Scalar const &init_value)
設定dimension, 並且針對每個identity point指定重設dimension
Vector< Scalar > identityPoint(ID const &id) const
取得一個identity point
~IdentityPoints()
destructor
bool write(FILE *f, bool bin, unsigned int fg) const
將資料寫入檔案
IdentityPointsMap::iterator IdentityPointsMapIter
IdentityPointsMap::const_iterator IdentityPointsMapIterK
Vector< Scalar > identityPoint(ID const &id, Vector< Scalar > const &b)
修改一個identity point
IdentityPointsMap const & identityPointsAdd(IdentityPointsMap const &points)
加入identity Points
IdentityPointsMap const & identityPointsDel(std::set< ID > const &ids)
移除identity Points