Python: wrap std::ostream/ofstream, for ascii tracing.
authorGustavo J. A. M. Carneiro <gjc@inescporto.pt>
Wed, 18 Feb 2009 12:23:08 +0000
changeset 4196 ed59d07c5373
parent 4195 e0a27ec2991a
child 4197 3aca059abe63
Python: wrap std::ostream/ofstream, for ascii tracing.
bindings/python/ns3modulegen.py
bindings/python/ns3modulegen_core_customizations.py
bindings/python/wscript
examples/wifi-ap.py
--- a/bindings/python/ns3modulegen.py	Sat Feb 14 14:02:40 2009 +0000
+++ b/bindings/python/ns3modulegen.py	Wed Feb 18 12:23:08 2009 +0000
@@ -86,6 +86,7 @@
     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:
--- a/bindings/python/ns3modulegen_core_customizations.py	Sat Feb 14 14:02:40 2009 +0000
+++ b/bindings/python/ns3modulegen_core_customizations.py	Wed Feb 18 12:23:08 2009 +0000
@@ -530,3 +530,20 @@
                                      flags=["METH_VARARGS", "METH_KEYWORDS", "METH_STATIC"])
 
 
+def add_std_ofstream(module):
+    module.add_include('<fstream>')
+    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, [])
+
--- a/bindings/python/wscript	Sat Feb 14 14:02:40 2009 +0000
+++ b/bindings/python/wscript	Wed Feb 18 12:23:08 2009 +0000
@@ -15,7 +15,7 @@
 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)
 
 
--- a/examples/wifi-ap.py	Sat Feb 14 14:02:40 2009 +0000
+++ b/examples/wifi-ap.py	Wed Feb 18 12:23:08 2009 +0000
@@ -154,9 +154,13 @@
   #   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