⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 message.h

📁 epson usb2.0 控制芯片 S1R72V05 固件程序。
💻 H
字号:
/*
 *  TOPPERS/JSP Kernel
 *      Toyohashi Open Platform for Embedded Real-Time Systems/
 *      Just Standard Profile Kernel
 * 
 *  Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory
 *                              Toyohashi Univ. of Technology, JAPAN
 * 
 *  忋婰挊嶌尃幰偼丆埲壓偺 (1)乣(4) 偺忦審偐丆Free Software Foundation 
 *  偵傛偭偰岞昞偝傟偰偄傞 GNU General Public License 偺 Version 2 偵婰
 *  弎偝傟偰偄傞忦審傪枮偨偡応崌偵尷傝丆杮僜僼僩僂僃傾乮杮僜僼僩僂僃傾
 *  傪夵曄偟偨傕偺傪娷傓丏埲壓摨偠乯傪巊梡丒暋惢丒夵曄丒嵞攝晍乮埲壓丆
 *  棙梡偲屇傇乯偡傞偙偲傪柍彏偱嫋戻偡傞丏
 *  (1) 杮僜僼僩僂僃傾傪僜乕僗僐乕僪偺宍偱棙梡偡傞応崌偵偼丆忋婰偺挊嶌
 *      尃昞帵丆偙偺棙梡忦審偍傛傃壓婰偺柍曐徹婯掕偑丆偦偺傑傑偺宍偱僜乕
 *      僗僐乕僪拞偵娷傑傟偰偄傞偙偲丏
 *  (2) 杮僜僼僩僂僃傾傪丆儔僀僽儔儕宍幃側偳丆懠偺僜僼僩僂僃傾奐敪偵巊
 *      梡偱偒傞宍偱嵞攝晍偡傞応崌偵偼丆嵞攝晍偵敽偆僪僉儏儊儞僩乮棙梡
 *      幰儅僯儏傾儖側偳乯偵丆忋婰偺挊嶌尃昞帵丆偙偺棙梡忦審偍傛傃壓婰
 *      偺柍曐徹婯掕傪宖嵹偡傞偙偲丏
 *  (3) 杮僜僼僩僂僃傾傪丆婡婍偵慻傒崬傓側偳丆懠偺僜僼僩僂僃傾奐敪偵巊
 *      梡偱偒側偄宍偱嵞攝晍偡傞応崌偵偼丆師偺偄偢傟偐偺忦審傪枮偨偡偙
 *      偲丏
 *    (a) 嵞攝晍偵敽偆僪僉儏儊儞僩乮棙梡幰儅僯儏傾儖側偳乯偵丆忋婰偺挊
 *        嶌尃昞帵丆偙偺棙梡忦審偍傛傃壓婰偺柍曐徹婯掕傪宖嵹偡傞偙偲丏
 *    (b) 嵞攝晍偺宍懺傪丆暿偵掕傔傞曽朄偵傛偭偰丆TOPPERS僾儘僕僃僋僩偵
 *        曬崘偡傞偙偲丏
 *  (4) 杮僜僼僩僂僃傾偺棙梡偵傛傝捈愙揑傑偨偼娫愙揑偵惗偠傞偄偐側傞懝
 *      奞偐傜傕丆忋婰挊嶌尃幰偍傛傃TOPPERS僾儘僕僃僋僩傪柶愑偡傞偙偲丏
 * 
 *  杮僜僼僩僂僃傾偼丆柍曐徹偱採嫙偝傟偰偄傞傕偺偱偁傞丏忋婰挊嶌尃幰偍
 *  傛傃TOPPERS僾儘僕僃僋僩偼丆杮僜僼僩僂僃傾偵娭偟偰丆偦偺揔梡壜擻惈傕
 *  娷傔偰丆偄偐側傞曐徹傕峴傢側偄丏傑偨丆杮僜僼僩僂僃傾偺棙梡偵傛傝捈
 *  愙揑傑偨偼娫愙揑偵惗偠偨偄偐側傞懝奞偵娭偟偰傕丆偦偺愑擟傪晧傢側偄丏
 * 
 *  @(#) $Id: message.h,v 1.1 2006/04/14 02:46:06 9564907 Exp $
 */

// $Header: J:\\SapporoSoft\\usb20\\S1R72V05\\Debug\\Repository/S1R72V05_Toppers/Toppers/cfg/base/message.h,v 1.1 2006/04/14 02:46:06 9564907 Exp $

#ifndef MESSAGE_H
#define MESSAGE_H

