Скачиваний:
12
Добавлен:
01.05.2014
Размер:
2.05 Кб
Скачать
#ifndef _SYMB_H
#define _SYMB_H

union ATTR {
	unsigned char val[2];
	void* ptr;
};

class SYMB {
public:
	SYMB(char = 0, char = 0, char = 0);
	int operator==(const SYMB&) const;
	inline void set_type(char);
	inline char get_type() const;
	inline void set_id(char, char);
	inline char get_id(char) const;
	void set_attr(char, unsigned char, unsigned char);
	void set_attr(char, void*);
	void set_attr(char, const ATTR&);
	void get_attr(char, unsigned char&, unsigned char&) const;
	void* get_attr(char) const;
	void get_attr(char, ATTR&) const;
private:
	char type;             // 0 - вҐа¬Ё­ «
						   // 1 - ­ҐвҐа¬Ё­ «
						   // 2 - ®ЇҐа жЁ®­­л© бЁ¬ў®«
						   // 3 - ­ з «м­л© бЁ¬ў®« ¬ Ј §Ё­ 
						   // 4 - eps
						   // 5 - cЁ¬ў®« ¤а. Ї®¤Ја ¬¬ вЁЄЁ
						   //      id[1] - ­®¬Ґа в.Ї®¤Ја ¬¬ вЁЄЁ
	char id[2];
	ATTR attr[4];
};



int SYMB::operator==(const SYMB& s) const
{
	if (type != s.type)
		return 0;
	int f;
	if (type == 1) {
		f = (id[0] == s.id[0] && id[1] == s.id[1]);
			return f;
	}
	f = (id[0] < 3) ? (id[0] == s.id[0] && id[1] == s.id[1]) : (id[0] == s.id[0]);
	return f;
}

void SYMB::set_type(char t)
{
	type = t;
}

char SYMB::get_type() const
{
	return type;
}

void SYMB::set_id(char n, char v)
{
	id[n] = v;
}

char SYMB::get_id(char n) const
{
	return id[n];
}


SYMB::SYMB(char t, char i1, char i2)
{
	type = t;
	id[0] = i1;
	id[1] = i2;
	attr[0].ptr = 0;
	attr[1].ptr = 0;
	attr[2].ptr = 0;
	attr[3].ptr = 0;
}


void SYMB::set_attr(char n, unsigned char v1, unsigned char v2)
{
	attr[n].val[0] = v1;
	attr[n].val[1] = v2;
}

void SYMB::set_attr(char n, void* ptr)
{
	attr[n].ptr = ptr;
}

void SYMB::set_attr(char n, const ATTR& a)
{
	attr[n] = a;
}

void SYMB::get_attr(char n, unsigned char& v1, unsigned char& v2) const
{
	v1 = attr[n].val[0];
	v2 = attr[n].val[1];
}

void* SYMB::get_attr(char n) const
{
	return attr[n].ptr;
}

void SYMB::get_attr(char n, ATTR& a) const
{
	a = attr[n];
}

#endif
Соседние файлы в папке kurs