Skip to content

Commit

Permalink
Replace fwd decl of json with wrapper type
Browse files Browse the repository at this point in the history
Since nlohmann/json#3590, the basic_json class
and the json using-declaration are located in a "versioned, ABI-tagged
inline namespace". This makes it impossible to forward declare the type
in REveElement.hxx.
Instead introduce a new struct REveJsonWrapper that just wraps a json
object (after including the full nlohmann/json.hpp). As the struct is
under our control, we can easily forward declare the type and use it
for method arguments.
  • Loading branch information
hahnjo committed Aug 16, 2022
1 parent 2c97479 commit fb0f5a8
Show file tree
Hide file tree
Showing 48 changed files with 144 additions and 92 deletions.
4 changes: 2 additions & 2 deletions graf3d/eve7/inc/ROOT/REveBox.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public:
// For TAttBBox:
virtual void ComputeBBox() override;

Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override;
Int_t WriteCoreJson(Internal::REveJsonWrapper &j, Int_t rnr_offset) override;
void BuildRenderData() override;
// Projectable:
virtual TClass* ProjectedClass(const REveProjection* p) const override;
Expand Down Expand Up @@ -76,7 +76,7 @@ public:
virtual ~REveBoxProjected();

void BuildRenderData() override;
Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override;
Int_t WriteCoreJson(Internal::REveJsonWrapper &j, Int_t rnr_offset) override;

// For TAttBBox:
void ComputeBBox() override;
Expand Down
2 changes: 1 addition & 1 deletion graf3d/eve7/inc/ROOT/REveBoxSet.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public:
void SetBoxSkip(Int_t bs) { fBoxSkip = bs; }


Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override;
Int_t WriteCoreJson(Internal::REveJsonWrapper &j, Int_t rnr_offset) override;
void BuildRenderData() override;
};

Expand Down
12 changes: 6 additions & 6 deletions graf3d/eve7/inc/ROOT/REveCalo.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ public:

Bool_t CellInEtaPhiRng (REveCaloData::CellData_t&) const;

Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override;
virtual void WriteCoreJsonSelection(nlohmann::json &j, REveCaloData::vCellId_t) = 0;
Int_t WriteCoreJson(Internal::REveJsonWrapper &j, Int_t rnr_offset) override;
virtual void WriteCoreJsonSelection(Internal::REveJsonWrapper &j, REveCaloData::vCellId_t) = 0;
};

/**************************************************************************/
Expand Down Expand Up @@ -177,8 +177,8 @@ public:
virtual ~REveCalo3D() {}
void ComputeBBox() override;

Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override;
void WriteCoreJsonSelection(nlohmann::json &j, REveCaloData::vCellId_t) override;
Int_t WriteCoreJson(Internal::REveJsonWrapper &j, Int_t rnr_offset) override;
void WriteCoreJsonSelection(Internal::REveJsonWrapper &j, REveCaloData::vCellId_t) override;
void BuildRenderData() override;

void SetFrameWidth(Float_t w) { fFrameWidth = w; }
Expand Down Expand Up @@ -249,8 +249,8 @@ public:

Float_t GetValToHeight() const override;

Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override;
void WriteCoreJsonSelection(nlohmann::json &j, REveCaloData::vCellId_t) override;
Int_t WriteCoreJson(Internal::REveJsonWrapper &j, Int_t rnr_offset) override;
void WriteCoreJsonSelection(Internal::REveJsonWrapper &j, REveCaloData::vCellId_t) override;
void BuildRenderData() override;

void NewBinPicked(Int_t bin, Int_t slice, Int_t selectionId, Bool_t multi);
Expand Down
4 changes: 2 additions & 2 deletions graf3d/eve7/inc/ROOT/REveCaloData.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,12 @@ public:
void SetSelector(REveCaloDataSelector* iSelector) { fSelector.reset(iSelector); }
REveCaloDataSelector* GetSelector() { return fSelector.get(); }

Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override;
Int_t WriteCoreJson(Internal::REveJsonWrapper &j, Int_t rnr_offset) override;

static Float_t EtaToTheta(Float_t eta);

bool RequiresExtraSelectionData() const override { return true; };
void FillExtraSelectionData(nlohmann::json&, const std::set<int>&) const override;
void FillExtraSelectionData(Internal::REveJsonWrapper&, const std::set<int>&) const override;

