alpar@2195: /** alpar@2195: \page getting_started Getting Started alpar@2195: alpar@2195: At the beginning we hardly suggest that you open your favorite text editor alpar@2195: and enter the code simultaneously as you read it. Compiling the demos is also alpar@2195: a good exercise. alpar@2195: alpar@2195: As the first example we show you a lemon style "Hello World" program. Now we alpar@2195: explain almost every line, but later we will skip the basics and focus on new alpar@2195: things. alpar@2195: alpar@2195: \section hello_world Hello World in LEMON alpar@2195: alpar@2195: In this little program we give you a taste of the LEMON programming. alpar@2195: alpar@2195: Let's see the code fragment to fragment! alpar@2195: alpar@2195: \dontinclude hello_world.cc alpar@2195: \skip include alpar@2195: \until iostream alpar@2195: alpar@2195: We want to use a \c lemon::ListGraph so the include goes like this: alpar@2195: \skip include alpar@2195: \until list_graph alpar@2195: alpar@2195: The next few lines are not necessary but useful shortcuts, if you don't alpar@2195: want to type \c lemon::ListGraph::Node every time. alpar@2195: \skip using alpar@2195: \until Edge alpar@2195: alpar@2195: For this demo we need to declare a ListGraph and a special NodeMap to store the alpar@2195: characters associated to the graph's nodes. alpar@2195: \skip main alpar@2195: \until char_map alpar@2195: alpar@2195: Adding nodes to the graph is very easy. alpar@2195: \skip new_node alpar@2195: \until addNode alpar@2195: alpar@2195: When a new node or edge to the graph the assigned maps are automatically resized. alpar@2195: So graphs can be build dynamically. The usage of a map is very natural. alpar@2195: \skip char_map alpar@2195: \until char_map alpar@2195: alpar@2195: Notice that no reference or additional assignment needed to work with nodes. alpar@2195: They won't become illegal or won't lead to throwing any exceptions. alpar@2195: You can declare and handle node like every other basic type such as \c int. alpar@2195: \skip Store alpar@2195: \until char_map alpar@2195: alpar@2195: As one expects adding an Edge is similar. You need to define the \b source node alpar@2195: and the \b destination node. The nodes must belong to the graph of course. The alpar@2195: Edge has the direction from the source to the destination. In some case you don't alpar@2195: want the edges to be directed - then you use an undirected graph. For example alpar@2195: lemon::ListUGraph. alpar@2195: \skip addEdge alpar@2195: \until addEdge alpar@2195: alpar@2195: In the next few lines we add some more nodes and edges and to the graph we need. alpar@2195: Those lines are not very interesting so we skip them, but you find the whole alpar@2195: working program in file hello_lemon.cc in the demo section. alpar@2195: alpar@2195: The next statement must be familiar. But what is that INVALID in the \c while alpar@2195: test statement? In LEMON we usually use the INVALID to check if an object alpar@2195: contains valid information. alpar@2195: \skip current_node alpar@2195: \until { alpar@2195: alpar@2195: We take the current node and write out the character assigned to it. Is's easy alpar@2195: with the \c char_map. alpar@2195: \skip std alpar@2195: \until std alpar@2195: alpar@2195: And here comes the trick. OutEdgeIt iterates on outgoing edges of a given node. alpar@2195: We pass the current node as argument to it, so the \c edge iterator will stand alpar@2195: on the first outgoing edge of the current node, or will be INVALID if the node alpar@2195: has no outgoing edges. alpar@2195: \skip edge alpar@2195: \until edge alpar@2195: alpar@2195: The graph we built before is linear, so we know that it ends, when no more outgoing alpar@2195: edges found. Otherwise the current node must be the node the edge points to. alpar@2195: Basic information about an edge can be requested from the graph. alpar@2195: \skip if alpar@2195: \until } alpar@2195: alpar@2195: Finish the code, just to be precise. alpar@2195: \skip return alpar@2195: \until } alpar@2195: alpar@2195: alpar@2195: \section compile_hw Compiling Hello World alpar@2195: To compile this program all you have to do is type in alpar@2195: \code g++ -ohw hello_world.cc \endcode alpar@2195: and press \c Enter! This is the case if you installed LEMON on your system. alpar@2195: (For more information see the LEMON installation instructions.) alpar@2195: alpar@2195: This is because LEMON is template library and most of it's code has to be available alpar@2195: as source code during compilation. alpar@2195: alpar@2195: Most programs using LEMON will compile as easy as this one unless you want to alpar@2195: use some performance measuring tools LEMON can provide. Then you need to link alpar@2195: an additional library against your program. alpar@2195: */