Hint: Debugging / Accessing osgEarth private members

classic Classic list List threaded Threaded
1 message Options
remoe remoe
Reply | Threaded
Open this post in threaded view
|

Hint: Debugging / Accessing osgEarth private members

This post was updated on .
Hi folks

Sometimes it is useful to access private members of osgEarth for debugging purpose. The following is based on http://bloglitb.blogspot.com/2011/12/access-to-private-members-safer.html

Attention: this is a bad practice! Use it only for debugging purpose :)

Here is a sample to access private members of FeatureModelGraph:

template<typename Tag, typename Tag::type M>
struct Rob {
	friend typename Tag::type get(Tag) {
		return M;
	}
};

template<typename Tag, typename Member>
struct TagBase {
	typedef Member type;
	friend type get(Tag);
};

struct FeatureModelGraph_f : TagBase<FeatureModelGraph_f, Util::StringSet FeatureModelGraph::*> { };
struct FeatureModelGraph_getBoundInWorldCoords : TagBase<FeatureModelGraph_getBoundInWorldCoords, osg::BoundingSphered (FeatureModelGraph::*)(const GeoExtent& extent, const Profile* tilingProfile) const > { };

template struct Rob< FeatureModelGraph_f, &FeatureModelGraph::_blacklist >;
template struct Rob< FeatureModelGraph_getBoundInWorldCoords, &FeatureModelGraph::getBoundInWorldCoords >;

FeatureModelGraph* fmg = findTopMostNodeOfType<FeatureModelGraph>(layer->getNode());
if (fmg) {
  osgEarth::StringSet& blacklist = fmg->*get(FeatureModelGraph_f());
  osg::BoundingSphered tileBound = (fmg->*get(FeatureModelGraph_getBoundInWorldCoords()))(e, 0L);
}

Remo Eichenberger, Switzerland