using REveElement::GetHighlightTooltip;
std::string GetHighlightTooltip(const std::set<int>& secondary_idcs) const override;
Expand Down
6 changes: 3 additions & 3 deletions graf3d/eve7/inc/ROOT/REveDataCollection.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private:
public:
REveDataItemList(const std::string& n = "Items", const std::string& t = "");
virtual ~REveDataItemList() {}
Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset) override;
Int_t WriteCoreJson(Internal::REveJsonWrapper &cj, Int_t rnr_offset) override;

virtual void ItemChanged(REveDataItem *item);
virtual void ItemChanged(Int_t idx);
Expand Down Expand Up @@ -151,8 +151,8 @@ public:
void *GetDataPtr(Int_t i) const { return fItemList->fItems[i]->GetDataPtr(); }
const REveDataItem* GetDataItem(Int_t i) const { return fItemList->fItems[i]; }

void StreamPublicMethods(nlohmann::json &cj) const;
Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset) override;
void StreamPublicMethods(Internal::REveJsonWrapper &cj) const;
Int_t WriteCoreJson(Internal::REveJsonWrapper &cj, Int_t rnr_offset) override;

void SetMainColor(Color_t) override;

Expand Down
2 changes: 1 addition & 1 deletion graf3d/eve7/inc/ROOT/REveDataTable.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public:
const REveDataCollection *GetCollection() const { return fCollection; }

void PrintTable();
virtual Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset);
virtual Int_t WriteCoreJson(Internal::REveJsonWrapper &cj, Int_t rnr_offset);

void AddNewColumn(const std::string& expr, const std::string& title, int prec = 2);
};
Expand Down
4 changes: 2 additions & 2 deletions graf3d/eve7/inc/ROOT/REveDigitSet.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ public:


bool RequiresExtraSelectionData() const override { return true; };
void FillExtraSelectionData(nlohmann::json& j, const std::set<int>& secondary_idcs) const override;
void FillExtraSelectionData(Internal::REveJsonWrapper& j, const std::set<int>& secondary_idcs) const override;

Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override;
Int_t WriteCoreJson(Internal::REveJsonWrapper &j, Int_t rnr_offset) override;
};

} // namespace Experimental
Expand Down
23 changes: 6 additions & 17 deletions graf3d/eve7/inc/ROOT/REveElement.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,6 @@

class TGeoMatrix;

namespace nlohmann {
template<typename T, typename SFINAE>
struct adl_serializer;

template <template <typename U, typename V, typename... Args> class ObjectType,
template <typename U, typename... Args> class ArrayType, class StringType, class BooleanType,
class NumberIntegerType, class NumberUnsignedType, class NumberFloatType,
template <typename U> class AllocatorType, template <typename T, typename SFINAE = void> class JSONSerializer,
class BinaryType>
class basic_json;

using json = basic_json<std::map, std::vector, std::string, bool, std::int64_t, std::uint64_t, double, std::allocator,
adl_serializer, std::vector<std::uint8_t>>;
} // namespace nlohmann

namespace ROOT {
namespace Experimental {

Expand All @@ -45,6 +30,10 @@ class REveCompound;
class REveTrans;
class REveRenderData;

namespace Internal {
struct REveJsonWrapper;
}

//==============================================================================
// REveElement
// Base class for ROOT Event Visualization Environment (EVE)
Expand Down Expand Up @@ -264,7 +253,7 @@ public:
virtual void SetTransMatrix(Double_t *carr);
virtual void SetTransMatrix(const TGeoMatrix &mat);

virtual Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset);
virtual Int_t WriteCoreJson(Internal::REveJsonWrapper &cj, Int_t rnr_offset);
virtual void BuildRenderData();

void* GetUserData() const { return fUserData; }
Expand Down Expand Up @@ -328,7 +317,7 @@ public:
void CSCApplyMainTransparencyToMatchingChildren() { fCSCBits |= kCSCBApplyMainTransparencyToMatchingChildren; }

virtual bool RequiresExtraSelectionData() const { return false; }
virtual void FillExtraSelectionData(nlohmann::json&, const std::set<int>&) const {}
virtual void FillExtraSelectionData(Internal::REveJsonWrapper&, const std::set<int>&) const {}

// Change-stamping and change bits
//---------------------------------
Expand Down
4 changes: 2 additions & 2 deletions graf3d/eve7/inc/ROOT/REveEllipsoid.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public:
void SetBaseVectors(REveVector& v0, REveVector& v1, REveVector& v3);
void SetPhiStep(float ps);

Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override;
Int_t WriteCoreJson(Internal::REveJsonWrapper &j, Int_t rnr_offset) override;

TClass *ProjectedClass(const REveProjection *p) const override;
};
Expand Down Expand Up @@ -78,7 +78,7 @@ public:

void BuildRenderData() override;

Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override;
Int_t WriteCoreJson(Internal::REveJsonWrapper &j, Int_t rnr_offset) override;

virtual void OutlineProjected();
virtual void SetProjection(REveProjectionManager *mng, REveProjectable *model) override;
Expand Down
2 changes: 1 addition & 1 deletion graf3d/eve7/inc/ROOT/REveGeoShape.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public:
REveGeoShape(const std::string &name = "REveGeoShape", const std::string &title = "");
virtual ~REveGeoShape();

Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override;
Int_t WriteCoreJson(Internal::REveJsonWrapper &j, Int_t rnr_offset) override;
void BuildRenderData() override;

Int_t GetNSegments() const { return fNSegments; }
Expand Down
2 changes: 1 addition & 1 deletion graf3d/eve7/inc/ROOT/REveJetCone.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public:
REveJetCone(const Text_t *n = "REveJetCone", const Text_t *t = "");
virtual ~REveJetCone() {}

Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override;
Int_t WriteCoreJson(Internal::REveJsonWrapper &j, Int_t rnr_offset) override;
void BuildRenderData() override;

void ComputeBBox() override;
Expand Down
2 changes: 1 addition & 1 deletion graf3d/eve7/inc/ROOT/REveLine.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public:

TClass *ProjectedClass(const REveProjection *p) const override;

Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset) override;
Int_t WriteCoreJson(Internal::REveJsonWrapper &cj, Int_t rnr_offset) override;
void BuildRenderData() override;

static Bool_t GetDefaultSmooth();
Expand Down
2 changes: 1 addition & 1 deletion graf3d/eve7/inc/ROOT/REvePointSet.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public:

TClass* ProjectedClass(const REveProjection *p) const override;

Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override;
Int_t WriteCoreJson(Internal::REveJsonWrapper &j, Int_t rnr_offset) override;
void BuildRenderData()override;

void ComputeBBox() override;
Expand Down
2 changes: 1 addition & 1 deletion graf3d/eve7/inc/ROOT/REvePolygonSetProjected.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public:
virtual void DumpPolys() const;
void DumpBuffer3D();

Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override;
Int_t WriteCoreJson(Internal::REveJsonWrapper &j, Int_t rnr_offset) override;
void BuildRenderData() override;
};

Expand Down
2 changes: 1 addition & 1 deletion graf3d/eve7/inc/ROOT/REveScene.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public:
void ProcessChanges();

void StreamElements();
void StreamJsonRecurse(REveElement *el, nlohmann::json &jobj);
void StreamJsonRecurse(REveElement *el, Internal::REveJsonWrapper &jobj);

// void Repaint(Bool_t dropLogicals=kFALSE);
// void RetransHierarchically();
Expand Down
2 changes: 1 addition & 1 deletion graf3d/eve7/inc/ROOT/REveSceneInfo.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public:
REveSceneInfo(REveViewer *viewer, REveScene *scene);
virtual ~REveSceneInfo() {}

Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override;
Int_t WriteCoreJson(Internal::REveJsonWrapper &j, Int_t rnr_offset) override;

REveViewer *GetViewer() const { return fViewer; }
REveScene *GetScene() const { return fScene; }
Expand Down
2 changes: 1 addition & 1 deletion graf3d/eve7/inc/ROOT/REveSelection.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public:

// ----------------------------------------------------------------

Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset) override;
Int_t WriteCoreJson(Internal::REveJsonWrapper &cj, Int_t rnr_offset) override;

};

