Simon Pickles <sipickles <at> hotmail.com> writes:
Here is a similar approach with twist that works for me. The key is to force a
situation where only one file/object can 'own' the macro. This can be
accomplished by 'defining' an 'owner' and having the macro definition file check
if the owner is defined as a condition on whether to define
MYSQLPP_SSQLS_NO_STATICS.
Hope this help someone!
Here are three test files:
/////////////////////////////////////////////////////////
// MACRO DEFINITION FILE BEGIN
#ifndef MyTable_SsqlsMacroDef_h
#define MyTable_SsqlsMacroDef_h
// Block of common includes. Import ones are related to vector, at least for me.
#include <iostream>
#include <iomanip>
#include <string>
#include <time.h>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <fstream>
#include <sys/types.h>
#include <sys/stat.h>
#include <vector>
#include <deque>
#include <algorithm>
#include <climits>
#include <cstring>
#include <memory>
using namespace std;
// IMPORTANT /////////////////////////////
// Here we check of the existence of 'MyTable_SsqlsMacroDef_Owner'
// which is defined and undefined only within the 'owning' cpp file below.
//
// If MyTable_SsqlsMacroDef_Owner is NOT defined, then MYSQLPP_SSQLS_NO_STATICS
// is defined.
//
// If MyTable_SsqlsMacroDef_Owner IS defined, the MYSQLPP_SSQLS_NO_STATICS is
// undefined.
#ifndef MyTable_SsqlsMacroDef_Owner
#define MYSQLPP_SSQLS_NO_STATICS
#else
#undef MYSQLPP_SSQLS_NO_STATICS
#endif
// With the above MYSQLPP_SSQLS_NO_STATICS managed, now include the mysql++
// stuff
#include <mysql++/mysql++.h>
#include <mysql++/ssqls.h>
// MyTable SSQLS Macro Definition
sql_create_3(MyTable, 2, 3,
mysqlpp::sql_int_unsigned, id,
mysqlpp::sql_int_unsigned, key,
mysqlpp::sql_int_unsigned, data)
// Create a typedef vector of MyTable
typedef vector<MyTable> MyTableSsqlsObj_RowVector;
#endif
// MACRO DEFINITION FILE END
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
// MyTable_Class HEADER FILE BEGIN
#ifndef MyTable_Class_h
#define MyTable_Class_h
#include "MyTable_SsqlsMacroDef.h"
// MyTable_Class Declaration
class MyTable_Class{
public:
MyTable_Class();
// Try creating a 'MyTable' SSQLS Macro Object
MyTable MyTableSsqlsObj;
};
#endif
// MyTable_Class HEADER FILE END
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
// MyTable_Class CPP FILE BEGIN
// IMPORTANT: #define MyTable_SsqlsMacroDef_Owner
#ifndef MyTable_SsqlsMacroDef_Owner
#define MyTable_SsqlsMacroDef_Owner
// Now include MyTable_Class_h, which will in turn
// include MyTable_SsqlsMacroDef.h, which will react
// properly to the setting of MyTable_SsqlsMacroDef_Owner
// above
#ifndef MyTable_Class_h
#include "MyTable_Class.h"
#endif
// MyTable_Class Definitions
MyTable_Class::MyTable_Class(){
// Try using MyTableSsqlsObj_RowVector
MyTableSsqlsObj_RowVector MyTableSsqlsObj_RowVec;
}
// IMPORTANT:
// Here we must #undef MyTable_SsqlsMacroDef_Owner
#undef MyTable_SsqlsMacroDef_Owner
#endif
// MyTable_Class CPP FILE END
/////////////////////////////////////////////////////////
| Thread |
|---|
| • Re: Linking errors after moving to SSQLSs, macro problem | Mark G | 23 May |