G_COPY(2) Demeter Software G_COPY(2) NAME g_copy - sends the generic copy message to an object. SYNOPSIS virtual Universal* Universal:: _g__c_o_p_y () DESCRIPTION _g__c_o_p_y performs a deep copy of the object to which the mes- sage is sent and returns the copy. This means that _g__c_o_p_y makes an instance of the class of the object. _g__c_o_p_y is then sent recursively to each part of the object to fill in the corresponding part in the newly made instance. The receiving object must be a tree object. That is, it cannot have any cycles or shared subobjects. REDEFINITION Since _g__c_o_p_y is a virtual function, it can be redefined at any user class. This means that the user can change what _g__c_o_p_y returns as a copy of any object. As a technical con- sideration, making _g__c_o_p_y virtual allows to define it recur- sively and to give the termination condition as a redefini- tion at the terminal classes DemIdent, DemNumber, DemReal, DemString, and DemText. RETURN VALUES _g__c_o_p_y returns an object of the class of the object to which the message was sent. However, the type returned by _g__c_o_p_y is _U_n_i_v_e_r_s_a_l*, since _g__c_o_p_y does not know in advance to what class the message is going to be sent. Therefore, the value returned must be cast to the appropriate type before it can be assigned or used in any way. For example: Compound* iCompound = new Compound(); iCompound = (Compound*)iCompound->g_parse("demeter-input"); Compound* iCompound2 = (Compound*)iCompound->g_copy(); if( iCompound->g_equal( iCompound2 ) == 1 ) cout << "Copied and original are equal\n"; else cout << "Copied and original are NOT equal\n"; SEE ALSO g_parse(2), g_equal(2), terminal(2), g_code(2), g_delete(2) Demeter Last change: 11 April 1991 1 G_COPY(2) Demeter Software G_COPY(2) REFERENCES _U_s_e_r _M_a_n_u_a_l _f_o_r _T_h_e _C++ _D_e_m_e_t_e_r Walter L. Hursch Northeastern University, 1993 _T_h_e _A_n_n_o_t_a_t_e_d _C++ _R_e_f_e_r_e_n_c_e _M_a_n_u_a_l Margaret A. Ellis and Bjarne Stroustrup Addison-Wesley, 1990 _C++ _P_r_i_m_e_r Stanley B. Lippman Addison-Wesley, 1989 Demeter Last change: 11 April 1991 2