Continuing the quest for the aha moment, Tracking how a simple line gets loaded in heekscad

Ok… I’ve I’m pretty much picking up from the end of my last post. (I’m not really interested in created revisions every time I edit something so probably keep this in draft mode for a while. Especially since this has got me some what confused and is going to take me a bit to work this out.

Currently I’m trying to figure out what the heck is going on with

HeeksObj* HeeksCADapp::ReadXMLElement(TiXmlElement* pElem)
{
std::string name(pElem->Value());

std::map< std::string, HeeksObj*(*)(TiXmlElement* pElem) >::iterator FindIt = xml_read_fn_map.find( name );
HeeksObj* object = NULL;
if(FindIt != xml_read_fn_map.end())
{
object = (*(FindIt->second))(pElem);
}
else
{
object = HXml::ReadFromXMLElement(pElem);
}

return object;
}

I’m confused by the “(*)” in the map. I’m starting to get a hmm but not an aha as to  whats going on .
Time to start looking at examples and tutorials here:

http://www.yolinux.com/TUTORIALS/CppStlMultiMap.html
http://www.cplusplus.com/reference/stl/map/empty/

This tutorial is fun: http://www.dreamincode.net/forums/topic/57446-stl-maps/

Duhh err I mean aha…. I just realized what was going on in that code

std::map< std::string, HeeksObj*(*)(TiXmlElement* pElem) >::iterator FindIt = xml_read_fn_map.find( name );

What going on is were declaring an iterator to a map and actually setting to xml_read_fn_map.find( name );

xml_read_fn_map is declared and populated further upstream..

void HeeksCADapp::InitializeXMLFunctions()
{
// set up function map
if(xml_read_fn_map.size() == 0)
{
xml_read_fn_map.insert( std::pair< std::string, HeeksObj*(*)(TiXmlElement* pElem) > ( “Line”, HLine::ReadFromXMLElement ) );
xml_read_fn_map.insert( std::pair< std::string, HeeksObj*(*)(TiXmlElement* pElem) > ( “Arc”, HArc::ReadFromXMLElement ) );
xml_read_fn_map.insert( std::pair< std::string, HeeksObj*(*)(TiXmlElement* pElem) > ( “InfiniteLine”, HILine::ReadFromXMLElement ) );
xml_read_fn_map.insert( std::pair< std::string, HeeksObj*(*)(TiXmlElement* pElem) > ( “Circle”, HCircle::ReadFromXMLElement ) );
xml_read_fn_map.insert( std::pair< std::string, HeeksObj*(*)(TiXmlElement* pElem) > ( “Point”, HPoint::ReadFromXMLElement ) );
xml_read_fn_map.insert( std::pair< std::string, HeeksObj*(*)(TiXmlElement* pElem) > ( “Image”, HImage::ReadFromXMLElement ) );
xml_read_fn_map.insert( std::pair< std::string, HeeksObj*(*)(TiXmlElement* pElem) > ( “Sketch”, CSketch::ReadFromXMLElement ) );
xml_read_fn_map.insert( std::pair< std::string, HeeksObj*(*)(TiXmlElement* pElem) > ( “STEP_file”, ReadSTEPFileFromXMLElement ) );
xml_read_fn_map.insert( std::pair< std::string, HeeksObj*(*)(TiXmlElement* pElem) > ( “STLSolid”, CStlSolid::ReadFromXMLElement ) );
xml_read_fn_map.insert( std::pair< std::string, HeeksObj*(*)(TiXmlElement* pElem) > ( “CoordinateSystem”, CoordinateSystem::ReadFromXMLElement ) );
xml_read_fn_map.insert( std::pair< std::string, HeeksObj*(*)(TiXmlElement* pElem) > ( “Text”, HText::ReadFromXMLElement ) );
xml_read_fn_map.insert( std::pair< std::string, HeeksObj*(*)(TiXmlElement* pElem) > ( “Dimension”, HDimension::ReadFromXMLElement ) );
xml_read_fn_map.insert( std::pair< std::string, HeeksObj*(*)(TiXmlElement* pElem) > ( “Ellipse”, HEllipse::ReadFromXMLElement ) );
xml_read_fn_map.insert( std::pair< std::string, HeeksObj*(*)(TiXmlElement* pElem) > ( “Spline”, HSpline::ReadFromXMLElement ) );
xml_read_fn_map.insert( std::pair< std::string, HeeksObj*(*)(TiXmlElement* pElem) > ( “Group”, CGroup::ReadFromXMLElement ) );
xml_read_fn_map.insert( std::pair< std::string, HeeksObj*(*)(TiXmlElement* pElem) > ( “Constraint”, Constraint::ReadFromXMLElement ) );
xml_read_fn_map.insert( std::pair< std::string, HeeksObj*(*)(TiXmlElement* pElem) > ( “OrientationModifier”, COrientationModifier::ReadFromXMLElement ) );
}
}

So… What I think is going on here, is when I hit this line of code

object = (*(FindIt->second))(pElem);

It fires the appropriate constructor, which creates the object, which returns the address of the heekobj.. which gets returned… Darn clever..  Time to step into this to see if what I think is going on is what is going on..  That is exactly whats going on….. Cool.  There is some nuance that I’m not quite getting, but I feel I can start marching forward…

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *