Generated Copy Functions

The -genCopy option causes copy functions to be generated. These functions can be used to copy the content of one generated type variable to another.

If no output file is specified with the –genCopy qualifier, the functions are written to separate .c/.cpp files for each module in the source file. The format of the name of each file is <module>Copy.c/.cpp where <module> would be replaced with the name of the ASN.1 module. If an output filename is specified after the –genCopy qualifier, all functions are written to that file.

The format of the name of each generated copy function is as follows:

   asn1Copy_[<prefix>]<prodName>

where <prodName> is the name of the ASN.1 production for which the function is being generated and <prefix> is an optional prefix that can be set via a configuration file setting. The configuration setting used to set the prefix is the <typePrefix> element. This element specifies a prefix that will be applied to all generated typedef names and function names for the production.

The calling sequence for each generated copy function is as follows:

   void asn1Copy_<name> (OSCTXT* pctxt,
                         <name>* pSrcValue,
                         <name>* pDstValue);

In this definition, <name> denotes the prefixed production name defined above.

The pointer to the context structure (pctxt) provides a storage area for the function to store all variables that have been copied

The pSrcValue argument is used to pass a pointer to a variable to be copied. The pDstValue argument is used to pass the pointer to the destination value. The source value is then copied to the destination value field-by-field. Memory will be allocated for dynamic fields using calls to the rtxMemAlloc function.

If C++ is used (-cpp option is specified) and PDU generation is not disabled (<noPDU> config option is not used) then the control class ASN1C_<name> additionally will contain:

Finally, the class declaration might look as follows:

   class EXTERN ASN1C_PersonnelRecord :
     public ASN1CType
   {
   protected:
      ASN1T_PersonnelRecord& msgData;
   public:
      ASN1C_PersonnelRecord (
         ASN1MessageBuffer& msgBuf, ASN1T_PersonnelRecord& data);

      ASN1C_PersonnelRecord (ASN1C_PersonnelRecord& original);

      ...

      ASN1T_PersonnelRecord& getCopy (ASN1T_PersonnelRecord*
                                      pDstData = 0);

      ASN1T_PersonnelRecord* newCopy ();

      inline ASN1C_PersonnelRecord&
         operator= (ASN1C_PersonnelRecord& srcData)
      {
         srcData.getCopy (&msgData);
         return *this;
      }
   } ;

The generated ASN1T<name> structure will also contain an additional copy constructor if C++ is used and PDU generation is not disabled. A destructor is also generated if the type contains dynamic memory fields. This destructor will free the dynamic memory upon destruction of the type instance.

For example:

   typedef struct EXTERN ASN1T_PersonnelRecord : public ASN1TPDU {
      ...
      ASN1T_PersonnelRecord () {
         m.uniPresent = 0;
         m.seqOfseqPresent = 0;
      }
      ASN1T_PersonnelRecord (ASN1C_PersonnelRecord& srcData);
      ~ASN1T_PersonnelRecord();
   } ASN1T_PersonnelRecord;

This constructor is used to create an instance of the ASN1T_<name> type from an ASN1C_<name> control class object.

Memory Management of Copied Items

Prior to ASN1C version 5.6, dynamic memory of decoded or copied items would only be available as long as the control class instance and/or the message buffer object used to decode or copy the item remained in scope or was not deleted. This restriction no longer exists as long as the type being copied is a Protocol Data Unit (PDU). The copied item will now hold a reference to the context variable used to create the item and will increment the item’s reference count. This reference is contained in the ASN1TPDU base class variable from which PDU data types are now derived. The dynamic memory within the item will persist until the item is deleted.