Commit 89b87283 authored by Alex Buts's avatar Alex Buts
Browse files

refs #5871 moved property manager pointer to tableWS

instead of ITableWorkspace.h
parent 915fc036
......@@ -117,13 +117,11 @@ class MANTID_API_DLL ITableWorkspace: public API::Workspace
{
public:
///Constructor
ITableWorkspace();
ITableWorkspace()
{}
/// Virtual destructor.
virtual ~ITableWorkspace();
/// Copy constructor
ITableWorkspace(const ITableWorkspace &other);
/// Operator =
ITableWorkspace & operator=(const ITableWorkspace &rhs);
virtual ~ITableWorkspace(){}
/// Return the workspace typeID
virtual const std::string id() const{return "ITableWorkspace";}
/** Creates a new column
......@@ -135,9 +133,9 @@ public:
/// Creates n new columns of the same type.
virtual bool addColumns(const std::string& type, const std::string& name, size_t n);
/**Get access to shared pointer containing workspace porperties */
API::LogManager_sptr logs(){return m_LogManager;}
virtual API::LogManager_sptr logs() = 0;
/**Get constant access to shared pointer containing workspace porperties */
API::LogManager_const_sptr getLogs()const{return m_LogManager;}
virtual API::LogManager_const_sptr getLogs()const = 0;
/// Removes a column.
virtual void removeColumn( const std::string& name) = 0;
......@@ -319,9 +317,6 @@ protected:
{
c->remove(index);
}
API::LogManager_sptr m_LogManager;
private:
/// Logger
static Kernel::Logger& g_log;
......
......@@ -75,6 +75,11 @@ namespace DataObjects
PeaksWorkspace* clone() const;
/**Get access to shared pointer containing workspace porperties */
API::LogManager_sptr logs();
/**Get constant access to shared pointer containing workspace porperties; Copies logs into new LogManager variable */
API::LogManager_const_sptr getLogs()const{return API::LogManager_const_sptr(new API::LogManager(this->run()));}
virtual ~PeaksWorkspace();
boost::shared_ptr<PeaksWorkspace> clone();
......@@ -194,10 +199,12 @@ namespace DataObjects
// ====================================== End ITableWorkspace Methods ==================================
// --- Nexus Methods ---
// --- Nexus Methods ---
// Save to Nexus
void saveNexus(::NeXus::File * file ) const;
// adapter for logs() function, which create reference to this class itself and does not allow to delete the shared pointers,
// returned by logs() function when they go out of scope
API::LogManager_sptr m_logCash;
};
......
......@@ -114,6 +114,11 @@ namespace DataObjects
std::vector<std::string> getColumnNames() const;
/// Number of rows in the workspace.
size_t rowCount() const {return m_rowCount;}
/**Get access to shared pointer containing workspace porperties */
API::LogManager_sptr logs(){return m_LogManager;}
/**Get constant access to shared pointer containing workspace porperties */
API::LogManager_const_sptr getLogs()const{return m_LogManager;}
/** get access to column vecotor for index i.
*
* The operation is unsafe with regards to the operaitons resizing obtained vector.
......@@ -378,7 +383,17 @@ private:
findValue(value,row,col);
}
/// Copy constructor
TableWorkspace(const TableWorkspace &other);
//{
// m_LogManager = boost::make_shared<API::LogManager>(*other.m_LogManager);
//}
/// Operator =
TableWorkspace & operator=(const TableWorkspace &rhs);
//{
// if(&rhs != this)m_LogManager = boost::make_shared<API::LogManager>(*rhs.m_LogManager);
// return *this;
//}
private:
/// Used in std::find_if algorithm to find a Column with name \a name.
class FindName
......@@ -407,7 +422,9 @@ private:
/// Logger
static Kernel::Logger& g_log;
// Kernel::PropertyManager_sptr m_TableProperties;
/// shared pointer to the logManager, responsible for the workspace properties.
API::LogManager_sptr m_LogManager;
};
......
......@@ -506,6 +506,19 @@ namespace DataObjects
file->closeGroup(); // end of peaks workpace
}
// prevent shared pointer from deleting this
struct NullDeleter {template<typename T> void operator()(T*) {} };
/**Get access to shared pointer containing workspace porperties, cashes the shared pointer
into internal class variable to not allow shared pointer being deleted */
API::LogManager_sptr PeaksWorkspace::logs()
{
if(m_logCash)return m_logCash;
m_logCash = API::LogManager_sptr(&(this->mutableRun()),NullDeleter());
return m_logCash;
}
}
}
......
......@@ -17,7 +17,8 @@ namespace Mantid
Kernel::Logger& TableWorkspace::g_log = Kernel::Logger::get("TableWorkspace");
/// Constructor
TableWorkspace::TableWorkspace(size_t nrows) : ITableWorkspace(), m_rowCount(0)
TableWorkspace::TableWorkspace(size_t nrows) : ITableWorkspace(), m_rowCount(0),
m_LogManager(new API::LogManager)
{
setRowCount(nrows);
}
......@@ -35,6 +36,7 @@ namespace Mantid
data_size += (*c)->sizeOfData();
}
data_size+= m_LogManager->getMemorySize();
return data_size;
}
......
......@@ -18,6 +18,8 @@
#include "MantidTestHelpers/ComponentCreationHelper.h"
#include "MantidAPI/AlgorithmManager.h"
#include "MantidAPI/FrameworkManager.h"
#include "MantidAPI/LogManager.h"
#include <Poco/File.h>
......@@ -129,7 +131,7 @@ public:
}
void test_saveNexus()
void xest_saveNexus()
{
// Ensure the plugin libraries are loaded so that we can use LoadNexusProcessed
Mantid::API::FrameworkManager::Instance();
......@@ -211,6 +213,41 @@ public:
}
void test_getSetLogAccess()
{
bool trueSwitch(true);
PeaksWorkspace * pw = buildPW();
LogManager_const_sptr props = pw->getLogs();
std::string existingVal;
TS_ASSERT_THROWS_NOTHING(existingVal=props->getPropertyValueAsType<std::string>("TestProp"));
TS_ASSERT_EQUALS("value",existingVal);
// define local scope;
if(trueSwitch)
{
// get mutable pointer to existing values;
LogManager_sptr mprops = pw->logs();
TS_ASSERT_THROWS_NOTHING(mprops->addProperty<std::string>("TestProp2","value2"));
TS_ASSERT(mprops->hasProperty("TestProp2"));
TS_ASSERT(!props->hasProperty("TestProp2"));
TS_ASSERT(pw->run().hasProperty("TestProp2"));
}
// nothing terrible happened and workspace still have this property
TS_ASSERT(pw->run().hasProperty("TestProp2"));
delete pw;
}
PeaksWorkspaceTest()
{
FrameworkManager::Instance();
AlgorithmManager::Instance();
}
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment