Skip to content

Commit

Permalink
Merge pull request #1452 from dgelessus/plfactory_unprivate
Browse files Browse the repository at this point in the history
Fix ODR violation for `plFactory` and avoid including it everywhere
  • Loading branch information
Hoikas authored Aug 8, 2023
2 parents 47126dc + 393ca19 commit 2df0f46
Show file tree
Hide file tree
Showing 26 changed files with 32 additions and 24 deletions.
1 change: 1 addition & 0 deletions Sources/Plasma/Apps/plPageInfo/plPageInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com

#include <string_theory/format>

#include "pnFactory/plFactory.h"
#include "pnKeyedObject/plKeyImp.h"

#include "plAgeDescription/plAgeManifest.h"
Expand Down
1 change: 1 addition & 0 deletions Sources/Plasma/FeatureLib/pfConsole/pfConsoleCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "pfConsole.h"
#include "pfDispatchLog.h"

#include "pnFactory/plFactory.h"
#include "pnInputCore/plKeyMap.h"
#include "pnKeyedObject/plFixedKey.h"
#include "pnKeyedObject/plKey.h"
Expand Down
1 change: 1 addition & 0 deletions Sources/Plasma/FeatureLib/pfConsole/pfDispatchLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include <string_theory/format>
#include <string_theory/string>

#include "pnFactory/plFactory.h"
#include "pnKeyedObject/plKey.h"
#include "pnKeyedObject/hsKeyedObject.h"
#include "pnMessage/plClientMsg.h"
Expand Down
1 change: 1 addition & 0 deletions Sources/Plasma/NucleusLib/pnDispatch/plDispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "HeadSpin.h"
#include "hsResMgr.h"
#include "plDispatch.h"
#include "pnFactory/plFactory.h"
#define PLMESSAGE_PRIVATE
#include "pnMessage/plMessage.h"
#include "pnKeyedObject/hsKeyedObject.h"
Expand Down
17 changes: 5 additions & 12 deletions Sources/Plasma/NucleusLib/pnFactory/plCreatable.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#ifndef plCreatable_inc
#define plCreatable_inc

#include "HeadSpin.h"

#include "hsRefCnt.h"
#include "plFactory.h"