#ifdef _MSC_VER
#  pragma warning(disable:4290) //C++ 偺椺奜偺巜掕偼柍帇偝傟傑偡丅娭悢偑 __declspec(nothrow) 偱側偄偙偲偺傒昞帵偝傟傑偡丅
#  pragma warning(disable:4786) //僨僶僢僌忣曬偱幆暿巕偑255暥帤偵愗傝幪偰傜傟傑偟偨丅
#endif

#include <string>
#include <sstream>
#include <stdarg.h>
#include <stdexcept>

//#include "base/testsuite.h"
#include "base/singleton.h"
#include "base/except.h"

    /*
     *   暥帤楍惍宍僿儖僷乕僋儔僗
     */
class Formatter
{
protected:
    std::string       templatestring;    //僥儞僾儗乕僩暥帤楍
    std::stringstream content;           //暥帤楍惍宍偲彂幃嵪傒暥帤楍壜擻応強梡僗僩儕乕儉
    bool              accept;            //堷悢傪庴擖壜擻偐偳偆偐

        //師偺堷悢偺憓擖愭傊偲堏摦
    void shift(void) throw();

        //枹愝掕偺堷悢傪 (null) 偱抲姺
    void shift_all(void) throw();

public:
        //僨僼僅儖僩僐儞僗僩儔僋僞
    Formatter(void) throw();

        //僐儞僗僩儔僋僞
    Formatter(std::string src) throw();

        //僐僺乕僐儞僗僩儔僋僞
    Formatter(const Formatter & src) throw();

        //僥儞僾儗乕僩暥帤楍偺愝掕 (拞恎偼徚偊傞)
    void assign(std::string src) throw();

        //撪梕偺僋儕傾
    void clear(void) throw();

        //戙擖墘嶼巕
    Formatter & operator =(const Formatter & src) throw();

        //堷悢偺愝掕
    template<class T>
    Formatter & operator << (const T & src) throw()
    {
        std::string::size_type pos;

            //堷悢傪庴擖壜擻側傜
        if(accept) {
            pos = content.str().size();
            content << src;

                /* 嬻暥帤偱側偗傟偽師偺憓擖応強偵堏摦 */
            if(pos != content.str().size())
                shift();
        }
        return *this;
    }

        //撪晹儊僢僙乕僕偺庢傝弌偟
    std::string str(void) throw();

        //昗弨弌椡僗僩儕乕儉傊偺弌椡梡 operator << 掕媊
    friend inline std::ostream & operator << (std::ostream & out, Formatter msg) throw()
    {
        out << msg.content.str();
        return out;
    }

//    TESTSUITE_PROTOTYPE(main)
};

    /*
     *   儊僢僙乕僕弌椡梡偵2尵岅懳墳傪峴偭偨暥帤楍惍宍僿儖僷乕僋儔僗
     */
class Message : public Formatter
{
public:
    enum tagLanguage
    {
        ENGLISH  = 0,
        JAPANESE = 1,

        LAST_LANG,              //嵟屻偺埵抲
        NEUTRAL  = ENGLISH,     //昗弨尵岅
    };

        /* 弌椡儊僢僙乕僕尵岅惂屼僋儔僗 */
    class MessageControl
    {
    protected:
        int language;   //偳偺尵岅傪巊梡偡傞偺偐

    public:
            //僐儞僗僩儔僋僞
        SINGLETON_CONSTRUCTOR(MessageControl) throw() : language(NEUTRAL) {};

            //傾僋僙僒
        inline void setLanguage(int _language) throw()  { language = _language; }
        inline int  getLanguage(void) const    throw()  { return language; }

        const char * select(const char * msg1, const char * msg2, va_list vl ) throw();
    };

protected:

        //攈惗僋儔僗梡僐儞僗僩儔僋僞
    void _initialize(const char * src1, const char * src2, va_list vl) throw();

public:
        //僨僼僅儖僩僐儞僗僩儔僋僞
    Message(void) throw();

        //僐儞僗僩儔僋僞 (扨堦尵岅)
    Message(std::string src) throw();

        //僐儞僗僩儔僋僞 (暋悢尵岅)
    Message(const char * src1, const char * src2, ... ) throw();

        //僐僺乕僐儞僗僩儔僋僞
    Message(const Message & src) throw();

        //僥儞僾儗乕僩暥帤楍偺愝掕 (拞恎偼徚偊傞)
    void assign(std::string src) throw() { Formatter::assign(src); }
    void assign(const char * src1, const char * src2, ... ) throw();

