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 4196ed59d07c5373
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
     1.1 --- a/bindings/python/ns3modulegen.py	Sat Feb 14 14:02:40 2009 +0000
     1.2 +++ b/bindings/python/ns3modulegen.py	Wed Feb 18 12:23:08 2009 +0000
     1.3 @@ -86,6 +86,7 @@
     1.4      ns3modulegen_core_customizations.Simulator_customizations(root_module)
     1.5      ns3modulegen_core_customizations.CommandLine_customizations(root_module)
     1.6      ns3modulegen_core_customizations.TypeId_customizations(root_module)
     1.7 +    ns3modulegen_core_customizations.add_std_ofstream(root_module)
     1.8  
     1.9  
    1.10      for local_module in LOCAL_MODULES:
     2.1 --- a/bindings/python/ns3modulegen_core_customizations.py	Sat Feb 14 14:02:40 2009 +0000
     2.2 +++ b/bindings/python/ns3modulegen_core_customizations.py	Wed Feb 18 12:23:08 2009 +0000
     2.3 @@ -530,3 +530,20 @@
     2.4                                       flags=["METH_VARARGS", "METH_KEYWORDS", "METH_STATIC"])
     2.5  
     2.6  
     2.7 +def add_std_ofstream(module):
     2.8 +    module.add_include('<fstream>')
     2.9 +    ostream = module.add_class('ostream', foreign_cpp_namespace='::std')
    2.10 +    ostream.set_cannot_be_constructed("abstract base class")
    2.11 +    ofstream = module.add_class('ofstream', foreign_cpp_namespace='::std', parent=ostream)
    2.12 +    ofstream.add_enum('openmode', [
    2.13 +            ('app', 'std::ios_base::app'),
    2.14 +            ('ate', 'std::ios_base::ate'),
    2.15 +            ('binary', 'std::ios_base::binary'),
    2.16 +            ('in', 'std::ios_base::in'),
    2.17 +            ('out', 'std::ios_base::out'),
    2.18 +            ('trunc', 'std::ios_base::trunc'),
    2.19 +            ])
    2.20 +    ofstream.add_constructor([Parameter.new("const char *", 'filename'),
    2.21 +                              Parameter.new("::std::ofstream::openmode", 'mode', default_value="std::ios_base::out")])
    2.22 +    ofstream.add_method('close', None, [])
    2.23 +
     3.1 --- a/bindings/python/wscript	Sat Feb 14 14:02:40 2009 +0000
     3.2 +++ b/bindings/python/wscript	Wed Feb 18 12:23:08 2009 +0000
     3.3 @@ -15,7 +15,7 @@
     3.4  import Utils
     3.5  
     3.6  ## https://launchpad.net/pybindgen/
     3.7 -REQUIRED_PYBINDGEN_VERSION = (0, 9, 0, 605)
     3.8 +REQUIRED_PYBINDGEN_VERSION = (0, 10, 0, 626)
     3.9  REQUIRED_PYGCCXML_VERSION = (0, 9, 5)
    3.10  
    3.11  
     4.1 --- a/examples/wifi-ap.py	Sat Feb 14 14:02:40 2009 +0000
     4.2 +++ b/examples/wifi-ap.py	Wed Feb 18 12:23:08 2009 +0000
     4.3 @@ -154,9 +154,13 @@
     4.4    #   Config::Connect ("/NodeList/*/DeviceList/*/Phy/Tx", MakeCallback (&PhyTxTrace));
     4.5    #   Config::Connect ("/NodeList/*/DeviceList/*/Phy/State", MakeCallback (&PhyStateTrace));
     4.6  
     4.7 +    ascii = ns3.ofstream("wifi-ap.tr")
     4.8 +    ns3.YansWifiPhyHelper.EnableAsciiAll(ascii)
     4.9 +
    4.10      ns3.Simulator.Run()
    4.11  
    4.12      ns3.Simulator.Destroy()
    4.13 +    ascii.close()
    4.14  
    4.15      return 0
    4.16