把颜色控制字符定义为一种特殊的Char,混合到String类中。
一个Color对象的length()总为0,这样String对象就不会多记录颜色
控制字符的长度。
[ class Color ]->[ class Char ]===>[ class String ]
|----------------| |--------------| |--------------]
[ int length()=0 ]->[ int length() ] -> [ int length() ]
| .. [ int size() ] |...
| ... |
[--------------]
// $Id: char.h,v 1.2 2004/04/09 12:55:46 jth Exp $
//
#ifndef _CHAR_H_
#define _CHAR_H_
/** 可变长度字符类。
*
* 由于中文和英文的字符长度,定制一可变字符类。
* 双字节字符和单字节字符都可以用一个可变长度字符类所
* 表示。为字符串类提供底层支持。
*
*/
class Char {
private:
char *m_data;
public:
Char();
Char(char);
Char(char, char);
Char(const Char&);
explicit Char(const char*);
virtual Char& operator=(const Char&);
virtual int size() const;
virtual char getByte(int) const;
virtual void setByte(int, char);
virtual bool equals(const Char&) const;
virtual const char* c_str() const;
virtual int length() const;
virtual ~Char();
};
#endif//_CHAR_H_
// $Id: color.h,v 1.2 2004/04/09 12:55:46 jth Exp $
//
#ifndef _COLOR_H_
#define _COLOR_H_
#include "char.h"
/** 颜色定义
*/
const int black = 0;
const int red = 1;
const int green = 2;
const int yellow = 3;
const int blue = 4;
const int purple = 5;
const int cyan = 6;
const int white = 7;
const int bold = 1;
const int normal = 0;
/** 颜色类。
*
* 一个颜色类包含了显示要素的色彩信息,
* 即背景,前景颜色,字符特性:加粗(TODO:闪烁,下划线等)
*
*/
class Color : public Char {
private:
char *m_color_data;
public:
Color(const Color&);
explicit Color(int fg = -1, int bg = -1, int bold = -1);
int length() const; // 总为0
int size() const;
char getByte(int) const;
void setByte(int, char);
bool equals(const Color&) const;
Color& operator=(const Color&);
const char* c_str() const;
~Color();
};
#endif//_COLOR_H_
-----------------------
stat.
netbbs statistics
------------------------
37 c++ source files.
37 c++ header files.
5794 lines code.
--
FROM 202.120.174.78