Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion smcore/about.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ Version <InsertVersionInfoHere> [InsertBuildInformationHere]
SourceMonitor Team
http://www.github.com/SourceMonitor
© SourceMonitor Team)~~~~";

return aboutText;
}
//******************************************************************************
}
}
18 changes: 14 additions & 4 deletions smcore/factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,29 @@

#include "factory.h"

#include <map>
#include <unordered_map>

namespace smos
{
namespace smcore
{
//******************************************************************************
Options *Factory::getOptions(smos::smcore::SMString optionsfile)
{
static Options *smOptions = nullptr;
if (nullptr == smOptions)
static std::unordered_map<smos::smcore::SMString, Options *> programOptions;
if (programOptions.find(optionsfile) == programOptions.end())
{
smOptions = new Options(optionsfile);
programOptions.insert(std::make_pair(optionsfile, new Options(optionsfile)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we have a similar problem as in line 47 - memory leak. the Options object will never be destroyed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the comments for line 47.

}
return smOptions;
return programOptions[optionsfile];
}
//******************************************************************************
Version *Factory::getVersion(void)
{
static Version smVersion;
return &smVersion;
}
//******************************************************************************
}
}
21 changes: 20 additions & 1 deletion smcore/factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,37 @@

#pragma once

#include "options.h"
#include <memory.h>

#include "options.h"
#include "smstring.h"
#include "version.h"

namespace smos
{
namespace smcore
{
/**
* @brief Factory class to retrieve specific objects from
*/
class Factory
{
public:
/**
* @brief Get the options object
*
* @param optionsfile Name of options file
*
* @return Options* Pointer to options object
*/
static Options *getOptions(smos::smcore::SMString optionsfile);

/**
* @brief Get the version object
*
* @return Version* Pointer to version object
*/
static Version *getVersion(void);
};
}
}
1 change: 1 addition & 0 deletions smcore/license.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@ DEALINGS IN THE SOFTWARE.
)~~~~";
return licenseText;
}
//******************************************************************************
}
}
1 change: 1 addition & 0 deletions smcore/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,6 @@ namespace smos
{
this->m_logfileName = logfileName;
}
//******************************************************************************
}
}
3 changes: 2 additions & 1 deletion smcore/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@

#pragma once

#include "smstring.h"
#include <memory>

#include "smstring.h"

namespace smos
{
namespace smcore
Expand Down
7 changes: 4 additions & 3 deletions smcore/project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
//******************************************************************************

#include "project.h"

#include <filesystem>

namespace smos
{
namespace smcore
{
//******************************************************************************
Project::Project(void)
Project::Project(void) : m_ClassVersion(0)
{
}
//******************************************************************************
Expand Down Expand Up @@ -73,13 +74,13 @@ namespace smos
//******************************************************************************
std::ostream &operator<<(std::ostream &os, const Project &obj)
{
os << obj.m_ProjectName << std::endl;
os << obj.m_ClassVersion << obj.m_ProjectName;
return os;
}
//******************************************************************************
std::istream &operator>>(std::istream &is, Project &obj)
{
is >> obj.m_ProjectName;
is >> obj.m_ClassVersion >> obj.m_ProjectName;
return is;
}
//******************************************************************************
Expand Down
10 changes: 8 additions & 2 deletions smcore/project.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@

#pragma once

#include <iostream>
#include <ctime>
#include <fstream>
#include <iostream>

#include "smstring.h"
#include "error.h"
#include "smstring.h"

namespace smos
{
Expand Down Expand Up @@ -101,6 +102,11 @@ namespace smos
friend std::istream &operator>>(std::istream &is, Project &obj);

private:
/**
* @brief Number of current class version for versioning
*/
uint16_t m_ClassVersion;

/**
* @brief Name of project
*/
Expand Down
1 change: 1 addition & 0 deletions smcore/smcore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ namespace smos
SMCore::SMCore(void)
{
}
//******************************************************************************
}
}
1 change: 1 addition & 0 deletions smcore/smstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ namespace smos
{
namespace smcore
{
//******************************************************************************
}
}
20 changes: 19 additions & 1 deletion smcore/version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
//******************************************************************************

#include "version.h"

#include <sstream>

namespace smos
Expand Down Expand Up @@ -81,11 +82,28 @@ namespace smos
return result;
}
//******************************************************************************
void Version::SetVersion(const short &major, const short &minor, const short &revision)
void Version::SetVersion(const uint16_t major, const uint16_t minor, const uint16_t revision)
{
this->m_major = major;
this->m_minor = minor;
this->m_revision = revision;
}
//******************************************************************************
std::ostream &operator<<(std::ostream &os, const Version &obj)
{
os << obj.m_major;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if the "short" type is portable - is it always the same size? Maybe it would be better to use int16_t or int8_t or even better uint16_t or uint8_t.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're absolutely right, I'll change this.

os << obj.m_minor;
os << obj.m_revision;
return os;
}
//******************************************************************************
std::istream &operator>>(std::istream &is, Version &obj)
{
is >> obj.m_major;
is >> obj.m_minor;
is >> obj.m_revision;
return is;
}
//******************************************************************************
}
}
34 changes: 29 additions & 5 deletions smcore/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@

#pragma once

#include "smstring.h"
#include <cstdint>
#include <ctime>
#include <fstream>
#include <iostream>

#include "smstring.h"

namespace smos
{
Expand Down Expand Up @@ -87,21 +91,41 @@ namespace smos
* @param minor Minor version information
* @param revision Revision version informationi
*/
void SetVersion(const short &major, const short &minor, const short &revision);
void SetVersion(const uint16_t major, const uint16_t minor, const uint16_t revision);

/**
* @brief Enable writing to stream
*
* @param os Outputstream to write to
* @param obj Version object to write to stream
*
* @return std::ostream&
*/
friend std::ostream &operator<<(std::ostream &os, const Version &obj);

/**
* @brief Enable reading from stream
*
* @param is Inputstream to read from
* @param obj Version object to read from stream
*
* @return std::istream&
*/
friend std::istream &operator>>(std::istream &is, Version &obj);

private:
/**
* @brief Major version number
*/
short m_major;
uint16_t m_major;
/**
* @brief Minor version number
*/
short m_minor;
uint16_t m_minor;
/**
* @brief Revision version number
*/
short m_revision;
uint16_t m_revision;
};
}
}