Modeling Services > Entry and Derived Data Members > Entry Data Members > Manipulating an Entry Data Member
 
Manipulating an Entry Data Member
Although it is an encapsulated type, the passengers data member behaves like an ordinary integer. The reason for this is that the type is implicitly converted to an int by a conversion operator. This type also includes an assignment operator.
Consequently, you can assign a new value to the entry passengers using the = operator like this:
b.passengers=20;
Similarly, an entry can be part of an expression as shown here:
half=b.passengers/2;
The getValue Function
In certain rare circumstances, the C++ compiler will have difficulty triggering a conversion to an integer explicitly. It is the case when you use a function with an ellipsis:
void F(...); // this function expects an integer
void g(Flight& f){
   F(f.passengers);
}
What happens is that when the function F is called, the compiler passes the type IlsEntry<int> to the function instead of passing the integer. Since the signature of the function is not specified, the compiler is unable to convert the entry to an integer.
The code will compile but will no doubt abort.
The member function IlsEntry::getValue function which helps you specify the conversion as shown in the following example:
void F(...);
void g(Flight& f){
   F(f.passengers.getValue());
}
The getValue function returns an int so that the function F receives the expected value.
The getValue function can be also very useful when there are many conversion operators or constructors involved. When a C++ compiler encounters multiple user-defined conversions, it is unable to infer the appropriate operation. In this case, you can help the compiler by explicitly invoking the function getValue.
The type of an entry must follow a number of additional rules. In particular, if the type of the entry is a class or a struct, it must contain a valid default constructor and copy constructor. In addition, since Rogue Wave® Server uses the assignment operator = to update an entry, the type must also include an assignment operator that is compliant with C++ semantics.
When an entry is modified, its old value is not destroyed if it involves a pointer to data. If you want the old value to be automatically destroyed, you have to use a smart pointer as the type of the entry. If you do not want to explicitly destroy an entry that has the type character string before you reassign it, do not use char*; rather, use a smart pointer to a character string instead.
The touch Function 
An entry is usually modified by means of an assignment operator. This may cause a problem if the type of the entry is a list, for example. You might want to use a member function to update the entry rather than an assignment operator. In the case of a list, you might want to use an insertion member function.
In this case, however, Rogue Wave Server will not be aware of the update, and consequently notification or recomputation of derived data members might not work properly.
In this case, in addition to the required function calls on the entry type, you should use the member function IlsEntry::touch instead of an assignment operator.
Consider the class Container declaring a list of items:
class Container
{
private:
   ItemList items;
};
In Rogue Wave Server, you add an item to a list by means of the insertion operator << and remove an item from a list by means of the extraction operator >>. Let us suppose that you want to use an entry that stores a list. That entry offers only the assignment operator for updates.
Example
class Container:
public IlsObject
{
public:
   Container(): items(*this){}
private:
   IlsEntry<ItemList> items;
};
To solve the problem we have just mentioned, you must use the IlsEntry::touch function as follows.
class Container:
public IlsObject
{
public:
   Container(): items(*this){}
   void addItem(Item& i){
      items.touch();
      items.getValue()<<i;
   }
   void removeItem(Item& i){
      items.touch();
      items.getValue()>>i;
   }
private:
   IlsEntry<ItemList> items;
};
The function touch is equivalent to an update. It stores the previous value for notification and performs the required tasks to re-evaluate derived data members. Notification is documented in View and Notification Services. Derived data members are documented in the next section.

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