From d1b501f370b61709a8613d507f551e24668ad1bd Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Wed, 18 Feb 2009 12:23:08 +0000 Subject: [PATCH] Python: wrap std::ostream/ofstream, for ascii tracing. --- bindings/python/ns3modulegen.py | 1 + .../python/ns3modulegen_core_customizations.py | 17 +++++++++++++++++ bindings/python/wscript | 2 +- examples/wifi-ap.py | 4 ++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/bindings/python/ns3modulegen.py b/bindings/python/ns3modulegen.py index a54fb5768..e3dd6790b 100755 --- a/bindings/python/ns3modulegen.py +++ b/bindings/python/ns3modulegen.py @@ -86,6 +86,7 @@ def main(): ns3modulegen_core_customizations.Simulator_customizations(root_module) ns3modulegen_core_customizations.CommandLine_customizations(root_module) ns3modulegen_core_customizations.TypeId_customizations(root_module) + ns3modulegen_core_customizations.add_std_ofstream(root_module) for local_module in LOCAL_MODULES: diff --git a/bindings/python/ns3modulegen_core_customizations.py b/bindings/python/ns3modulegen_core_customizations.py index d89c525b0..8ad75632f 100644 --- a/bindings/python/ns3modulegen_core_customizations.py +++ b/bindings/python/ns3modulegen_core_customizations.py @@ -530,3 +530,20 @@ def TypeId_customizations(module): flags=["METH_VARARGS", "METH_KEYWORDS", "METH_STATIC"]) +def add_std_ofstream(module): + module.add_include('') + ostream = module.add_class('ostream', foreign_cpp_namespace='::std') + ostream.set_cannot_be_constructed("abstract base class") + ofstream = module.add_class('ofstream', foreign_cpp_namespace='::std', parent=ostream) + ofstream.add_enum('openmode', [ + ('app', 'std::ios_base::app'), + ('ate', 'std::ios_base::ate'), + ('binary', 'std::ios_base::binary'), + ('in', 'std::ios_base::in'), + ('out', 'std::ios_base::out'), + ('trunc', 'std::ios_base::trunc'), + ]) + ofstream.add_constructor([Parameter.new("const char *", 'filename'), + Parameter.new("::std::ofstream::openmode", 'mode', default_value="std::ios_base::out")]) + ofstream.add_method('close', None, []) + diff --git a/bindings/python/wscript b/bindings/python/wscript index 403cbca07..d30b668c9 100644 --- a/bindings/python/wscript +++ b/bindings/python/wscript @@ -15,7 +15,7 @@ import Build import Utils ## https://launchpad.net/pybindgen/ -REQUIRED_PYBINDGEN_VERSION = (0, 9, 0, 605) +REQUIRED_PYBINDGEN_VERSION = (0, 10, 0, 626) REQUIRED_PYGCCXML_VERSION = (0, 9, 5) diff --git a/examples/wifi-ap.py b/examples/wifi-ap.py index 75f180d48..d02b5ad7b 100644 --- a/examples/wifi-ap.py +++ b/examples/wifi-ap.py @@ -154,9 +154,13 @@ def main(argv): # Config::Connect ("/NodeList/*/DeviceList/*/Phy/Tx", MakeCallback (&PhyTxTrace)); # Config::Connect ("/NodeList/*/DeviceList/*/Phy/State", MakeCallback (&PhyStateTrace)); + ascii = ns3.ofstream("wifi-ap.tr") + ns3.YansWifiPhyHelper.EnableAsciiAll(ascii) + ns3.Simulator.Run() ns3.Simulator.Destroy() + ascii.close() return 0