Expand Down
2 changes: 1 addition & 1 deletion graf3d/eve7/inc/ROOT/REveShape.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public:
REveShape(const std::string &n = "REveShape", const std::string &t = "");
virtual ~REveShape();

Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override;
Int_t WriteCoreJson(Internal::REveJsonWrapper &j, Int_t rnr_offset) override;

// Rendering parameters.
void SetMainColor(Color_t color) override;
Expand Down
2 changes: 1 addition & 1 deletion graf3d/eve7/inc/ROOT/REveStraightLineSet.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public:

TClass* ProjectedClass(const REveProjection* p) const override;

Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override;
Int_t WriteCoreJson(Internal::REveJsonWrapper &j, Int_t rnr_offset) override;
void BuildRenderData() override;

void ComputeBBox() override;
Expand Down
2 changes: 1 addition & 1 deletion graf3d/eve7/inc/ROOT/REveTableInfo.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public:

void AddDelegate(Delegate_t d) { fDelegates.push_back(d); }

Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override;
Int_t WriteCoreJson(Internal::REveJsonWrapper &j, Int_t rnr_offset) override;

// read
REveTableHandle::Entries_t &RefTableEntries(std::string cname);
Expand Down
2 changes: 1 addition & 1 deletion graf3d/eve7/inc/ROOT/REveTrack.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public:

TClass *ProjectedClass(const REveProjection *p) const override;

Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset) override;
Int_t WriteCoreJson(Internal::REveJsonWrapper &cj, Int_t rnr_offset) override;
void BuildRenderData() override;
};

Expand Down
2 changes: 1 addition & 1 deletion graf3d/eve7/inc/ROOT/REveTrackProjected.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public:

void SecSelected(REveTrack *) override; // marked as signal in REveTrack

Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset) override;
Int_t WriteCoreJson(Internal::REveJsonWrapper &cj, Int_t rnr_offset) override;
void BuildRenderData() override;
};

Expand Down
2 changes: 1 addition & 1 deletion graf3d/eve7/inc/ROOT/REveViewer.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public:

void RemoveElementLocal(REveElement *el) override;
void RemoveElementsLocal() override;
Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset) override;
Int_t WriteCoreJson(Internal::REveJsonWrapper &cj, Int_t rnr_offset) override;
};


Expand Down
5 changes: 3 additions & 2 deletions graf3d/eve7/src/REveBox.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#include "TClass.h"

#include "REveJsonWrapper.hxx"
#include <nlohmann/json.hpp>

using namespace ROOT::Experimental;
Expand Down Expand Up @@ -99,7 +100,7 @@ void REveBox::ComputeBBox()
////////////////////////////////////////////////////////////////////////////////
/// Fill core part of JSON representation.

Int_t REveBox::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
Int_t REveBox::WriteCoreJson(Internal::REveJsonWrapper &j, Int_t rnr_offset)
{
Int_t ret = REveElement::WriteCoreJson(j, rnr_offset);

Expand Down Expand Up @@ -276,7 +277,7 @@ void REveBoxProjected::BuildRenderData()
////////////////////////////////////////////////////////////////////////////////
/// Fill core part of JSON representation.

Int_t REveBoxProjected::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
Int_t REveBoxProjected::WriteCoreJson(Internal::REveJsonWrapper &j, Int_t rnr_offset)
{
Int_t ret = REveShape::WriteCoreJson(j, rnr_offset);

Expand Down
3 changes: 2 additions & 1 deletion graf3d/eve7/src/REveBoxSet.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "TRandom.h"
#include <cassert>

#include "REveJsonWrapper.hxx"
#include <nlohmann/json.hpp>

using namespace::ROOT::Experimental;
Expand Down Expand Up @@ -333,7 +334,7 @@ void REveBoxSet::ComputeBBox()
////////////////////////////////////////////////////////////////////////////////
/// Fill core part of JSON representation.

Int_t REveBoxSet::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
Int_t REveBoxSet::WriteCoreJson(Internal::REveJsonWrapper &j, Int_t rnr_offset)
{
Int_t ret = REveDigitSet::WriteCoreJson(j, rnr_offset);
j["boxType"] = int(fBoxType);
Expand Down
Loading

0 comments on commit fb0f5a8

Please sign in to comment.