-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmorph.h
44 lines (40 loc) · 1.18 KB
/
morph.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef __MORPH_H__
#define __MORPH_H__
#include "base.h"
typedef std::function<BYTE(int,int)> MorphFunc;
class MorphCore{
std::vector<std::string> dat;
int r,c,sz,mr=-1,mc=-1;
public:
MorphCore(const char *str){
std::string s(str);
dat=str_split(s,';');
r=dat.size();
if(r==0) throw "MorphCore::bad_str";
c=dat[0].size();
if(c==0) throw "MorphCore::bad_str";
sz=0;
for(int i=0;i<r;++i){
if(dat[i].size()!=c) throw "MorphCore::bad_str";
for(int j=0;j<c;++j){
char y=dat[i][j];
if(y!='.' && y!='o' && y!='x') throw "MorphCore::bad_str";
if(y=='x'){
if(mr!=-1 && mc!=-1) throw "MorphCore::bad_str";
mr=r;mc=c;
}
if(y!='.') ++sz;
}
}
if(mr==-1 || mc==-1) throw "MorphCore::bad_str";
}
std::string& operator[](int i){
return dat[i];
}
int getRows(){return r;}
int getCols(){return c;}
int getSize(){return sz;}
int getCenterRow(){return mr;}
int getCenterCol(){return mc;}
};
#endif