[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [libredwg] Reply to review about proposal

From: Till Heuschmann
Subject: Re: [libredwg] Reply to review about proposal
Date: Sat, 25 May 2013 21:44:30 +0200

Hi Gaganjyot,

your examples are high level but need some note:

Dwg_Object_LAYER ** extract_layers(Dwg_Data *dwg)

There is a Dwg_Object_LAYER_CONTROL struct in the drawing which represents the layer table. A good API function would be:

Dwg_Object_LAYER_CONTROL* dwg_get_layer_control(Dwg_Data *dwg);

To access the layer control these functions are possible:

// returns the number of records in the layer table
int dwg_layer_control_get_length(Dwg_Object_LAYER_CONTROL *ctrl);

// returns the layer at a given index
Dwg_Object_LAYER* dwg_layer_control_get_at(Dwg_Object_LAYER_CONTROL *ctrl, int index);

// returns the layer with a given handle 
Dwg_Object_LAYER* dwg_layer_control_get_by_handle(Dwg_Object_LAYER_CONTROL *ctrl, Dwg_Handle *handle);

// returns the layer with a given handle 
Dwg_Object_LAYER* dwg_layer_control_get_by_name(Dwg_Object_LAYER_CONTROL *ctrl, DWGCHAR *name);

unsigned char *
get_layer_name(Dwg_Object_Entity *entity, Dwg_Object_LAYER *layer)

This function is a litle bit too high level. It not only returns the name of a layer but the layer itself. It wold be better to split the function:

Dwg_Object_LAYER* dwg_entity_get_layer(Dwg_Object_Entity *entity);

DWGCHAR dwg_layer_get_name(Dwg_Object_LAYER *layer);

An API should hide the implementation details, that means a user of the API should not see the variables of internal structs like Dwg_Object_LAYER_CONTROL. Declare it as an opaque pointer in the header for the API: 

typedef struct Dwg_Object_LAYER_CONTROL Dwg_Object_LAYER_CONTROL; 

In the .c file where you implement the functions you can include the dwg.h and have the detailed definitions of all structs.


Am 24.05.2013 um 17:54 schrieb gagan:

On 5/24/13, Rodrigo Rodrigues da Silva <address@hidden> wrote:


As for low-level/high-level examples:

Dwg_Object * should_be_layer = obj->tio.entity->layer->obj;
   Dwg_Object_LAYER * layer;
   unsigned int _type = should_be_layer->type;
   printf("type = %u ", _type);
   if (_type == 51)
       layer = obj->tio.entity->layer->obj->tio.object->tio.LAYER; //low
level struct access

in a higher level c-ish way:

Dwg_Object_LAYER * layer;

int error = dwg_get_obj_layer(obj, &layer); //higher level c api


another example (I've implemented it already, I guess)

int layer_count = dwg_get_layer_count(&dwg_data);

Reading these, I have created 2 examples, Please have a look at them
and tell me if we can consider them developed in high level C ?

My API code :-

Dwg_Object_LAYER ** extract_layers(Dwg_Data *dwg)
 int i, a=0;
 Dwg_Object_LAYER **layer = (Dwg_Object_LAYER **)malloc(
 dwg_get_layer_count(dwg) * (sizeof (Dwg_Object_LAYER*) + 10));
   for (i = 0; i < dwg->num_objects; i++)
           layer[a] = dwg->object[i].tio.object->tio.LAYER;
return layer;

Application code :-


My API code :-

unsigned char *
get_layer_name(Dwg_Object_Entity *entity, Dwg_Object_LAYER *layer)
 layer = entity->layer->obj->tio.object->tio.LAYER;
 return layer->entry_name;

Application code :-
Dwg_Object_LAYER *layer;
get_layer_name(entity, layer); //here entity can be any, user should
know how to get entity here.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]