473,396 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

template class XML parser

I wrote a template class that inherits from the PUG xml_tree_walker
class so that I can load data from any XML file without having to
write a parser for each one.

template <class T>
class CGenericXMLWalker : public pug::xml_tree_walker
{
T* m_pData;

public:

CGenericXMLWalker(T* pDataIn);

~CGenericXMLWalker();

T* GetData() {m_pData->AddRef(); return m_pData;}

//Traversal begin callback.
bool begin(pug::xml_node& node);

//Traversal node callback; cumulatively outputs a simple document
outline.
bool for_each(pug::xml_node& node);

//Traversal end callback.
bool end(pug::xml_node& node);

bool traverse(pug::xml_node& node);

VOID AddNodeAttributes(pug::xml_node& node);
};
It calls a function that I have defined in another file that accepts
an xml node and determines which class to pass to the template based
on the name of the xml node.

PDataDefObject TraverseDataType(pug::xml_node & Node)
{
if (Node.empty() || Node.has_attribute( "NoParse" ) )
return NULL;

PDataDefObject pDataDefObject = NULL;
static TagMap mapObjectTypes;
static std::vector<ULONGaObjectCounts;

if (mapObjectTypes.empty())
{
// fill map here

mapObjectTypes["AbilityBonus"] = DATA_TYPE_ABILITY_BONUS;
mapObjectTypes["AbilityBonusOptions"] =
DATA_TYPE_ABILITY_BONUS_OPTION;
// etc

}

if (aObjectCounts.empty())
{
aObjectCounts.assign(NUM_ELEMENTAL_DATA_TYPES, 0);
}

ULONG ulDataType = UNKNOWN_ELEMENTAL_DATA_TYPE;
ULONG ulObjectCount = 0;

TagMap::iterator itFind = mapObjectTypes.find(Node.name());
if (itFind != mapObjectTypes.end())
{
ulDataType = (*itFind).second;

ulObjectCount = aObjectCounts[ulDataType];

switch(ulDataType)
{
case DATA_TYPE_ABILITY_BONUS:
{
PAbilityBonus pAbilityBonus = NULL;
CGenericXMLWalker<CAbilityBonusWalker(pAbilityBonu s);
if (Walker.traverse(Node))
{
pDataDefObject = (PDataDefObject) Walker.GetData();
}
}
break;

case DATA_TYPE_ABILITY_BONUS_OPTION:
{
PAbilityBonusOption pOption = NULL;
CGenericXMLWalker<CAbilityBonusOptionWalker(pOptio n);
if (Walker.traverse(Node))
{
pDataDefObject = (PDataDefObject) Walker.GetData();
}
}
break;
};
}

if (pDataDefObject)
{
pDataDefObject->SetDataTypeString(Node.name());
pDataDefObject->SetDataType(ulDataType);

++ulObjectCount;
aObjectCounts[ulDataType] = ulObjectCount;
}

return pDataDefObject;
}

It compiles OK, but I get linker errors:

error LNK2019: unresolved external symbol "public: virtual __thiscall
CGenericXMLWalker<class CAbilityBonusOption>::~CGenericXMLWalker<class
CAbilityBonusOption>(void)" (??1?
$CGenericXMLWalker@VCAbilityBonusOption@@@@UAE@XZ) referenced in
function "class CDataDefObject * __cdecl TraverseDataType(class
pug::xml_node &)" (?
TraverseDataType@@YAPAVCDataDefObject@@AAVxml_node @pug@@@Z)

error LNK2019: unresolved external symbol "public: bool __thiscall
CGenericXMLWalker<class CAbilityBonusOption>::traverse(class
pug::xml_node &)" (?traverse@?
$CGenericXMLWalker@VCAbilityBonusOption@@@@QAE_NAA Vxml_node@pug@@@Z)
referenced in function "class CDataDefObject * __cdecl
TraverseDataType(class pug::xml_node &)" (?
TraverseDataType@@YAPAVCDataDefObject@@AAVxml_node @pug@@@Z)

error LNK2019: unresolved external symbol "public: __thiscall
CGenericXMLWalker<class CAbilityBonusOption>::CGenericXMLWalker<class
CAbilityBonusOption>(class CAbilityBonusOption *)" (??0?
$CGenericXMLWalker@VCAbilityBonusOption@@@@QAE@PAV CAbilityBonusOption@@@Z)
referenced in function "class CDataDefObject * __cdecl
TraverseDataType(class pug::xml_node &)" (?
TraverseDataType@@YAPAVCDataDefObject@@AAVxml_node @pug@@@Z)

