[Qt-interest] C code in QT use queue in Class
Mic J
michael.cognacc at gmail.com
Wed Aug 5 13:53:44 CEST 2009
>We still need to see some code. Show us the header file you are
>including. Global variables and extern declarations have been around
>for a while. Perhaps you don't need to include the header at all (in
>the C++ header), but instead make an extern "C" declaration for the
>variable that you need from the C header.
header file
---
#ifndef _S_57_DEFS_H
#define _S_57_DEFS_H
/*
* File: s_57_defs.h
* Author: run
*
* Created on March 10, 2009, 3:07 PM
*/
#ifdef __cplusplus
extern "C" {
#endif
#include <sys/queue.h>
typedef char octet;
typedef char tag[5]; //! \todo ? check this typedef, see page 146 k&r
// Leader is 24 octets (bytes long) both DDR an DR leader (S-57)
#define LEADER_SIZE 24
// Fieldtag size ie VRID, is 4 octets long, specified int S-57
#define FIELD_TAG_SIZE 4
// SHOULD Probably read this and check, but not now
// field RP 09
#define DDR_FIELD_CONTROL_LENGTH 9
// See iso8211 table 1 delimiter and their uses
// Unit terminator : printable '&' : Terminates a unit in a field
#define UT 0x1F // dec: 31 oct: \037
// Field terminator : printable ';' : Terminates a complete field(ex: VRID)
#define FT 0x1E // dec: 30 oct: \036
// This could be defined for each field (vrid, frid etc.)
#define STD_SIZE_LEN 220
struct GNAME {int len; char val[10];};
// global variables for conversion between octets to datatypes
// bXY : X is signednes Y is width in octets
unsigned char S57TYPE_b11; // UNSIGNED ONE OCTET CHAR
signed char S57TYPE_b21; // SIGNED ONE OCTET UNSIGNED CHAR
unsigned short S57TYPE_b12; // UNSIGNED TWO OCTET UNSIGNED CHAR
signed short S57TYPE_b22; // SIGNED TWO OCTET SIGNED CHAR
unsigned long S57TYPE_b14; //
signed long S57TYPE_b24; //
unsigned char S57TYPE_B5[5];
unsigned char S57TYPE_B8[8];
unsigned char S57TYPE_B[20]; // any large enough number
// DUMMY just to shut compiler up
char S57TYPE_A[200];
char S57TYPEA_UL[200]; // ascii unspecified length
char S57TYPEA_L8[8]; // which lengths
char S57TYPE_I[200]; // type i of generic legnth, real
length seen at data read time
double S57TYPE_R; // \note correct S57TYPE long ?
- think its incorrect!?
int LENGTH_TYPESIZE; // length to send as
parameter to function
TAILQ_HEAD(tailhead, DR_Data) dr_head;
typedef struct DR_Data // DR_Data is tag
{
char fieldtagname[5]; // the tagname, like VRID FOID DSSI, can be
used to look at the S57TYPE (if NAME = cast S57TYPE)
//BOOL is_toplevel; // is a toplevel field (ex: VRID)
int is_toplevel;
// record numbers used for debugging data structures
int dr_rec_nr; // total records ie FIELD numbers
int dr_toplevel_nr; // top level FIELDS (VRID, FOID, DSID, DSSI, ..)
number of toplevel fields, called a "RECORD BLOCK"
int dr_repeat_nr; // repeating fields number, same fields repeating count
// int dr_different_fields // total fields exclusive repeating
fields (counted once)
//-----------------
void *field_ptr; // void pointer to a field a HUGE case for
casting to field S57TYPE (or look out for aut5o generating)
struct DR_Data *next_data; // DR_Data is tag
// LIST struct list_head somename see man queue (LIST*)
TAILQ_ENTRY(DR_Data) dr_data_list;
}DR_Data; // DR_Data i typedef
DR_Data *dr_data_ptr, *dr_data_pnext, *dr_data_pprev;
struct tailhead *pos_data, *q_data, *dr_head_ptr;
void usage(char **arg);
// DR_Data *
int readRecordSet(char * s57_filename);
void queue_init(void);
#ifdef __cplusplus
}
#endif
#endif /* _S_57_DEFS_H */
---
c++ file using it(the DR_Data type):
chartinfo.h (chartinfo.cpp need it too)
Chartinfo is a collection of records of the type DR_Data
---
#ifndef CHARTINFO_H
#define CHARTINFO_H
#include <string>
extern "C"
{
#include <stdlib.h>
#include <assert.h>
#include "../../decode_seacharts/s_57_defs.h"
}
// inner struct / class
// latitude and longtiude coordinates
struct LatLon
{
signed long lat; // Latitude
signed long lon; // Longtitude
};
struct XYPos
{
int lat; // Latitude
int lon; // Longtitude
char * unit; // m or km // define domains ?
};
class ChartInfo
{
public:
ChartInfo();
void loadRecordSet(char *filename);
long long getLNAME_id(); // RCNM '+' RCID
long long getNAME_id();
signed long getLattitude();
signed long getLongtitude();
int translateLatLon_to_meters(struct LatLon ll);
int translateLatLon_to_kilometers(struct LatLon ll);
// test function traverse all dr_data
void traverseAllDRData();
private: // private functions
long long getRecordSet_key();
double convertLatLon_to_degree(signed long lon_or_lat);
// private variables and data =======================================
// DR_Data *genericDRData; // used for doing random things
// tailhead *q etc
};
#endif // CHARTINFO_H
---
> Pavel.
>PS. When you referred to TAILQ earlier, I assume you mean the queue
>macros described by man 3 queue (#include <sys/queue.h>). It's the
>first time I've heard of TAILQ.
Yes
Mic
More information about the Qt-interest-old
mailing list