Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

ASN1 Object Factory

The Boost.ASN1 library uses a singleton object factory to instantiate asn_base_ptr objects during decoding of ASN1 PDUs. The library automagically registers all the known Boost.ASN1 objects when it is first called.

The asn_factory::create() method in the factory calls the registered create() method of the ASN1 object you are requesting and simply instantiates a new object and returns the asn_base_ptr. The asn_factory::create() method is defined as follows:

const primitive_t
Primitive data type
const construction_t
Construction type, defaults to _primitive
const classification_t
ASN1 object classification, defaults to _universal

asn_base_ptr create(const primitives_t primitive, 
                    const construction_t construction = _primitive, 
                    const classification_t classification = _universal);

To instantiate a new INTEGER ASN1 type, we would do the following:

asn_base_ptr asn_object = asn_factory::instance().create(_integer);

or

integer_ptr asn_integer = asn_factory::instance().create(_integer);

The asn_factory::subscribe() method is used to register ASN1 types that can be created by the factory. This method is mentioned here in the event that you are creating a custom ASN1 data type for your application.

asn_create_t
Create method for the ASN1 object:
typedef boost::function<shared_ptr<asn_base_t>()> asn_create_t;
const primitive_t
Primitive tag identifier
const construction_t
Construction type identifier
const classification_t
Classification identifier

void subscribe(asn_create_t creator, 
               const primitives_t primitive, 
               const construction_t construction, 
               const classification_t classification);

If you are attempting to create a new ASN1 type, you'll need to supply a create() method in your ASN1 type class. The method must be defined as static asn_base_ptr create();. This method should create a new instance of the type class and pass it back via the asn_base_ptr.

Copyright © 2007 Andreas Haberstroh

PrevUpHomeNext