error LNK2019: unresolved external symbol "public: virtual __thiscall
CGenericXMLWalker<class CAbilityBonus>::~CGenericXMLWalker<class
CAbilityBonus>(void)" (??1?
$CGenericXMLWalker@VCAbilityBonus@@@@UAE@XZ) referenced in function
"class CDataDefObject * __cdecl TraverseDataType(class pug::xml_node
&)" (?TraverseDataType@@YAPAVCDataDefObject@@AAVxml_no de@pug@@@Z)

error LNK2019: unresolved external symbol "public: bool __thiscall
CGenericXMLWalker<class CAbilityBonus>::traverse(class pug::xml_node
&)" (?traverse@?
$CGenericXMLWalker@VCAbilityBonus@@@@QAE_NAAVxml_n ode@pug@@@Z)
referenced in function "class CDataDefObject * __cdecl
TraverseDataType(class pug::xml_node &)" (?
TraverseDataType@@YAPAVCDataDefObject@@AAVxml_node @pug@@@Z)

error LNK2019: unresolved external symbol "public: __thiscall
CGenericXMLWalker<class CAbilityBonus>::CGenericXMLWalker<class
CAbilityBonus>(class CAbilityBonus *)" (??0?
$CGenericXMLWalker@VCAbilityBonus@@@@QAE@PAVCAbili tyBonus@@@Z)
referenced in function "class CDataDefObject * __cdecl
TraverseDataType(class pug::xml_node &)" (?
TraverseDataType@@YAPAVCDataDefObject@@AAVxml_node @pug@@@Z)
: fatal error LNK1120: 6 unresolved externals

I've got all the proper files included, all my classes are defined,
and I just can't figure out why it's getting the linker errors. Does
anyone have any ideas?

Thanks.

Feb 22 '07 #1
2 1990
Cari Elf wrote:
I wrote a template class that inherits from the PUG xml_tree_walker
class so that I can load data from any XML file without having to
write a parser for each one.

template <class T>
class CGenericXMLWalker : public pug::xml_tree_walker
{
[snip]
>
I've got all the proper files included, all my classes are defined,
and I just can't figure out why it's getting the linker errors. Does
anyone have any ideas?

Thanks.
Because template code should be placed in header files, all of it.

This is a FAQ

http://www.parashift.com/c++-faq-lit...html#faq-35.12

john
Feb 22 '07 #2
On Feb 22, 6:25 pm, John Harrison <john_androni...@hotmail.comwrote:
Cari Elf wrote:
I wrote a template class that inherits from the PUG xml_tree_walker
class so that I can load data from any XML file without having to
write a parser for each one.
template <class T>
class CGenericXMLWalker : public pug::xml_tree_walker
{

[snip]
I've got all the proper files included, all my classes are defined,
and I just can't figure out why it's getting the linker errors. Does
anyone have any ideas?
Thanks.

Because template code should be placed in header files, all of it.

This is a FAQ

http://www.parashift.com/c++-faq-lit...html#faq-35.12

john
Thank you, I'll have to try that. None of the references I checked
mentioned that.

Feb 26 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Andrea A | last post by:
Hi, i'm developing a website that will have an huge amount of visitors a day --> it will be a contest with 100.000$ of prize. I'm concerning about using a template class (and which one do you...
2
by: Xenos | last post by:
The new version of GCC is out and in its list of changes, it talks about the C++ Standard's requirements for using the typename and template keywords to disambiguate dependent names. I'm use to...
5
by: Shlomi | last post by:
Hi ! I've wrote quite a big code which bases on a considerable large amount of template classes. (uses many different kinds of each template class). Now, without prior knowledge of mine, it...
2
by: max_sang | last post by:
Hello I have a nasty problem... take a look at this code: struct Parser { Parser(const string& s) { ... tokenizes s into pieces... } template <class T> to(size_t idx); private: vector<string>...
4
by: Hendrik Schober | last post by:
Hi, this is a cut down version of some some template meta stuff that I have: /////////////////////////////////////////////////////// template< typename TL, typename TR > struct Dummy1 {}; ...
2
by: a | last post by:
I'm having problem compiling this simple template program, my g++ complains it doesn't know what size and ia are on ArrayRC. TIA, John #include <iostream.h>
2
by: Joseph Turian | last post by:
I have a class Feature defined, which is a kind of Vocab: template <class T, unsigned I> class Vocab : boost::totally_ordered<Vocab<T,I { public: Vocab(); Vocab(const T& t); template<typename...
1
by: gio | last post by:
I have a template class with a function that looks like this: template <class Key, int Value, class Tail> struct Parser<Typelist< MakePair<Key, Value>, Tail >, EmptyType> { static...
3
by: Pierre Yves | last post by:
Hi there, Template, once again... Nice topic but a bit tricky to code. My problem is the following: I have to video parser which retrieve image frames. The pixel values can be unsigned char...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.