Chinaunix首页 | 论坛 | 博客
  • 博客访问: 208307
  • 博文数量: 35
  • 博客积分: 2691
  • 博客等级: 少校
  • 技术积分: 527
  • 用 户 组: 普通用户
  • 注册时间: 2008-01-11 09:42
文章分类

全部博文(35)

文章存档

2012年(5)

2010年(6)

2009年(2)

2008年(22)

我的朋友

分类: C/C++

2009-12-24 10:02:49

 

#ifndef B3_VARIABLE_H
#define B3_VARIABLE_H
#include <assert.h>
#include <vector>
#include <string>
#include <set>
using namespace std;
#include "ParamArray.h"
#include "Util.h"
class Variable
{
public:
 Variable() {};
 virtual ~Variable() {}
 virtual int GetLength() = 0;
 virtual void Clear() = 0;
 virtual void Echo() = 0;
 virtual int GetInt();
 virtual double GetDouble();
 virtual const char* GetString();
 virtual void SetValue(const char* pVal, int nLen) = 0;
 virtual void SetValue(const char* pVal) = 0;
 virtual void SetValue(Variable* pRight) = 0;
public:
 static bool IsSupport(const char*);
};
class VarInt : public Variable
{
protected:
 int m_nVal;
public:
 VarInt() {};
 virtual ~VarInt() {}
 virtual void SetValue(const char* pVal, int nLen);
 virtual void SetValue(const char* pVal);
 virtual void SetValue(Variable* pRight);
 void SetInt(int n) {m_nVal = n;}
 virtual int GetInt();
 virtual double GetDouble();
 virtual const char* GetString();
 virtual int GetLength();
 virtual void Clear();
 virtual void Echo();
public:
 bool operator == (VarInt& r) const {
  return m_nVal == r.GetInt();
 }
 
 bool operator < (VarInt& r) const {
  return m_nVal < r.GetInt();
 }
};
class VarDouble : public Variable
{
private:
 double m_dblVal;
public:
 VarDouble() {};
 virtual ~VarDouble() {};
 virtual void SetValue(const char* pVal, int nLen);
 virtual void SetValue(const char* pVal);
 virtual void SetValue(Variable* pRight);
 virtual int GetInt();
 virtual double GetDouble();
 virtual const char* GetString();
 virtual int GetLength();
 virtual void Clear();
 virtual void Echo();
public:
 bool operator == (VarDouble& r) const {
  return m_dblVal == r.GetDouble();
 }
 
 bool operator < (VarDouble& r) const {
  return m_dblVal < r.GetDouble();
 }
};
class VarString : public Variable
{
private:
 string m_strVal;
public:
 VarString() {};
 virtual ~VarString() {};
 virtual void SetValue(const char* pVal, int nLen);
 virtual void SetValue(const char* pVal);
 virtual void SetValue(Variable* pRight);
 virtual int GetInt();
 virtual double GetDouble();
 virtual const char* GetString();
 
 virtual int GetLength();
 virtual void Clear();
 virtual void Echo();
public:
 bool operator == (VarString& r) const {
  return m_strVal.compare(r.GetString()) == 0;
 }
 
 bool operator < (VarString& r) const {
  return m_strVal.compare(r.GetString()) < 0;
 }
};
class VarVar : public Variable
{
private:
 Variable* m_pActualVar;
 string m_strName;
public:
 VarVar() {};
 virtual ~VarVar() {};
 virtual void SetName(const char* pVal, int nLen);
 virtual void SetName(const char* pVal);
 virtual void SetVar(Variable* pActual);
 virtual void SetValue(const char* pVal, int nLen) {};
 virtual void SetValue(const char* pVal) {};
 virtual void SetValue(Variable* pRight) {};
 virtual const char* GetName();
 virtual Variable* GetVar();
 virtual int GetInt();
 virtual double GetDouble();
 virtual const char* GetString();
 virtual int GetLength();
 virtual void Clear();
 virtual void Echo();
};
class VarDate : public Variable
{
private:
 tm m_oTm;
 char m_achDate[64];
public:
 VarDate() {};
 virtual ~VarDate() {};
 virtual void SetValue(const char* pVal, int nLen);
 virtual void SetValue(const char* pVal);
 virtual void SetValue(Variable* pRight);
 virtual int GetLength();
 virtual void Clear();
 virtual void Echo();
 virtual int GetInt();
 virtual double GetDouble();
 virtual const char* GetString();
public:
 bool operator == (VarDate& r) {
  return GetInt() == r.GetInt();
 }
 