        //尵岅慖戰
    static void selectLanguage(enum tagLanguage lang = NEUTRAL) throw();
        
        //尵岅偺庢摼
    static enum tagLanguage getCurrentLanguage(void) throw()
    {   return static_cast<enum tagLanguage>(Singleton<MessageControl>::getInstance()->getLanguage());   }

    //TESTSUITE_PROTOTYPE(main)
};


    /*
     *   忕挿弌椡梡暥帤楍惍宍僿儖僷乕僋儔僗
     */
class VerboseMessage : public Message
{
public:
        //嫟捠偺忕挿弌椡忣曬傪帩偮僋儔僗
    class VerboseControl
    {
    public:
        bool           verbose;     //忕挿弌椡傪峴偆偐偳偆偐
        std::ostream * out;         //弌椡愭

            //僐儞僗僩儔僋僞
        SINGLETON_CONSTRUCTOR(VerboseControl) throw() : verbose(false), out(0)
        {}

            //忕挿弌椡惂屼
        template<class T>
        inline const VerboseControl & operator << (const T & src) const throw()
        {
            if(verbose && out != 0)
                (*out) << src;
            return *this;
        }

            //verbose傾僋僙僒
        void setVerbose(bool _verbose) throw()
        {   verbose = _verbose;   }
        bool getVerbose(void) const throw()
        {   return verbose;   }

            //out傾僋僙僒
        void setStream(std::ostream * _out) throw()
        {   out = _out;   }
        std::ostream * getStream(void) throw()
        {   return out;   }
    };

        //忕挿弌椡僗僩儕乕儉 (扨弮側梷巭婡峔偮偒儔僢僷乕僋儔僗)
    class VerboseStream
    {
    protected:
        std::ostream * out;

    public:
        VerboseStream(std::ostream * _out = 0) throw() : out(_out) {};

        template<class T>
        VerboseStream & operator << (const T & src) throw()
        {
            if(out != 0)
                (*out) << src;
            return *this;
        }
    };

protected:
        //僨僼僅儖僩僐儞僗僩儔僋僞 (僥僗僩梡)
    VerboseMessage(void) throw();

public:

        //僐儞僗僩儔僋僞
    VerboseMessage(const char * src) throw();
    VerboseMessage(const std::string & src) throw();
    VerboseMessage(const char * src1, const char * src2, ... ) throw();

        //僨僗僩儔僋僞
    ~VerboseMessage(void) throw();

        //忕挿弌椡惂屼 (傾僋僙僒夞憲)
    inline static void setVerbose(bool _verbose) throw()
    {   Singleton<VerboseControl>::getInstance()->setVerbose(_verbose);   }

        //忕挿弌椡愭僗僩儕乕儉愝掕 (傾僋僙僒夞憲)
    inline static void setStream(std::ostream * _stream) throw()
    {   Singleton<VerboseControl>::getInstance()->setStream(_stream);   }

        //忕挿弌椡惂屼偺忬懺庢摼
    inline static bool getVerbose(void) throw()
    {   return Singleton<VerboseControl>::getInstance()->getVerbose();   }

        //忕挿弌椡愭僗僩儕乕儉偺庢摼 (愝掕偟偨傕偺偲摨偠傕偺偼弌偰偙側偄)
    inline static VerboseStream getStream(void) throw()
    {   return VerboseStream(getVerbose() ? Singleton<VerboseControl>::getInstance()->getStream() : 0);   }

    //TESTSUITE_PROTOTYPE(main)
};

    /*
     *   椺奜儊僢僙乕僕梡暥帤楍惍宍僿儖僷乕僋儔僗
     */
class ExceptionMessage : public Message
{
public:
        //椺奜偺婋尟搙儗儀儖
    enum tagLevel {
        DEFAULT = 0,
        FATAL   = 1,
        WARNING = 2
    };

#ifdef EXCEPT_H
    class ExceptionMessageException : public Exception
    {
    friend class ExceptionMessage;
    protected:
        ExceptionMessageException(int _code, std::string _details) throw() : Exception("ExceptionMessage", _code, _details) {}
    };
#endif

protected:
    enum tagLevel level;

public:
        //僐儞僗僩儔僋僞
    ExceptionMessage(const char * src) throw();
    ExceptionMessage(const std::string & src) throw();
    ExceptionMessage(const char * src1, const char * src2, ...) throw();

