ctemplate使用
来源:互联网 发布:广州手趣网络 招聘 编辑:程序博客网 时间:2024/05/29 09:15
CTemplate is a simple but powerful template language for C++. It emphasizes separating logic from presentation: it is impossible to embed application logic in this template language.
Here's an example of how to use it: not complete, but gives a good feel for what the ctemplate API looks like.
Here is a simple template file:
Hello {{NAME}},You have just won ${{VALUE}}!{{#IN_CA}}Well, ${{TAXED_VALUE}}, after taxes.{{/IN_CA}}
Here is a C++ program to fill in the template, which we assume is stored in the file 'example.tpl':
#include <stdlib.h>#include <string>#include <iostream> #include <google/template.h> int main(int argc, char** argv) { google::TemplateDictionary dict("example"); dict.SetValue("NAME", "John Smith"); int winnings = rand() % 100000; dict.SetIntValue("VALUE", winnings); dict.SetFormattedValue("TAXED_VALUE", "%.2f", winnings * 0.83); // For now, assume everyone lives in CA. // (Try running the program with a 0 here instead!) if (1) { dict.ShowSection("IN_CA"); } google::Template* tpl = google::Template::GetTemplate("example.tpl", google::DO_NOT_STRIP); std::string output; tpl->Expand(&output, &dict); std::cout << output; return 0;}
If you are interested in this templating language but are programming in Java, consider Hapax, which is similar to ctemplate.
News
ctemplate 0.91 introduces the beginning of some API changes, as I look to clean up the API in preparation for ctemplate 1.0. After 1.0, the API will remain backwards compatible, but until that time, the API may change. Please take a look at the ChangeLog to see if any of these changes affect you.
One change is the introduction of a new PerExpandData class, which holds some state that was formerly in the TemplateDictionary class. I'm still not sure if this class is a good idea, if it should be separate from TemplateDictionary or a member, or what functionality should move there (for instance, should SetTemplateGlobal move there, since template-global variables are really, in some sense, per-expand variables?) If you have any feedback, ideally based on your own experience using the current API, feel free to post it at google-ctemplate@googlegroups.com.
ctemplate also has several new features, including the addition of "separator" sections, and the ability to change the markup character (from {{). See the ChangeLog for a complete list, and the howto documentation for more details on these new features.
- ctemplate使用
- ctemplate简单使用test
- Google开源html模板库ctemplate的完整使用示例
- Google开源C++模板库ctemplate完整使用示例
- Google CTemplate:
- ctemplate模板
- [置顶] 使用 acl_cpp 的 HttpServlet 类及 google 的 ctemplate 库编写 WEB 应用
- Ctemplate的简介
- C++模板引擎Ctemplate的介绍
- C++模板引擎Ctemplate的介绍
- C++模板引擎Ctemplate的介绍
- C++ 模板引擎 Ctemplate 的介绍
- ctemplate在Windows下的编译
- 简介:google ctemplate:简单易用的文字模板
- 简介:google ctemplate:简单易用的文字模板
- 简介:google ctemplate:简单易用的文字模板
- 使用
- 使用
- 如何“干净地”终止 Win32 中的应用程序
- 重载与覆写
- Flexd的dataGrid控件使用(事件调用外部函数)
- 解Issue
- C++中const的正确用法之一
- ctemplate使用
- Creating Threads
- 工作中用到的日语
- 救火!各位大虾,怎样用JAVA程序读取excle文件或excle数据库,并插入到oracle数据库中,万分感谢
- delphi实现一个类继承抽象类并实现接口
- 高洛德着色
- Web应用程序的部署与安装(1)
- 设置与删除cookie时一定要注意路径问题(另读取cookie中firfox与ie的区别)
- 多普达S600短信不直接显示在屏幕上的设置方法