Skip to content

Commit

Permalink
Clear a couple of MSVC warnings. Re #4473.
Browse files Browse the repository at this point in the history
Also move some definitions from the PeaksWorkspace header to the cpp.
  • Loading branch information
RussellTaylor committed Mar 2, 2012
1 parent 0fce028 commit 6b6cb6e
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 75 deletions.
4 changes: 2 additions & 2 deletions Code/Mantid/Framework/API/inc/MantidAPI/IPeaksWorkspace.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespace API
/** Removes the indicated peak
* @param peakNum the peak to remove. peakNum starts at 0
*/
virtual void removePeak(const int peakNum) = 0;
virtual void removePeak(int peakNum) = 0;

//---------------------------------------------------------------------------------------------
/** Add a peak to the list
Expand All @@ -83,7 +83,7 @@ namespace API
* @param peakNum :: index of the peak to get.
* @return a reference to a Peak object.
*/
virtual IPeak & getPeak(const int peakNum) = 0;
virtual IPeak & getPeak(int peakNum) = 0;

//---------------------------------------------------------------------------------------------
/** Return a pointer to the Peak
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,77 +87,14 @@ namespace DataObjects

void sort(std::vector< std::pair<std::string, bool> > & criteria);

//---------------------------------------------------------------------------------------------
/** @return the number of peaks
*/
int getNumberPeaks() const
{
return int(peaks.size());
}

//---------------------------------------------------------------------------------------------
/** Removes the indicated peak
* @param peakNum the peak to remove. peakNum starts at 0
*/
void removePeak(const int peakNum)
{
if (peakNum >= static_cast<int>(peaks.size()) || peakNum < 0 ) throw std::invalid_argument("PeaksWorkspace::removePeak(): peakNum is out of range.");
peaks.erase(peaks.begin()+peakNum);
}

//---------------------------------------------------------------------------------------------
/** Add a peak to the list
* @param ipeak :: Peak object to add (copy) into this.
*/
void addPeak(const API::IPeak& ipeak)
{
if (dynamic_cast<const Peak*>(&ipeak))
{
peaks.push_back((const Peak&)ipeak);
}
else
{
peaks.push_back(Peak(ipeak));
}
}

//---------------------------------------------------------------------------------------------
/** Return a reference to the Peak
* @param peakNum :: index of the peak to get.
* @return a reference to a Peak object.
*/
API::IPeak & getPeak(const int peakNum)
{
if (peakNum >= static_cast<int>(peaks.size()) || peakNum < 0 ) throw std::invalid_argument("PeaksWorkspace::getPeak(): peakNum is out of range.");
return peaks[peakNum];
}

//---------------------------------------------------------------------------------------------
/** Create an instance of a Peak
* @param QLabFrame :: Q of the center of the peak, in reciprocal space
* @param detectorDistance :: distance between the sample and the detector.
* @return a pointer to a new Peak object.
*/
API::IPeak* createPeak(Kernel::V3D QLabFrame, double detectorDistance=1.0)
{
return new Peak(this->getInstrument(), QLabFrame, detectorDistance);
}

//---------------------------------------------------------------------------------------------
/** Return a reference to the Peaks vector */
std::vector<Peak> & getPeaks()
{
return peaks;
}



//---------------------------------------------------------------------------------------------
/// Return the memory used in bytes
virtual size_t getMemorySize() const
{
return getNumberPeaks() * sizeof(Peak);
}
int getNumberPeaks() const;
void removePeak(int peakNum);
void addPeak(const API::IPeak& ipeak);
API::IPeak & getPeak(int peakNum);
API::IPeak* createPeak(Kernel::V3D QLabFrame, double detectorDistance=1.0);
std::vector<Peak> & getPeaks();

virtual size_t getMemorySize() const;

// ====================================== ITableWorkspace Methods ==================================
/// Number of columns in the workspace.
Expand Down
71 changes: 71 additions & 0 deletions Code/Mantid/Framework/DataObjects/src/PeaksWorkspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,77 @@ namespace DataObjects
std::stable_sort(peaks.begin(), peaks.end(), comparator);
}

//---------------------------------------------------------------------------------------------
/** @return the number of peaks
*/
int PeaksWorkspace::getNumberPeaks() const
{
return int(peaks.size());
}

//---------------------------------------------------------------------------------------------
/** Removes the indicated peak
* @param peakNum the peak to remove. peakNum starts at 0
*/
void PeaksWorkspace::removePeak(const int peakNum)
{
if (peakNum >= static_cast<int>(peaks.size()) || peakNum < 0 ) throw std::invalid_argument("PeaksWorkspace::removePeak(): peakNum is out of range.");
peaks.erase(peaks.begin()+peakNum);
}

//---------------------------------------------------------------------------------------------
/** Add a peak to the list
* @param ipeak :: Peak object to add (copy) into this.
*/
void PeaksWorkspace::addPeak(const API::IPeak& ipeak)
{
if (dynamic_cast<const Peak*>(&ipeak))
{
peaks.push_back((const Peak&)ipeak);
}
else
{
peaks.push_back(Peak(ipeak));
}
}

//---------------------------------------------------------------------------------------------
/** Return a reference to the Peak
* @param peakNum :: index of the peak to get.
* @return a reference to a Peak object.
*/
API::IPeak & PeaksWorkspace::getPeak(const int peakNum)
{
if (peakNum >= static_cast<int>(peaks.size()) || peakNum < 0 ) throw std::invalid_argument("PeaksWorkspace::getPeak(): peakNum is out of range.");
return peaks[peakNum];
}

//---------------------------------------------------------------------------------------------
/** Create an instance of a Peak
* @param QLabFrame :: Q of the center of the peak, in reciprocal space
* @param detectorDistance :: distance between the sample and the detector.
* @return a pointer to a new Peak object.
*/
API::IPeak* PeaksWorkspace::createPeak(Kernel::V3D QLabFrame, double detectorDistance)
{
return new Peak(this->getInstrument(), QLabFrame, detectorDistance);
}

//---------------------------------------------------------------------------------------------
/** Return a reference to the Peaks vector */
std::vector<Peak> & PeaksWorkspace::getPeaks()
{
return peaks;
}



//---------------------------------------------------------------------------------------------
/// Return the memory used in bytes
size_t PeaksWorkspace::getMemorySize() const
{
return getNumberPeaks() * sizeof(Peak);
}

//---------------------------------------------------------------------------------------------
/** Destructor */
Expand Down
4 changes: 2 additions & 2 deletions Code/Mantid/Vates/VatesAPI/test/vtkPeakMarkerFactoryTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ class MockPeaksWorkspace : public PeaksWorkspace
MOCK_METHOD0(getInstrument, Mantid::Geometry::Instrument_const_sptr ());
MOCK_CONST_METHOD0(clone, Mantid::DataObjects::PeaksWorkspace*());
MOCK_CONST_METHOD0(getNumberPeaks, int());
MOCK_METHOD1(removePeak, void (const int peakNum) );
MOCK_METHOD1(removePeak, void (int peakNum) );
MOCK_METHOD1(addPeak, void (const IPeak& ipeak));
MOCK_METHOD1(getPeak, Mantid::API::IPeak & (const int peakNum));
MOCK_METHOD1(getPeak, Mantid::API::IPeak & (int peakNum));
MOCK_METHOD2(createPeak, Mantid::API::IPeak* (Mantid::Kernel::V3D QLabFrame, double detectorDistance));
};

Expand Down

0 comments on commit 6b6cb6e

Please sign in to comment.