 bool operator < (VarDate& r) {
  return GetInt() < r.GetInt();
 }
};
class VarComplex : public Variable
{
public:
 VarComplex() {};
 virtual ~VarComplex() {};
 
 virtual void SetValue(const char* pVal, int nLen) {assert(0);}
 virtual void SetValue(const char* pVal) {assert(0);}
 virtual void SetValue(Variable* pRight) {assert(0);}
 virtual int GetInt() { return 0; }
 virtual double GetDouble() { return 0.0; }
 virtual const char* GetString() { return ""; }
 virtual void PushBack(Variable*) = 0;
 virtual void PushBack(const char*) = 0;
 virtual Variable* GetElement() = 0;
 virtual void Erase() = 0;
 virtual void SetValue(ParamArray&) = 0;
};
template <typename T>
class VarArray : public VarComplex
{
private:
 vector<T> m_vecVar;
 typename vector<T>::iterator m_it;
public:
 VarArray();
 virtual ~VarArray() {};
 void SetValue(int x, const char* pVal);
 void SetValue(int x, Variable* pRight);
 virtual void SetValue(ParamArray&);
 virtual void PushBack(Variable*);
 virtual void PushBack(const char*);
 virtual Variable* GetElement();
 virtual void Erase();
 virtual int GetLength();
 virtual void Clear();
 virtual void Echo();
};
template <typename T>
class VarSet : public VarComplex
{
private:
 set<T> m_setVar;
 typename set<T>::iterator m_it;
public:
 VarSet();
 virtual ~VarSet() {}
 virtual void SetValue(ParamArray&);
 virtual void PushBack(Variable*);
 virtual void PushBack(const char*);
 virtual Variable* GetElement();
 virtual void Erase();
 virtual int GetLength();
 virtual void Clear();
 virtual void Echo();
};
template <typename T>
class VarMatrix : public VarComplex
{
private:
 vector<VarArray<T> > m_matrixVar;
 typename vector<VarArray<T> >::iterator m_it;
public:
 VarMatrix();
 virtual ~VarMatrix() {}
 void SetValue(int x, int y, const char* pVal);
 void SetValue(int x, int y, Variable* pRight);
 virtual void SetValue(ParamArray&);
 virtual void PushBack(Variable*);
 virtual void PushBack(const char*);
 virtual Variable* GetElement();
 virtual void Erase();
 virtual int GetLength();
 virtual void Clear();
 virtual void Echo();
};
class VarSerial : public VarComplex
{
private:
 int m_nLow;
 int m_nHigh;
 VarInt m_var;
public:
 VarSerial();
 virtual ~VarSerial();
 void SetValue(int x, int y);
 virtual void SetValue(ParamArray&);
 virtual void PushBack(Variable*);
 virtual void PushBack(const char*);
 virtual Variable* GetElement();
 virtual void Erase();
 virtual int GetLength();
 virtual void Clear();
 virtual void Echo();
};
//////////////////////////////////////////////

关于template的实现隐去
///////////////////////////////////////

#endif
/* vim: set tabstop=4 shiftwidth=4 : */


阅读(1237) | 评论(0) | 转发(0) |
0

上一篇:linux文件锁例子

下一篇:一些脚本

给主人留下些什么吧!~~