diff --git a/scratch/.gitignore b/scratch/.gitignore index d29af8d20..fc504faed 100644 --- a/scratch/.gitignore +++ b/scratch/.gitignore @@ -1,6 +1,5 @@ # Ignore everything on scratch by default, except the provided examples /* -!.gitignore !subdir/ !scratch-simulator.cc !CMakeLists.txt diff --git a/scratch/subdir/scratch-simulator-subdir.cc b/scratch/subdir/scratch-subdir-additional-header.cc similarity index 74% rename from scratch/subdir/scratch-simulator-subdir.cc rename to scratch/subdir/scratch-subdir-additional-header.cc index b0b774b35..e8238111e 100644 --- a/scratch/subdir/scratch-simulator-subdir.cc +++ b/scratch/subdir/scratch-subdir-additional-header.cc @@ -14,16 +14,17 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "ns3/core-module.h" +// This file contains the implementation of the functions declared in the +// corresponding header file. -using namespace ns3; +#include "scratch-subdir-additional-header.h" -NS_LOG_COMPONENT_DEFINE ("ScratchSimulator"); +namespace ns3 { -int -main (int argc, char *argv[]) +std::string +ScratchSubdirGetMessage () { - NS_LOG_UNCOND ("Scratch Simulator"); - CommandLine cmd; - cmd.Parse (argc, argv); + return "Scratch Subdir"; } + +} // namespace ns3 diff --git a/scratch/subdir/scratch-subdir-additional-header.h b/scratch/subdir/scratch-subdir-additional-header.h new file mode 100644 index 000000000..9e303edf8 --- /dev/null +++ b/scratch/subdir/scratch-subdir-additional-header.h @@ -0,0 +1,32 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +// This header does not provide much functionality but is meant to demonstrate how, +// in a scratch subdirectory, one can create new programs that are implemented +// in multiple files and headers. + +#include + +namespace ns3 { + +/** + * Get a message from the subdir. + * + * \return The message from the subdir + */ +std::string ScratchSubdirGetMessage (); + +} // namespace ns3 diff --git a/scratch/subdir/scratch-subdir.cc b/scratch/subdir/scratch-subdir.cc new file mode 100644 index 000000000..fd45398ad --- /dev/null +++ b/scratch/subdir/scratch-subdir.cc @@ -0,0 +1,49 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation; + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +// This example shows how to create new simulations that are implemented in +// multiple files and headers. The structure of this simulation project +// is as follows: +// +// scratch/ +// | subdir/ +// | | - scratch-subdir.cc // Main simulation file +// | | - scratch-subdir-additional-header.h // Additional header +// | | - scratch-subdir-additional-header.cc // Additional header implementation +// +// This file contains the main() function, which calls an external function +// defined in the "scratch-subdir-additional-header.h" header file and +// implemented in "scratch-subdir-additional-header.cc". + +#include "ns3/core-module.h" +#include "scratch-subdir-additional-header.h" +#include + +using namespace ns3; + +NS_LOG_COMPONENT_DEFINE ("ScratchSubdir"); + +int +main (int argc, char *argv[]) +{ + std::string message = ScratchSubdirGetMessage (); + NS_LOG_UNCOND (message); + + Simulator::Run (); + Simulator::Destroy (); + + return 0; +}