more goo
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Mon Apr 06 17:06:39 2009 +0200 (11 months ago)
changeset 197626d19888ff
parent 18 2089a6e50f69
child 20 96f32c03843b
more goo
tutorial.tex
     1.1 --- a/tutorial.tex	Mon Apr 06 16:38:52 2009 +0200
     1.2 +++ b/tutorial.tex	Mon Apr 06 17:06:39 2009 +0200
     1.3 @@ -773,6 +773,108 @@
     1.4  \item We can set them all from environment variables
     1.5  \end{itemize}
     1.6  
     1.7 +\break
     1.8 +
     1.9 +Traditionally, in C++:
    1.10 +\begin{itemize}
    1.11 +\item Export attributes as part of a class's public API
    1.12 +\item Walk pointer chains (and iterators, when
    1.13 +  needed) to find what you need
    1.14 +\item Use static variables for defaults
    1.15 +\end{itemize}
    1.16 +For example:
    1.17 +{\footnotesize
    1.18 +\begin{block}{}
    1.19 +\begin{verbatim}
    1.20 +class MyModel {
    1.21 +public:
    1.22 +  MyModel () : m_foo (m_defaultFoo) {}
    1.23 +  void SetFoo (int foo) {m_foo = foo;}
    1.24 +  int GetFoo (void) {return m_foo}
    1.25 +  static void SetDefaultFoo (int foo) {m_defaultFoo = foo;}
    1.26 +  static int GetDefaultFoo (void) {return m_defaultFoo;}
    1.27 +private:
    1.28 +  int m_foo;
    1.29 +  static int m_defaultFoo = 10;
    1.30 +};
    1.31 +\end{verbatim}
    1.32 +\end{block}
    1.33 +}
    1.34 +
    1.35 +\break
    1.36 +
    1.37 +In ns-3, it's all done automatically:
    1.38 +\begin{itemize}
    1.39 +\item Set a default value:
    1.40 +{\footnotesize
    1.41 +\begin{block}{}
    1.42 +\begin{verbatim}
    1.43 +Config::SetDefaultValue ("ns3::WifiPhy::TxGain", StringValue ("10"));
    1.44 +\end{verbatim}
    1.45 +\end{block}
    1.46 +}
    1.47 +\item Set a value on a specific object:
    1.48 +{\footnotesize
    1.49 +\begin{block}{}
    1.50 +\begin{verbatim}
    1.51 +phy->SetAttribute ("TxGain", StringValue ("10"));
    1.52 +\end{verbatim}
    1.53 +\end{block}
    1.54 +}
    1.55 +\item Set a value deep in the system using a namespace string:
    1.56 +{\footnotesize
    1.57 +\begin{block}{}
    1.58 +\begin{verbatim}
    1.59 +Config::SetAttribute ("/NodeList/5/DeviceList/0/Phy/TxGain", 
    1.60 +                      StringValue ("10"));
    1.61 +\end{verbatim}
    1.62 +\end{block}
    1.63 +}
    1.64 +\item Set a value from the command-line \code{--ns3::WifiPhy::TxGain=10}:
    1.65 +{\footnotesize
    1.66 +\begin{block}{}
    1.67 +\begin{verbatim}
    1.68 +CommandLine cmd;
    1.69 +cmd.Parse (argc, argv);
    1.70 +\end{verbatim}
    1.71 +\end{block}
    1.72 +}
    1.73 +\end{itemize}
    1.74 +
    1.75 +\break
    1.76 +
    1.77 +All automatically:
    1.78 +\begin{itemize}
    1.79 +\item Load, Change, and Save all values from and to a raw text or xml file with a GUI:
    1.80 +{\footnotesize
    1.81 +\begin{block}{}
    1.82 +\begin{verbatim}
    1.83 +GtkConfigStore config;
    1.84 +config.ConfigureDefaults ();
    1.85 +...
    1.86 +config.ConfigureAttributes ();
    1.87 +\end{verbatim}
    1.88 +\end{block}
    1.89 +}
    1.90 +\item Load and Save all values from and to a raw text or xml file:
    1.91 +{\footnotesize
    1.92 +\begin{block}{}
    1.93 +\begin{verbatim}
    1.94 +ConfigStore config;
    1.95 +config.ConfigureDefaults ();
    1.96 +...
    1.97 +config.ConfigureAttributes ();
    1.98 +\end{verbatim}
    1.99 +\end{block}
   1.100 +}
   1.101 +\item Set a value with an environment variable \code{NS\_ATTRIBUTE\_DEFAULT=ns3::WifiPhy::TxGain=10}
   1.102 +\end{itemize}
   1.103 +
   1.104 +\break
   1.105 +
   1.106 +Attribute namespace strings are a structured representation of a path
   1.107 +through a set of object pointers:
   1.108 +
   1.109  \end{frame}
   1.110  
   1.111