当前位置: 首页 > news >正文

网站建设的宗旨wordpress 随机标签

网站建设的宗旨,wordpress 随机标签,asp网站免费完整源码,做行政关注什么类型的网站以下示例展示了 log_agent 类,它类似于 dataflow_agent 类。 log_agent 类实现异步记录代理,用于将日志消息写入文件和控制台。 log_agent 类使应用程序能够将消息分类为信息性、警告或错误消息。 它还使应用程序能够指定每个日志类别是写入文件、控制台…

以下示例展示了 log_agent 类,它类似于 dataflow_agent 类。 log_agent 类实现异步记录代理,用于将日志消息写入文件和控制台。 log_agent 类使应用程序能够将消息分类为信息性、警告或错误消息。 它还使应用程序能够指定每个日志类别是写入文件、控制台还是同时写入这两者。 本示例将所有日志消息写入文件,并仅将错误消息写入控制台。

消息代理
// log-filter.cpp
// compile with: /EHsc 
#include <windows.h>
#include <agents.h>
#include <sstream>
#include <fstream>
#include <iostream>using namespace concurrency;
using namespace std;// A synchronization primitive that is signaled when its 
// count reaches zero.
class countdown_event
{
public:countdown_event(unsigned int count = 0L): _current(static_cast<long>(count)) {// Set the event if the initial count is zero.if (_current == 0L){_event.set();}}// Decrements the event counter.void signal(){if(InterlockedDecrement(&_current) == 0L){_event.set();}}// Increments the event counter.void add_count(){if(InterlockedIncrement(&_current) == 1L){_event.reset();}}// Blocks the current context until the event is set.void wait(){_event.wait();}private:// The current count.volatile long _current;// The event that is set when the counter reaches zero.event _event;// Disable copy constructor.countdown_event(const countdown_event&);// Disable assignment.countdown_event const & operator=(countdown_event const&);
};// Defines message types for the logger.
enum log_message_type
{log_info    = 0x1,log_warning = 0x2,log_error   = 0x4,
};// An asynchronous logging agent that writes log messages to 
// file and to the console.
class log_agent : public agent
{// Holds a message string and its logging type.struct log_message{wstring message;log_message_type type;};public:log_agent(const wstring& file_path, log_message_type file_messages, log_message_type console_messages): _file(file_path), _file_messages(file_messages), _console_messages(console_messages), _active(0){if (_file.bad()){throw invalid_argument("Unable to open log file.");}}// Writes the provided message to the log.void log(const wstring& message, log_message_type type){  // Increment the active message count._active.add_count();// Send the message to the network.log_message msg = { message, type };send(_log_buffer, msg);}void close(){// Signal that the agent is now closed._closed.set();}protected:void run(){//// Create the dataflow network.//// Writes a log message to file.call<log_message> writer([this](log_message msg){if ((msg.type & _file_messages) != 0){// Write the message to the file.write_to_stream(msg, _file);}if ((msg.type & _console_messages) != 0){// Write the message to the console.write_to_stream(msg, wcout);}// Decrement the active counter._active.signal();});// Connect _log_buffer to the internal network to begin data flow._log_buffer.link_target(&writer);// Wait for the closed event to be signaled._closed.wait();// Wait for all messages to be processed._active.wait();// Close the log file and flush the console._file.close();wcout.flush();// Set the agent to the completed state.done();}private:// Writes a logging message to the specified output stream.void write_to_stream(const log_message& msg, wostream& stream){// Write the message to the stream.wstringstream ss;switch (msg.type){case log_info:ss << L"info: ";break;case log_warning:ss << L"warning: ";break;case log_error:ss << L"error: ";}ss << msg.message << endl;stream << ss.str();}private:   // The file stream to write messages to.wofstream _file;// The log message types that are written to file.log_message_type _file_messages;// The log message types that are written to the console.log_message_type _console_messages;// The head of the network. Propagates logging messages// to the rest of the network.unbounded_buffer<log_message> _log_buffer;// Counts the number of active messages in the network.countdown_event _active;// Signals that the agent has been closed.event _closed;
};int wmain()
{// Union of all log message types.log_message_type log_all = log_message_type(log_info | log_warning  | log_error);// Create a logging agent that writes all log messages to file and error // messages to the console.log_agent logger(L"log.txt", log_all, log_error);// Start the agent.logger.start();// Log a few messages.logger.log(L"===Logging started.===", log_info);logger.log(L"This is a sample warning message.", log_warning);logger.log(L"This is a sample error message.", log_error);logger.log(L"===Logging finished.===", log_info);// Close the logger and wait for the agent to finish.logger.close();agent::wait(&logger);
}

本示例将以下输出写入控制台。

error: This is a sample error message.

此示例还生成 log.txt 文件,其中包含以下文本。

info: ===Logging started.===
warning: This is a sample warning message.
error: This is a sample error message.
info: ===Logging finished.===
编译代码

复制示例代码,并将它粘贴到 Visual Studio 项目中,或粘贴到名为 log-filter.cpp 的文件中,再在 Visual Studio 命令提示符窗口中运行以下命令。

cl.exe /EHsc log-filter.cpp

http://www.yayakq.cn/news/238494/

相关文章:

  • 使用c#语言建设网站优点wordpress必须安装php吗
  • 做网站好还是做app好网站图片验证码出不来
  • 用dw6做网站首页腾讯企业邮箱网页版登录入口
  • 网站帮助中心设计网站开发的投标案例
  • 苗木企业网站源码高职两学一做专题网站
  • 网站开发企业培训报名做推广网站的文章术语
  • 云南省城乡建设培训中心网站永州网站建设优化
  • 长沙做网站seo优化外包网站网络推广方式方法
  • 阳原网站建设辽宁建设工程信息网上开标流程
  • 网站建设步骤完整版中装建设集团有限公司董事长是谁
  • 遵义市播州区建设厅网站在线制作网站页面
  • 网站源码生成合肥经开区建设局网站
  • 建站自学网站建设培训会上的讲话
  • 信阳市住房和城乡建设厅网站广州企业网站模板购买
  • 西安道桥建设有限公司网站国外可以做会员网站的网站
  • 网站项目建设与管理论文ios开发用什么软件
  • 太原网站建设司假山网站建设
  • 有广告的网站输入网站域名
  • 适合做网站背景的图片新品牌进入市场的推广方案
  • 优质的网站建设微信开放平台开发者
  • 贵阳网站开发推荐做推广类门户网站怎么样
  • 网站php网站空间郑州区块链数字钱包网站开发周期
  • 一般公司网站用什么域名套餐网站建设排名的公司哪家好
  • 相城网站建设商城网站策划方案
  • 多语言建站系统个人网站建设与实现
  • 网站空间续费查询wordpress 淘客代码
  • jsp企业网站源码网站admin密码
  • 做那种事免费网站在线安装软件网站开发
  • 深圳网站建设网站运营js打开网站
  • 来宾住房和建设局网站wordpress积分充值插件