class plCreator;
class hsStream;
Expand Down Expand Up @@ -97,7 +98,6 @@ class plCreatable : public hsRefCnt
// as plClassName, return that, else nullptr. Incs the ref count of the object.
// static plClassName* ConvertNoRef(plCreatable* c) - Same as Convert(), but
// doesn't inc the ref count.
// static plClassName* Create() - returns a new object of type plClassName
// Insert into public section of class definition.
//
// Normally one of the next 3 macros should follow CLASSNAME_REGISTER
Expand All @@ -124,13 +124,13 @@ class plCreatable : public hsRefCnt
//
// USAGE:
// There is a method of identifying an object's type. You should rarely need it,
// using Create() and Convert() instead.
// using Convert() instead.
// ClassIndex() the class handle is an immutable index to this class. It provides an
// instantaneous lookup. It may be stored, loaded, sent over the wire, etc.
//
// Create()
// If you know what type object you want to create at compile time, use
// <ObjectType>::Create()
// new <ObjectType>()
// But if you have a class index at run-time (e.g. loaded from file), use
// plCreatable* plFactory::Create(hClass);
// The ultra-safe way to do this is:
Expand All @@ -139,7 +139,7 @@ class plCreatable : public hsRefCnt
// hsRefCnt_SafeUnRef(tmp);
//
// If you have a fred interface to an object f, and want a wilma interface, use
// fred* f = fred::Create(); more likely f was passed in.
// fred* f = new fred(); more likely f was passed in.
// wilma* w = wilma::Convert(f)
// NOTE that two strange things may be true here:
// 1) f != nullptr, w == nullptr
Expand Down Expand Up @@ -178,10 +178,6 @@ public: \
static uint16_t Index() { \
return plClassName##ClassIndex; \
} \
static plClassName* Create() { \
return static_cast<plClassName*>( \
plFactory::Create(plClassName##ClassIndex)); \
} \
static plClassName* ConvertNoRef(plCreatable* c) { \
plClassName* retVal = c \
? static_cast<plClassName*>( \
Expand All @@ -200,9 +196,6 @@ public: \
plClassName* retVal = ConvertNoRef(c); \
hsRefCnt_SafeRef(retVal); \
return retVal; \
} \
static bool HasDerivedClass(uint16_t hDer) { \
return plFactory::DerivesFrom(plClassName##ClassIndex, hDer); \
}


Expand Down
2 changes: 0 additions & 2 deletions Sources/Plasma/NucleusLib/pnFactory/plCreator.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ class plCreator
return !(std::is_base_of_v<hsKeyedObject, _CreatableT>);
return true;
}

friend class plFactory;
};

#define VERIFY_CREATABLE(plClassName) \
Expand Down
2 changes: 1 addition & 1 deletion Sources/Plasma/NucleusLib/pnFactory/plFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
*==LICENSE==*/

#define PLFACTORY_PRIVATE
#include "plFactory.h"

#include "hsStream.h"
#include "plCreatable.h"
#include "plCreator.h"
Expand Down
8 changes: 2 additions & 6 deletions Sources/Plasma/NucleusLib/pnFactory/plFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com

#include "hsRefCnt.h"
#include "HeadSpin.h"
#ifdef PLFACTORY_PRIVATE
#include <vector>
#endif

#include <vector>

class plCreator;
class plCreatable;
Expand All @@ -56,7 +55,6 @@ class hsResMgr;

class plFactory : public hsRefCnt
{
#ifdef PLFACTORY_PRIVATE
private:
std::vector<plCreator*> fCreators;

Expand All @@ -74,11 +72,9 @@ class plFactory : public hsRefCnt

plFactory();
~plFactory();
#endif

public:
// Don't use this unless you're initializing a DLL
friend class plClient;
static plFactory* GetTheFactory();


Expand Down
4 changes: 4 additions & 0 deletions Sources/Plasma/NucleusLib/pnKeyedObject/plKeyImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plProfile.h"
#include "plgDispatch.h"

#if defined(HS_DEBUGGING) || defined(LOG_ACTIVE_REFS)
#include "pnFactory/plFactory.h"
#endif

plProfile_CreateMemCounter("Keys", "Memory", KeyMem);

static uint32_t CalcKeySize(plKeyImp* key)
Expand Down
1 change: 1 addition & 0 deletions Sources/Plasma/NucleusLib/pnSceneObject/plSceneObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plCoordinateInterface.h"
#include "plAudioInterface.h"
#include "pnDispatch/plDispatch.h"
#include "pnFactory/plFactory.h"
#include "pnModifier/plModifier.h"
#include "pnMessage/plMessage.h"
#include "pnMessage/plRefMsg.h"
Expand Down
1 change: 1 addition & 0 deletions Sources/Plasma/PubUtilLib/plAnimation/plAGAnimInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "hsTimer.h" // just when debugging for GetSysSeconds

// other
#include "pnFactory/plFactory.h"
#include "plInterp/plAnimTimeConvert.h"
#include "pnNetCommon/plSDLTypes.h"
#include "plMessage/plAnimCmdMsg.h"
Expand Down
2 changes: 2 additions & 0 deletions Sources/Plasma/PubUtilLib/plAnimation/plAGApplicator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "hsResMgr.h"
#include "hsStream.h"

#include "pnFactory/plFactory.h"

#include "plAGChannel.h"
#include "plAGModifier.h"

Expand Down
1 change: 1 addition & 0 deletions Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "hsSystemInfo.h"
#include "hsTimer.h"

#include "pnFactory/plFactory.h"
#include "pnMessage/plClientMsg.h"
#include "pnMessage/plPlayerPageMsg.h"
#include "pnMessage/plTimeMsg.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plCreatableIndex.h"
#include "plNetLinkingMgr.h"

#include "pnFactory/plFactory.h"
#include "pnMessage/plMessage.h"
#include "pnNetCommon/plNetApp.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com

#include "pnAsyncCore/pnAsyncCore.h"
#include "pnEncryption/plChallengeHash.h"
#include "pnFactory/plFactory.h"
#include "pnNetBase/pnNbConst.h"
#include "pnNetCli/pnNetCli.h"
#include "pnNetCommon/plNetApp.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plgDispatch.h"
#include "hsStream.h"

#include "pnFactory/plFactory.h"
#include "pnMessage/plNotifyMsg.h"

#include "plNetMessage/plNetMessage.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "hsResMgr.h"
#include "hsStream.h"

#include "pnFactory/plFactory.h"
#include "pnMessage/plNotifyMsg.h"
#include "pnNetCommon/plNetApp.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include <iterator>
#include <string_theory/string>

#include "pnFactory/plFactory.h"
#include "pnNetCommon/plGenericVar.h"
#include "pnNetCommon/plNetApp.h"
#include "pnNetCommon/pnNetCommon.h"
Expand Down
1 change: 1 addition & 0 deletions Sources/Plasma/PubUtilLib/plNetCommon/plNetMsgScreener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plNetMsgScreener.h"
#include "plCreatableIndex.h"

#include "pnFactory/plFactory.h"
#include "pnNetCommon/plNetApp.h"
#include "pnKeyedObject/plKey.h"

Expand Down
2 changes: 1 addition & 1 deletion Sources/Plasma/PubUtilLib/plNetMessage/plNetMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ void plNetMsgGameMessage::WriteVersion(hsStream* s, hsResMgr* mgr)

ST::string plNetMsgGameMessage::AsString() const
{
const char* noc = plFactory::GetTheFactory()->GetNameOfClass(StreamInfo()->GetStreamType());
const char* noc = plFactory::GetNameOfClass(StreamInfo()->GetStreamType());
return ST::format("{} {}", plNetMsgStream::AsString(), noc ? noc : "?");
}

Expand Down
1 change: 1 addition & 0 deletions Sources/Plasma/PubUtilLib/plNetMessage/plNetMsgHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com

#include "hsStream.h"

#include "pnFactory/plFactory.h"
#include "pnKeyedObject/plKey.h"
#include "pnNetCommon/plNetApp.h"

Expand Down
1 change: 0 additions & 1 deletion Sources/Plasma/PubUtilLib/plResMgr/plRegistryNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plRegistryKeyList.h"
#include "plVersion.h"

#include "pnFactory/plFactory.h"
#include "pnKeyedObject/plKeyImp.h"

plRegistryPageNode::plRegistryPageNode(const plFileName& path)
Expand Down
1 change: 1 addition & 0 deletions Sources/Plasma/PubUtilLib/plResMgr/plResManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com

#include "pnDispatch/plDispatch.h"
#include "pnFactory/plCreator.h"
#include "pnFactory/plFactory.h"
#include "pnKeyedObject/hsKeyedObject.h"
#include "pnKeyedObject/plFixedKey.h"
#include "pnKeyedObject/plKeyImp.h"
Expand Down
1 change: 1 addition & 0 deletions Sources/Plasma/PubUtilLib/plSDL/plStateVariable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "hsStream.h"

#include "pnFactory/plCreatable.h"
#include "pnFactory/plFactory.h"
#include "pnNetCommon/plNetApp.h"
#include "pnNetCommon/pnNetCommon.h"

Expand Down
1 change: 0 additions & 1 deletion Sources/Tools/MaxMain/plMaxUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plMaxUtils.h"
#include "plResMgr/plPageInfo.h"
#include "pnKeyedObject/plUoid.h"
#include "pnFactory/plFactory.h"

class MaxUtilsClassDesc : public plMaxClassDesc<ClassDesc>
{
Expand Down
1 change: 1 addition & 0 deletions Sources/Tools/plResBrowser/plResBrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com

#include "pnAllCreatables.h"

#include "pnFactory/plFactory.h"
#include "pnKeyedObject/plKey.h"
#include "pnKeyedObject/plKeyImp.h"
#include "pnKeyedObject/plUoid.h"
Expand Down

0 comments on commit 2df0f46

Please sign in to comment.