资源简介
JsonCpp is a C++ library that allows manipulating JSON values, including serialization and deserialization to and from strings. It can also preserve existing comment in unserialization/serialization steps, making it a convenient format to store user input files.
代码片段和文件信息
“““Amalgate json-cpp library sources into a single source and header file.
Works with python2.6+ and python3.4+.
Example of invocation (must be invoked from json-cpp top directory):
python amalgate.py
“““
import os
import os.path
import sys
class AmalgamationFile:
def __init__(self top_dir):
self.top_dir = top_dir
self.blocks = []
def add_text(self text):
if not text.endswith(“\n“):
text += “\n“
self.blocks.append(text)
def add_file(self relative_input_path wrap_in_comment=False):
def add_marker(prefix):
self.add_text(““)
self.add_text(“// “ + “/“*70)
self.add_text(“// %s of content of file: %s“ % (prefix relative_input_path.replace(“\\““/“)))
self.add_text(“// “ + “/“*70)
self.add_text(““)
add_marker(“Beginning“)
f = open(os.path.join(self.top_dir relative_input_path) “rt“)
content = f.read()
if wrap_in_comment:
content = “/*\n“ + content + “\n*/“
self.add_text(content)
f.close()
add_marker(“End“)
self.add_text(“\n\n\n\n“)
def get_value(self):
return ““.join(self.blocks).replace(“\r\n““\n“)
def write_to(self output_path):
output_dir = os.path.dirname(output_path)
if output_dir and not os.path.isdir(output_dir):
os.makedirs(output_dir)
f = open(output_path “wb“)
f.write(str.encode(self.get_value() ‘UTF-8‘))
f.close()
def amalgamate_source(source_top_dir=None
target_source_path=None
header_include_path=None):
“““Produces amalgated source.
Parameters:
source_top_dir: top-directory
target_source_path: output .cpp path
header_include_path: generated header path relative to target_source_path.
“““
print(“Amalgating header...“)
header = AmalgamationFile(source_top_dir)
header.add_text(“/// Json-cpp amalgated header (http://jsoncpp.sourceforge.net/).“)
header.add_text(‘/// It is intended to be used with #include “%s“‘ % header_include_path)
header.add_file(“LICENSE“ wrap_in_comment=True)
header.add_text(“#ifndef JSON_AMALGATED_H_INCLUDED“)
header.add_text(“# define JSON_AMALGATED_H_INCLUDED“)
header.add_text(“/// If defined indicates that the source file is amalgated“)
header.add_text(“/// to prevent private header inclusion.“)
header.add_text(“#define JSON_IS_AMALGAMATION“)
header.add_file(“include/json/version.h“)
#header.add_file(“include/json/allocator.h“) # Not available here.
header.add_file(“include/json/config.h“)
header.add_file(“include/json/forwards.h“)
header.add_file(“include/json/features.h“)
header.add_file(“include/json/value.h“)
header.add_file(“include/json/reader.h“)
header.add_file(“include/json/writer.h“)
header.add_file(“include/json/assertions.h“)
header.add_text(“#endif //
相关资源
- VC++ 实现定时关机或休眠-MFC 对话框应
- 循环列队数据结构课题舞会配对的问
- 校园导航系统c++数据结构
- c++ 编写的 有理数类
- C++远程监控软件源码
- C++经典练习例题200例
- C++原始SOCKET编写的SYN Flood 源码
- PTA基础编程答案
- 中国地质大学C++课件6
- springsnail项目源码
- 条码CODE128C语言算法
- 图书信息管理系统设计源代码C++
- fmod 音频库 c++ Qt编写
- 基于c++的RSA加密解密程序及源码
- 鼠标脚本精灵.rar
- 实现简单银行叫号模拟系统(C++版)
- C++万能头文件 stdc++.h
- 数据结构课设排序算法的可视化演示
- c++所有头文件
- C++ primer plus 第六版 全部编程练习答案
- stm32_Cjson源码
- C++面试题常见问题
- C++ 用户管理模块
- C++实现HTTP处理类
- C++2017.txt
- C.C++笔试面试必备宝典我就靠它进的公
- 02_C++PrimerPlus_中文版_第6版_超清.txt
- C++自绘柱状图.rar
- 自己写的元胞自动机NS模型
- 2048C++版本带图形界面
评论
共有 条评论