CppUnit部分核心代码分析之Message

本文主要分析CppUnit中的Message类,它用于存储异常产生的信息。类包含简短描述和详细信息集合,并提供了多种构造函数及操作方法,如添加、获取和清除详细信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Message(异常信息对象)

说明:

对于异常(Exception)产生时候的一些信息说明。

预定义宏:

类设计详解:

类名:

classCPPUNIT_API Message

类图:


成员变量:

private:

  std::string m_shortDescription;  // 简短信息描述

  typedef CppUnitDeque<std::string>Details;

  Details m_details;  // 详细信息的集合描述

成员函数:

Message();

说明:

默认构造函数。

 

Message(const Message &other );

说明:

拷贝构造函数,支持线程安全,利用字符串缓冲区拷贝。

 

explicitMessage( const std::string &shortDescription );

说明:

不能默认转换的拷贝构造函数,初始化简短信息描述。

 

Message(const std::string &shortDescription,

           const std::string &detail1 );

说明:

构造函数,初始化简短信息和单个详细信息。

 

Message(const std::string &shortDescription,

           const std::string &detail1,

           const std::string &detail2 );

说明:

构造函数,初始化简短信息和两个详细信息。

 

Message(const std::string &shortDescription,

           const std::string &detail1,

           const std::string &detail2,

           const std::string &detail3 );

说明:

构造函数,初始化简短信息和三个详细信息。

 

 

Message&operator =( const Message &other );

说明:

赋值操作符,保证线程安全,利用字符串缓冲区构造。

 

conststd::string &shortDescription() const;

说明:

返回简短信息。

 

intdetailCount() const;

说明:

返回详细信息字符串的个数。

 

std::string detailAt(int index ) const;

说明:

返回index下标的详细信息,如果index<0或者index>count则报异常。

std::invalid_argument(),标准的C++参数异常。

 

std::stringdetails() const;

说明:

返回详细信息的连接字符串,每个详细信息中都通过’\n’来进行分割,以’-’开头。

 

voidclearDetails();

说明:

移除所有详细信息(clear).

 

voidaddDetail( const std::string &detail );

说明:

增加单个的详细信息到集合中。

 

voidaddDetail( const std::string &detail1,

                   const std::string &detail2 );

说明:

增加两个详细信息到集合中。

 

voidaddDetail( const std::string &detail1,

                   const std::string &detail2,

                   const std::string &detail3 );

说明:

增加三个的详细信息到集合中。

 

voidaddDetail( const Message &message );

说明:

增加特定Message中的详细信息在this集合中。

 

void setShortDescription(const std::string &shortDescription );

说明:

设置一个新的简短信息。

 

booloperator ==( const Message &other ) const;

bool operator !=( constMessage &other ) const;

说明:

操作符重载。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值