    ExceptionMessage(enum tagLevel level = DEFAULT) throw();
    ExceptionMessage(enum tagLevel level, const char * src) throw();
    ExceptionMessage(enum tagLevel level, const std::string & src) throw();
    ExceptionMessage(enum tagLevel level, const char * src1, const char * src2, ...) throw();

    ExceptionMessage(const ExceptionMessage & src) throw();


        //婋尟搙儗儀儖嶲徠
    inline bool operator == (enum tagLevel _level) const throw()
    {   return level == _level;   }

        //婋尟搙儗儀儖嶲徠
    inline bool operator != (enum tagLevel _level) const throw()
    {   return !(operator ==(_level));   }

        //堷悢偺愝掕 (曉媝抣偺宆傪Message & 偐傜 ExceptionMessage & 偵偡傞偨傔偺彫嵶岺)
    template<class T>
    inline ExceptionMessage & operator << (const T & src) throw()
    {
        Message::operator << ( src );
        return *this;
    }

#ifdef EXCEPT_H     //Exception僋儔僗傪巊梡偡傞応崌
        //椺奜偺敪惗
    bool throwException(void) throw(Exception)
    {
        ExceptionMessageException exc(level, str());
        return exc.throwException();
    }
        //儅僯僺儏儗乕僞
    inline ExceptionMessage & operator << ( ExceptionMessage & (* func)(ExceptionMessage &) ) throw(Exception)
    {   return (*func)(*this);   }

#else               //stdexcept傪巊梡偡傞応崌
        //椺奜偺敪惗
    template<class T>
    bool throwException(void) throw(T)
    {
        throw T(str());
        return true;
    }
        //儅僯僺儏儗乕僞
    inline ExceptionMessage & operator << ( ExceptionMessage & (* func)(ExceptionMessage &) ) throw(T)
    {   return (*func)(*this);   }
#endif

    //TESTSUITE_PROTOTYPE(main)
};

#ifdef EXCEPT_H     //Exception僋儔僗傪巊梡偡傞応崌

        //椺奜傪僗儘乕偡傞偨傔偺儅僯僺儏儗乕僞
    inline ExceptionMessage & throwException(ExceptionMessage & excmsg) throw(Exception)
    {
        excmsg.throwException();
        return excmsg;
    }

#else
        //椺奜傪僗儘乕偡傞偨傔偺儅僯僺儏儗乕僞
    template<class T>
    inline ExceptionMessage & throwException(ExceptionMessage & excmsg) throw(T)
    {
        excmsg.throwException<T>();
        return excmsg;
    }

#endif



    /*
     *   僨僶僢僌忣曬弌椡梡暥帤楍惍宍僿儖僷乕僋儔僗
     */
class DebugMessage : public Formatter
{
public:
        //嫟捠偺忕挿弌椡忣曬傪帩偮僋儔僗 (僔儞僌儖僩儞偵偡傞偺偱VerboseControl傪摨偠傕偺傪僋儔僗壔偡傞)
    class DebugControl : public VerboseMessage::VerboseControl
    { public: SINGLETON_CONSTRUCTOR_(DebugControl) throw() : VerboseMessage::VerboseControl(_singleton) {} };


protected:
        //僨僼僅儖僩僐儞僗僩儔僋僞 (僥僗僩梡)
    DebugMessage(void) throw();

public:

        //僐儞僗僩儔僋僞
    DebugMessage(std::string src) throw();

        //僨僗僩儔僋僞
    ~DebugMessage(void) throw();

        //忕挿弌椡惂屼 (傾僋僙僒夞憲)
    inline static void setVerbose(bool _verbose) throw()
    {   Singleton<DebugControl>::getInstance()->setVerbose(_verbose);   }

        //忕挿弌椡愭僗僩儕乕儉愝掕 (傾僋僙僒夞憲)
    inline static void setStream(std::ostream * _stream) throw()
    {   Singleton<DebugControl>::getInstance()->setStream(_stream);   }

        //忕挿弌椡惂屼偺忬懺庢摼
    inline static bool getVerbose(void) throw()
    {   return Singleton<DebugControl>::getInstance()->getVerbose();   }

        //忕挿弌椡愭僗僩儕乕儉偺庢摼 (愝掕偟偨傕偺偲摨偠傕偺偼弌偰偙側偄)
    inline static VerboseMessage::VerboseStream getStream(void) throw()
    {   return VerboseMessage::VerboseStream(getVerbose() ? Singleton<DebugControl>::getInstance()->getStream() : 0);   }

//  TESTSUITE_PROTOTYPE(main)
};


#endif  //MESSAGE_H


⌨️ 快捷键说明

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