Tutorial: Building an Rogue Wave Server Application > Designing the Server Object Model > Defining Entries
 
Defining Entries
With Rogue Wave® Server, you can define data members, called entries, whose update will trigger notification as well as the recalculation of derived data members depending on these entries.
You will find an overview of entries and derived data members in the section Entry and Derived Data Members of this manual. Notification is explained in Chapter 3 of this manual. You will learn how to use derived members in the next section, Defining Derived Members.
In this section, you are going to define entry data members for both the Node and Line classes, using the IlsEntry class template. This class template takes the type of the data member as its argument.
The entry data members that you are going to associate with the class Node are name and the coordinates x and y, which indicate the position of a node on a map.
1. Modify the Node class in the file network.h, like this:
class Node:
public IlsObject
{
public:
   Node(IlsIdentifier name, int x=1, int y=0);
   IlsEntry<IlsIdentifier> name;
   IlsEntry<int> x;
   IlsEntry<int> y;
   ....
}
IlsIdentifier is a smart pointer to a character string. When using IlsIdentifier, you do not have to explicitly delete character strings.
2. Modify the constructor of the class Node in the file network.cpp, like this:
Node::Node(IlsIdentifier nm, int px, int py):
   name(*this,nm),
   x(*this,px),
   y(*this,py),
   domain(*this),
   inputLines(*this),
   outputLines(*this)
{
}
Note: The names of the last two arguments passed to the constructors (px and py) are not the same as those of the corresponding data members (x and y). Giving the same names to both identifiers would cause one identifier to hide the other.
You are now going to declare the entry data members name and capacity for the class Line.
3. Modify the class Line in the file network.h,like this:
class Line: public IlsObject
{
public:
   Line(IlsIdentifier name, int cap, NodeP i, NodeP o);
   IlsEntry<IlsIdentifier> name;
   IlsEntry<int> capacity;
   IlsUses<Line,Node> input, output;
};
4. Modify the constructor for the class Line in the file network.cpp, like this:
Line::Line(IlsIdentifier n, int cap, NodeP i, NodeP o):
   name(*this,n),
   capacity(*this,cap),
   input(*this,i),
   output(*this,o)
{
}
5. Modify the main.cpp file created previously as indicated below and compile.
#include <network.h>
 
int
main()
{
   NetworkP n=new Network("mynetwork"); // builds a network
   DomainP d=new Domain(); // builds a domain
   n->domains<<d; // inserts domain in the network
   NodeP n1=new Node("Node 1", 5, 5); // creates n1
   NodeP n2=new Node("Node 2", 10, 10); // creates n2
   NodeP n3=new Node("Node 3", 15, 15); // creates n3
   NodeP n4=new Node("Node 4", 20, 20); // creates n4
   d->nodes<<n1<<n2<<n3<<n4; // inserts nodes in the domain
   LineP l1=new Line("L1", 10, n1, n2); // creates l1
   LineP l2=new Line("L2", 25, n2, n3); // creates l2
   LineP l3=new Line("L3", 40, n2, n4); // creates l3
   d->lines<<l1<<l2<<l3; // inserts lines in the domain
   return 0;
}
The network you get can be graphically represented, like this:
A Graphical Representation of the Network Object Model
6. Now add the following lines to the file main.cpp to rename the lines, just before return.
l1->name="Line 1";
l2->name="Line 2";
l3->name="Line 3";
7. Add the following line to modify the capacity of Line 1, just before return.
l1->capacity=5;
8. Move line 3 so as to connect Node 1 to Node 4, just before return and compile.
l3->input=n1;
l3->output=n4;
The resulting network can be graphically represented like this:
New State of Network Object Model
Summary
In this section, you have learned how to declare the entry data members name, x, and y for the class Node and the entry data members name and capacity for the class Line.
In the next section, we will demonstrate that the modification of an entry triggers the recomputation of a derived member that depends on it.

Version 6.3
Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.