chars.hpp

来自「模糊聚類分析源碼。包含教學文件」· HPP 代码 · 共 226 行

HPP
226
字号
/*    Context       : Basic Utility Files  Author        : Frank Hoeppner, see also AUTHORS file   Description   : header of class Chars                  Source Documentation Handbook: tutorial-UTIL  History       : see source file  Comment       :     This file was generated automatically. DO NOT EDIT.  Copyright     : Copyright (C) 1999-2000 Frank Hoeppner    This program is free software; you can redistribute it and/or modify    it under the terms of the GNU General Public License as published by    the Free Software Foundation; either version 2 of the License, or    (at your option) any later version.    This program is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    GNU General Public License for more details.    You should have received a copy of the GNU General Public License    along with this program; if not, write to the Free Software    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA*/#ifndef Chars_HEADER#define Chars_HEADER/* configuration include */#ifdef HAVE_CONFIG_H/*//FILETREE_IFDEF HAVE_CONFIG_H*/#include "config.h"/*//FILETREE_ENDIF*/#endif// necessary includes#include <iostream.h>#include <stdio.h>#include "defbool.hpp"//#define INLINE inline// global types, constants, definitions#define STRREF(charsinstance) (charsinstance)(),(charsinstance).size()// class definitiontemplate <int SIZE=128>class Chars    {    public:        inline Chars();    inline Chars(char);    inline Chars(const Chars&);    inline Chars(const char *);    inline char* operator()();    inline const char* operator()() const;    inline char& operator[](int);    inline char operator[](int) const;    inline int size() const;    inline int len() const;    bool empty() const;    inline void operator=(char c);    inline void operator=(const char* p );    inline void operator=(const Chars& c );    inline void operator+=(const char*);    inline void operator+=(const char);    inline void operator+=(const Chars&);     inline void operator+=(int);     inline void operator-=(size_t);    inline bool operator<(const Chars& S) const;    inline bool operator>(const Chars& S) const;    inline bool operator==(const Chars& S) const;    inline bool operator!=(const Chars& S) const;    inline bool operator<(const char *p_S) const;    inline bool operator>(const char *p_S) const;    inline bool operator==(const char *p_S ) const;    inline bool operator!=(const char *p_S ) const;    inline void read(istream& is);    inline void write(ostream& os) const;      protected:              private:            char m_text[SIZE];      };// class related functions and definitions/* inline implementation */template <int SIZE>inline Chars<SIZE>::Chars()  { m_text[0]='\0'; }template <int SIZE>inline Chars<SIZE>::Chars(char c)  { m_text[0]=c; m_text[1]='\0'; }template <int SIZE>inline Chars<SIZE>::Chars(const Chars& a_chars)   { strcpy(m_text,a_chars.m_text); }template <int SIZE>inline Chars<SIZE>::Chars(const char *ap_charp)   { if (ap_charp==NULL) m_text[0]='\0'; else strncpy(m_text,ap_charp,SIZE); }template <int SIZE>inline char* Chars<SIZE>::operator()()   { return m_text; }template <int SIZE>const char* Chars<SIZE>::operator()() const   { return m_text; }template <int SIZE>inline char& Chars<SIZE>::operator[](int i)   { return m_text[i]; }template <int SIZE>char Chars<SIZE>::operator[](int i) const   { return m_text[i]; }template <int SIZE>inline int Chars<SIZE>::size() const   { return SIZE; }template <int SIZE>inline int Chars<SIZE>::len() const   { return strlen(m_text); }template <int SIZE>inline bool Chars<SIZE>::empty() const   { return m_text[0]=='\0'; }template <int SIZE>inline void Chars<SIZE>::operator=(char c)   { m_text[0]=c; m_text[1]='\0'; }template <int SIZE>inline void Chars<SIZE>::operator=(const char* p)   { strncpy(m_text,p,SIZE-1); }template <int SIZE>inline void Chars<SIZE>::operator=(const Chars& c)   { strncpy(m_text,c.m_text,SIZE-1); }template <int SIZE>inline void Chars<SIZE>::operator+=(const char* p)   { strncat(m_text,p,SIZE-strlen(m_text)-1); }template <int SIZE>inline void Chars<SIZE>::operator+=(const char c)   { m_text[strlen(m_text)]=c; m_text[strlen(m_text)+1]='\0'; }template <int SIZE>inline void Chars<SIZE>::operator+=(const Chars& S)   { strncat(m_text,S.m_text,SIZE-strlen(m_text)-1); }template <int SIZE>inline void Chars<SIZE>::operator+=(int n)   { char p[7]; sprintf(p,"%d",n); operator+=(p); }template <int SIZE>inline void Chars<SIZE>::operator-=(size_t i)  { if (i>strlen(m_text)) i=0; else i=strlen(m_text)-i; m_text[i]='\0'; }template <int SIZE>inline bool Chars<SIZE>::operator<(const Chars& S) const  { return strcmp(m_text,S.m_text)<0; }template <int SIZE>inline bool Chars<SIZE>::operator>(const Chars& S) const  { return strcmp(m_text,S.m_text)>0; }template <int SIZE>inline bool Chars<SIZE>::operator==(const Chars& S) const  { return strcmp(m_text,S.m_text)==0; }template <int SIZE>inline bool Chars<SIZE>::operator!=(const Chars& S) const  { return strcmp(m_text,S.m_text)!=0; }template <int SIZE>inline bool Chars<SIZE>::operator<(const char* p_S) const  { return strcmp(m_text,p_S)<0; }template <int SIZE>inline bool Chars<SIZE>::operator>(const char* p_S) const  { return strcmp(m_text,p_S)>0; }template <int SIZE>inline bool Chars<SIZE>::operator==(const char* p_S) const  { return strcmp(m_text,p_S)==0; }template <int SIZE>inline bool Chars<SIZE>::operator!=(const char *p_S) const  { return strcmp(m_text,p_S)!=0; }template <int SIZE>inline void Chars<SIZE>::read(istream& is)   { is >> m_text; }template <int SIZE>inline void Chars<SIZE>::write(ostream& os) const   { os << m_text; }template <int SIZE>inline istream& operator>>  (  istream &is,   Chars<SIZE>& a_var  )   {   a_var.read(is);  return is;   }template <int SIZE>inline ostream& operator<<  (  ostream &os,   const Chars<SIZE>& a_var  )   {  a_var.write(os);  return os;   }#endif // Chars_HEADER

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?