JohnQ said:
Can they be implemented that way though (early work did exactly that).
If you refer to cfront then that's not true. The output from cfront
just used C as the "assembler".
This is a cute piece of code - do this with macros.
=======================================================================
// ======== GroupRangeDefine ==========================================
/**
* This is used in the specializations of the GroupTypeData template
* below. It contains the specification of the beginning of the
* range as specified in the dxf file.
*/
template <
int w_From,
int w_To,
typename w_ExternalType,
typename w_InternalType = w_ExternalType,
bool w_skip_white = false
class GroupRangeDefine
{
public:
enum {
e_From = w_From,
e_To = w_To
};
// ======== Traits ================================================
/**
* This defines the traits for this group.
*
*/
class Traits
{
public:
enum { SkipWhiteSpace = false };
typedef w_ExternalType t_ExternalType;
typedef w_InternalType t_InternalType;
};
typedef Traits t_Traits;
typedef typename GroupSemanticData<w_From>::t_SemanticTraits
t_SemanticTraits;
};
// ======== GroupTypeData =============================================
/**
* GroupTypeData scans recursively through the types looking for
* the specialization that corresponds to the w_GroupCode parameter.
* This is done so that the specifications for the group type data
* correspond in a 1:1 fashion with the dxf spec. This makes the
* compiler fill in all the blanks and hence less tedious or
* error prone.
*/
template <int w_GroupCode>
class GroupTypeData
{
public:
enum {
e_From = GroupTypeData<w_GroupCode-1>::e_From,
e_To = GroupTypeData<w_GroupCode-1>::e_To
};
typedef
typename at::TypeSelect<
(e_To < w_GroupCode),
GroupTraits_Undefined,
typename GroupTypeData said:
t_Traits;
typedef
typename GroupSemanticData<w_GroupCode>::t_SemanticTraits
t_SemanticTraits;
};
// specializations based on dxf documentation for "AutoCAD 2007 - March
2006"
template <> class GroupTypeData< 0 > : public GroupRangeDefine< 0, 9,
std::string > {}; // String
template <> class GroupTypeData< 10 > : public GroupRangeDefine< 10, 39,
double > {}; // Double precision 3D point value
template <> class GroupTypeData< 40 > : public GroupRangeDefine< 40, 59,
double > {}; // Double-precision floating-point value
template <> class GroupTypeData< 60 > : public GroupRangeDefine< 60, 79,
at::Int16 > {}; // 16-bit integer value
template <> class GroupTypeData< 90 > : public GroupRangeDefine< 90, 99,
at::Int32 > {}; // 32-bit integer value
template <> class GroupTypeData< 100 > : public GroupRangeDefine< 100,
100, std::string > {}; // String (255-character maximum; less for
Unicode strings)
template <> class GroupTypeData< 102 > : public GroupRangeDefine< 102,
102, std::string > {}; // String (255-character maximum; less for
Unicode strings)
template <> class GroupTypeData< 105 > : public GroupRangeDefine< 105,
105, std::string > {}; // String representing hexadecimal (hex) handle value
template <> class GroupTypeData< 110 > : public GroupRangeDefine< 110,
119, double > {}; // Double precision floating-point value
template <> class GroupTypeData< 120 > : public GroupRangeDefine< 120,
129, double > {}; // Double precision floating-point value
template <> class GroupTypeData< 130 > : public GroupRangeDefine< 130,
139, double > {}; // Double precision floating-point value
template <> class GroupTypeData< 140 > : public GroupRangeDefine< 140,
149, double > {}; // Double precision scalar floating-point value
template <> class GroupTypeData< 170 > : public GroupRangeDefine< 170,
179, at::Int16 > {}; // 16-bit integer value
template <> class GroupTypeData< 210 > : public GroupRangeDefine< 210,
239, double > {}; // Double-precision floating-point value
template <> class GroupTypeData< 270 > : public GroupRangeDefine< 270,
279, at::Int16 > {}; // 16-bit integer value
template <> class GroupTypeData< 280 > : public GroupRangeDefine< 280,
289, at::Int16 > {}; // 16-bit integer value
template <> class GroupTypeData< 290 > : public GroupRangeDefine< 290,
299, at::Int8, bool > {}; // Boolean flag value
template <> class GroupTypeData< 300 > : public GroupRangeDefine< 300,
309, std::string > {}; // Arbitrary text string
template <> class GroupTypeData< 310 > : public GroupRangeDefine< 310,
319, BinaryXdata, std::string > {}; // String representing hex value of
binary chunk
template <> class GroupTypeData< 320 > : public GroupRangeDefine< 320,
329, BinaryXdata, std::string > {}; // String representing hex handle value
template <> class GroupTypeData< 330 > : public GroupRangeDefine< 330,
369, std::string > {}; // String representing hex object IDs
template <> class GroupTypeData< 370 > : public GroupRangeDefine< 370,
379, at::Int16 > {}; // 16-bit integer value
template <> class GroupTypeData< 380 > : public GroupRangeDefine< 380,
389, at::Int16 > {}; // 16-bit integer value
template <> class GroupTypeData< 390 > : public GroupRangeDefine< 390,
399, std::string > {}; // String representing hex handle value
template <> class GroupTypeData< 400 > : public GroupRangeDefine< 400,
409, at::Int16 > {}; // 16-bit integer value
template <> class GroupTypeData< 410 > : public GroupRangeDefine< 410,
419, std::string > {}; // String
template <> class GroupTypeData< 420 > : public GroupRangeDefine< 420,
429, at::Int32 > {}; // 32-bit integer value
template <> class GroupTypeData< 430 > : public GroupRangeDefine< 430,
439, std::string > {}; // String
template <> class GroupTypeData< 440 > : public GroupRangeDefine< 440,
449, at::Int32 > {}; // 32-bit integer value
template <> class GroupTypeData< 450 > : public GroupRangeDefine< 450,
459, at::Int32 > {}; // Long
template <> class GroupTypeData< 460 > : public GroupRangeDefine< 460,
469, double > {}; // Double-precision floating-point value
template <> class GroupTypeData< 470 > : public GroupRangeDefine< 470,
479, std::string > {}; // String
template <> class GroupTypeData< 999 > : public GroupRangeDefine< 999,
999, std::string > {}; // Comment (string)
template <> class GroupTypeData< 1000 > : public GroupRangeDefine< 1000,
1009, std::string > {}; // String (same limits as indicated with 0-9
code range)
template <> class GroupTypeData< 1010 > : public GroupRangeDefine< 1010,
1059, double > {}; // Double-precision floating-point value
template <> class GroupTypeData< 1060 > : public GroupRangeDefine< 1060,
1070, at::Int16 > {}; // 16-bit integer value
template <> class GroupTypeData< 1071 > : public GroupRangeDefine< 1071,
1071, at::Int32 > {}; // 32-bit integer value
template <> class GroupTypeData< -5 > : public GroupRangeDefine< -5, -5,
std::string > {}; // APP: persistent reactor chain
template <> class GroupTypeData< -4 > : public GroupRangeDefine< -4, -4,
std::string > {}; // APP: conditional operator (used only with ssget)
template <> class GroupTypeData< -3 > : public GroupRangeDefine< -3, -3,
BinaryXdata, std::string > {}; // APP: extended data (XDATA) sentinel
(fixed)
template <> class GroupTypeData< -2 > : public GroupRangeDefine< -2, -2,
std::string > {}; // APP: entity name reference (fixed)
=======================================================================
This code allows the mapping of an int to type. This made the parsing
of dxf files a piece of cake. This can be used in a table or directly
in code and is basically a simple transformation from the dxf
documentation making the dxf parser easy to write from this point. I
don't think you can remotely do this with macros as they stand today.
After having written this DXF parser, I have yet to find a file that it
can't parse which is more than I can say for some commercial code I've
used. The neat thing is that it took me less time to write the parser
than it did trying to fix the previous version simply because I can
model the code to fit the specification closer that I could in C.
Can you create a macro to tell you if a type converts to another type or
if a type has a particular member or change behaviour of a function
template for a specific type (I call this the C++ come-from).
I disagree. I'm leaning toward "they should be the same". Beyond that
(macros), templates become unwieldly.
Templates do have a learning curve. You do have to think of your code
in a more generic fashion.
....
Again, I whole-heartedly disagree.
That you disagree is great. Don't stop there, do tell us of your reasoning.