From 0811e7c3501e72411d98b6bb2c807a5bdade4c99 Mon Sep 17 00:00:00 2001 From: Hleb Valoshka <375gnu@gmail.com> Date: Mon, 6 Jul 2020 20:48:58 +0300 Subject: [PATCH] Remove make_shared and make_unique to keep single style --- src/celcompat/fs.cpp | 4 ++-- src/celcompat/memory.h | 14 -------------- src/celengine/frametree.cpp | 13 +++---------- src/celengine/frametree.h | 2 +- src/celengine/observer.cpp | 21 +++++++++++---------- src/celengine/parseobject.cpp | 24 +++++++++++++----------- src/celengine/render.cpp | 5 +++-- src/celengine/renderglsl.cpp | 2 +- src/celengine/solarsys.cpp | 2 +- src/celengine/timelinephase.cpp | 16 ++++++++-------- src/celestia/celestiacore.cpp | 7 +++---- src/celestia/sdl/sdlmain.cpp | 4 ++-- src/celscript/legacy/legacyscript.cpp | 7 +++---- src/celscript/lua/celx_observer.cpp | 2 +- src/celscript/lua/luascript.cpp | 7 +++---- 15 files changed, 55 insertions(+), 75 deletions(-) delete mode 100644 src/celcompat/memory.h diff --git a/src/celcompat/fs.cpp b/src/celcompat/fs.cpp index f86ea85f0..8982da930 100644 --- a/src/celcompat/fs.cpp +++ b/src/celcompat/fs.cpp @@ -206,7 +206,7 @@ directory_iterator::directory_iterator(const path& p) : directory_iterator::directory_iterator(const path& p, std::error_code& ec) : m_path(p), m_ec(ec), - m_search(std::make_shared(p)) + m_search(new SearchImpl(p)) { if (!m_search->advance(m_entry)) reset(); @@ -239,7 +239,7 @@ struct recursive_directory_iterator::DirStack recursive_directory_iterator::recursive_directory_iterator(const path& p) { if (m_dirs == nullptr) - m_dirs = std::make_shared(); + m_dirs = std::shared_ptr(new DirStack); m_iter = directory_iterator(p); } diff --git a/src/celcompat/memory.h b/src/celcompat/memory.h deleted file mode 100644 index 65f3843b1..000000000 --- a/src/celcompat/memory.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include - -#if !defined(_MSC_VER) && __cplusplus < 201402L -namespace std -{ -template -std::unique_ptr make_unique(Args&&... args) -{ - return std::unique_ptr(new T(std::forward(args)...)); -} -} -#endif diff --git a/src/celengine/frametree.cpp b/src/celengine/frametree.cpp index b3ab71ace..1fa2bbde1 100644 --- a/src/celengine/frametree.cpp +++ b/src/celengine/frametree.cpp @@ -49,11 +49,10 @@ FrameTree::FrameTree(Star* star) : starParent(star), bodyParent(nullptr), m_changed(true), - defaultFrame(nullptr) -{ // Default frame for a star is J2000 ecliptical, centered // on the star. - defaultFrame = make_shared(Selection(star)); + defaultFrame(new J2000EclipticFrame(Selection(star))) +{ } @@ -63,14 +62,8 @@ FrameTree::FrameTree(Body* body) : starParent(nullptr), bodyParent(body), m_changed(true), - defaultFrame(nullptr) -{ // Default frame for a solar system body is the mean equatorial frame of the body. - defaultFrame = make_shared(Selection(body), Selection(body)); -} - - -FrameTree::~FrameTree() + defaultFrame(new BodyMeanEquatorFrame(Selection(body), Selection(body))) { } diff --git a/src/celengine/frametree.h b/src/celengine/frametree.h index d3513767c..906bbd6eb 100644 --- a/src/celengine/frametree.h +++ b/src/celengine/frametree.h @@ -27,7 +27,7 @@ class FrameTree public: FrameTree(Star*); FrameTree(Body*); - ~FrameTree(); + ~FrameTree() = default; /*! Return the star that this tree is associated with; it will be * nullptr for frame trees associated with solar system bodies. diff --git a/src/celengine/observer.cpp b/src/celengine/observer.cpp index 5053f4bfb..747fca801 100644 --- a/src/celengine/observer.cpp +++ b/src/celengine/observer.cpp @@ -56,7 +56,8 @@ static Vector3d slerp(double t, const Vector3d& v0, const Vector3d& v1) * updates due to an active goto operation. */ -Observer::Observer() : frame(make_shared()) +Observer::Observer() : + frame(new ObserverFrame) { updateUniversal(); } @@ -768,7 +769,7 @@ void Observer::convertFrameCoordinates(const ObserverFrame::SharedConstPtr &newF */ void Observer::setFrame(ObserverFrame::CoordinateSystem cs, const Selection& refObj, const Selection& targetObj) { - auto newFrame = make_shared(cs, refObj, targetObj); + auto newFrame = shared_ptr(new ObserverFrame(cs, refObj, targetObj)); convertFrameCoordinates(newFrame); frame = newFrame; } @@ -1509,16 +1510,16 @@ ObserverFrame::createFrame(CoordinateSystem _coordSys, switch (_coordSys) { case Universal: - return make_shared(Selection()); + return shared_ptr(new J2000EclipticFrame(Selection())); case Ecliptical: - return make_shared(_refObject); + return shared_ptr(new J2000EclipticFrame(_refObject)); case Equatorial: - return make_shared(_refObject, _refObject); + return shared_ptr(new BodyMeanEquatorFrame(_refObject, _refObject)); case BodyFixed: - return make_shared(_refObject, _refObject); + return shared_ptr(new BodyFixedFrame(_refObject, _refObject)); case PhaseLock: { @@ -1537,7 +1538,7 @@ ObserverFrame::createFrame(CoordinateSystem _coordSys, case PhaseLock_Old: { FrameVector rotAxis(FrameVector::createConstantVector(Vector3d::UnitY(), - make_shared(_refObject, _refObject))); + shared_ptr(new BodyMeanEquatorFrame(_refObject, _refObject)))); return shared_ptr(new TwoVectorFrame(_refObject, FrameVector::createRelativePositionVector(_refObject, _targetObject), 3, rotAxis, 2)); @@ -1546,7 +1547,7 @@ ObserverFrame::createFrame(CoordinateSystem _coordSys, case Chase_Old: { FrameVector rotAxis(FrameVector::createConstantVector(Vector3d::UnitY(), - make_shared(_refObject, _refObject))); + shared_ptr(new BodyMeanEquatorFrame(_refObject, _refObject)))); return shared_ptr(new TwoVectorFrame(_refObject, FrameVector::createRelativeVelocityVector(_refObject.parent(), _refObject), 3, @@ -1556,10 +1557,10 @@ ObserverFrame::createFrame(CoordinateSystem _coordSys, case ObserverLocal: // TODO: This is only used for computing up vectors for orientation; it does // define a proper frame for the observer position orientation. - return make_shared(Selection()); + return shared_ptr(new J2000EclipticFrame(Selection())); default: - return make_shared(_refObject); + return shared_ptr(new J2000EclipticFrame(_refObject)); } } diff --git a/src/celengine/parseobject.cpp b/src/celengine/parseobject.cpp index 3648496fa..5fdb73e9e 100644 --- a/src/celengine/parseobject.cpp +++ b/src/celengine/parseobject.cpp @@ -1316,7 +1316,7 @@ CreateBodyFixedFrame(const Universe& universe, if (center.empty()) return nullptr; - return make_shared(center, center); + return shared_ptr(new BodyFixedFrame(center, center)); } @@ -1344,14 +1344,16 @@ CreateMeanEquatorFrame(const Universe& universe, clog << "CreateMeanEquatorFrame " << center.getName() << ", " << obj.getName() << "\n"; double freezeEpoch = 0.0; + BodyMeanEquatorFrame *ptr; if (ParseDate(frameData, "Freeze", freezeEpoch)) { - return make_shared(center, obj, freezeEpoch); + ptr = new BodyMeanEquatorFrame(center, obj, freezeEpoch); } else { - return make_shared(center, obj); + ptr = new BodyMeanEquatorFrame(center, obj); } + return shared_ptr(ptr); } @@ -1623,15 +1625,15 @@ CreateTwoVectorFrame(const Universe& universe, center, secondaryData); - shared_ptr frame; + TwoVectorFrame *frame = nullptr; if (primaryVector != nullptr && secondaryVector != nullptr) { - frame = shared_ptr(new TwoVectorFrame(center, - *primaryVector, primaryAxis, - *secondaryVector, secondaryAxis)); + frame = new TwoVectorFrame(center, + *primaryVector, primaryAxis, + *secondaryVector, secondaryAxis); } - return frame; + return shared_ptr(frame); } @@ -1645,7 +1647,7 @@ CreateJ2000EclipticFrame(const Universe& universe, if (center.empty()) return nullptr; - return make_shared(center); + return shared_ptr(new J2000EclipticFrame(center)); } @@ -1659,7 +1661,7 @@ CreateJ2000EquatorFrame(const Universe& universe, if (center.empty()) return nullptr; - return make_shared(center); + return shared_ptr(new J2000EquatorFrame(center)); } @@ -1672,7 +1674,7 @@ CreateTopocentricFrame(const Selection& center, const Selection& target, const Selection& observer) { - shared_ptr eqFrame = make_shared(target, target); + auto eqFrame = shared_ptr(new BodyMeanEquatorFrame(target, target)); FrameVector north = FrameVector::createConstantVector(Vector3d::UnitY(), eqFrame); FrameVector up = FrameVector::createRelativePositionVector(observer, target); diff --git a/src/celengine/render.cpp b/src/celengine/render.cpp index 1eb89a746..54cedecd5 100644 --- a/src/celengine/render.cpp +++ b/src/celengine/render.cpp @@ -65,7 +65,6 @@ std::ofstream hdrlog; #include "boundariesrenderer.h" #include "rendcontext.h" #include "vertexobject.h" -#include #include #include #include @@ -5451,7 +5450,9 @@ Renderer::getShadowFBO(int index) const void Renderer::createShadowFBO() { - m_shadowFBO = make_unique(m_shadowMapSize, m_shadowMapSize, FramebufferObject::DepthAttachment); + m_shadowFBO = unique_ptr(new FramebufferObject(m_shadowMapSize, + m_shadowMapSize, + FramebufferObject::DepthAttachment)); if (!m_shadowFBO->isValid()) { clog << "Error creating shadow FBO.\n"; diff --git a/src/celengine/renderglsl.cpp b/src/celengine/renderglsl.cpp index 662902241..f28d3f11c 100644 --- a/src/celengine/renderglsl.cpp +++ b/src/celengine/renderglsl.cpp @@ -868,7 +868,7 @@ void renderRings_GLSL(RingSystem& rings, ringsTex->bind(); if (rings.renderData == nullptr) - rings.renderData = make_shared(); + rings.renderData = shared_ptr(new GLRingRenderData); auto data = reinterpret_cast(rings.renderData.get()); unsigned nSections = 180; diff --git a/src/celengine/solarsys.cpp b/src/celengine/solarsys.cpp index 879ac3186..648cbc25b 100644 --- a/src/celengine/solarsys.cpp +++ b/src/celengine/solarsys.cpp @@ -454,7 +454,7 @@ static bool CreateTimeline(Body* body, ReferenceFrame::SharedConstPtr defaultBodyFrame; if (bodyType == SurfaceObject) { - defaultOrbitFrame = make_shared(parentObject, parentObject); + defaultOrbitFrame = shared_ptr(new BodyFixedFrame(parentObject, parentObject)); defaultBodyFrame = CreateTopocentricFrame(parentObject, parentObject, Selection(body)); } else diff --git a/src/celengine/timelinephase.cpp b/src/celengine/timelinephase.cpp index 64d0264dd..6107b9648 100644 --- a/src/celengine/timelinephase.cpp +++ b/src/celengine/timelinephase.cpp @@ -80,14 +80,14 @@ TimelinePhase::CreateTimelinePhase(Universe& universe, return nullptr; } - auto phase = make_shared(body, - startTime, - endTime, - orbitFrame, - &orbit, - bodyFrame, - &rotationModel, - frameTree); + auto phase = shared_ptr(new TimelinePhase(body, + startTime, + endTime, + orbitFrame, + &orbit, + bodyFrame, + &rotationModel, + frameTree)); frameTree->addChild(phase); diff --git a/src/celestia/celestiacore.cpp b/src/celestia/celestiacore.cpp index 3b4ce59c6..e290fb0c9 100644 --- a/src/celestia/celestiacore.cpp +++ b/src/celestia/celestiacore.cpp @@ -38,7 +38,6 @@ #include #include #include -#include #include #include #include @@ -142,11 +141,11 @@ CelestiaCore::CelestiaCore() : routine will be called much later. */ renderer(new Renderer()), timer(new Timer()), - m_legacyPlugin(make_unique(this)), + m_legacyPlugin(new LegacyScriptPlugin(this)), #ifdef CELX - m_luaPlugin(make_unique(this)), + m_luaPlugin(new LuaScriptPlugin(this)), #endif - m_scriptMaps(make_shared()), + m_scriptMaps(new ScriptMaps()), oldFOV(stdFOV) { diff --git a/src/celestia/sdl/sdlmain.cpp b/src/celestia/sdl/sdlmain.cpp index 0b2938972..34214268a 100644 --- a/src/celestia/sdl/sdlmain.cpp +++ b/src/celestia/sdl/sdlmain.cpp @@ -95,7 +95,7 @@ SDL_Application::init(const std::string name, int w, int h) SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); #endif - return std::make_shared(std::move(name), w, h); + return std::shared_ptr(new SDL_Application(std::move(name), w, h)); } SDL_Application::~SDL_Application() @@ -329,7 +329,7 @@ SDL_Application::handleKeyReleaseEvent(const SDL_KeyboardEvent &event) } if ((event.keysym.mod & KMOD_SHIFT) != 0) mod |= CelestiaCore::ShiftKey; - + m_appCore->keyUp(key, 0); } } diff --git a/src/celscript/legacy/legacyscript.cpp b/src/celscript/legacy/legacyscript.cpp index 343c38fb2..b765899c5 100644 --- a/src/celscript/legacy/legacyscript.cpp +++ b/src/celscript/legacy/legacyscript.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include "legacyscript.h" @@ -60,7 +59,7 @@ public: LegacyScript::LegacyScript(CelestiaCore *core) : m_appCore(core), - m_execEnv(make_unique(*core)) + m_execEnv(new CoreExecutionEnvironment(*core)) { } @@ -75,7 +74,7 @@ bool LegacyScript::load(ifstream &scriptfile, const fs::path &/*path*/, string & errorMsg = (*errors)[0]; return false; } - m_runningScript = make_unique(*script, *m_execEnv); + m_runningScript = unique_ptr(new Execution(*script, *m_execEnv)); return true; } @@ -98,7 +97,7 @@ unique_ptr LegacyScriptPlugin::loadScript(const fs::path &path) return nullptr; } - auto script = make_unique(appCore()); + auto script = unique_ptr(new LegacyScript(appCore())); string errorMsg; if (!script->load(scriptfile, path, errorMsg)) { diff --git a/src/celscript/lua/celx_observer.cpp b/src/celscript/lua/celx_observer.cpp index ce4054e01..034eb4347 100644 --- a/src/celscript/lua/celx_observer.cpp +++ b/src/celscript/lua/celx_observer.cpp @@ -716,7 +716,7 @@ static int observer_setframe(lua_State* l) frame = celx.toFrame(2); if (frame != nullptr) { - obs->setFrame(make_shared(*frame)); + obs->setFrame(std::shared_ptr(new ObserverFrame(*frame))); } else { diff --git a/src/celscript/lua/luascript.cpp b/src/celscript/lua/luascript.cpp index 7eaf2f020..1233f28ca 100644 --- a/src/celscript/lua/luascript.cpp +++ b/src/celscript/lua/luascript.cpp @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -29,7 +28,7 @@ namespace scripts LuaScript::LuaScript(CelestiaCore *appcore) : m_appCore(appcore), - m_celxScript(make_unique()) + m_celxScript(new LuaState) { m_celxScript->init(m_appCore); } @@ -89,7 +88,7 @@ unique_ptr LuaScriptPlugin::loadScript(const fs::path &path) return nullptr; } - auto script = make_unique(appCore()); + auto script = unique_ptr(new LuaScript(appCore())); string errMsg; if (!script->load(scriptfile, path, errMsg)) { @@ -238,7 +237,7 @@ bool CreateLuaEnvironment(CelestiaCore *appCore, const CelestiaConfig *config, P if (luaHook != nullptr) { - auto lh = make_unique(appCore); + auto lh = unique_ptr(new LuaHook(appCore)); lh->m_state = unique_ptr(luaHook); appCore->setScriptHook(std::move(lh));