Skip to content

Commit

Permalink
Merge pull request #412 from micro-manager/no-using-namespace
Browse files Browse the repository at this point in the history
Avoid 'using namespace' in MMDevice, MMCore, DemoCamera and other cleanup
  • Loading branch information
marktsuchida authored Dec 11, 2023
2 parents 8f1a307 + 8a295f5 commit 605caee
Show file tree
Hide file tree
Showing 30 changed files with 274 additions and 368 deletions.
1 change: 1 addition & 0 deletions DeviceAdapters/Andor/SRRFControl.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "SRRFControl.h"
#include <boost/filesystem/operations.hpp>
#include "boost/date_time/posix_time/posix_time.hpp"
#include "DeviceUtils.h"
#include "ImgBuffer.h"

#ifdef WIN32
Expand Down
37 changes: 17 additions & 20 deletions DeviceAdapters/DemoCamera/DemoCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@
#include <iostream>
#include <future>



using namespace std;
const double CDemoCamera::nominalPixelSizeUm_ = 1.0;
double g_IntensityFactor_ = 1.0;

Expand Down Expand Up @@ -346,7 +343,7 @@ int CDemoCamera::Initialize()
nRet = CreateStringProperty(MM::g_Keyword_PixelType, g_PixelType_8bit, false, pAct);
assert(nRet == DEVICE_OK);

vector<string> pixelTypeValues;
std::vector<std::string> pixelTypeValues;
pixelTypeValues.push_back(g_PixelType_8bit);
pixelTypeValues.push_back(g_PixelType_16bit);
pixelTypeValues.push_back(g_PixelType_32bitRGB);
Expand All @@ -362,7 +359,7 @@ int CDemoCamera::Initialize()
nRet = CreateIntegerProperty("BitDepth", 8, false, pAct);
assert(nRet == DEVICE_OK);

vector<string> bitDepths;
std::vector<std::string> bitDepths;
bitDepths.push_back("8");
bitDepths.push_back("10");
bitDepths.push_back("11");
Expand Down Expand Up @@ -1021,7 +1018,7 @@ int CDemoCamera::SendExposureSequence() const {

int CDemoCamera::SetAllowedBinning()
{
vector<string> binValues;
std::vector<std::string> binValues;
binValues.push_back("1");
binValues.push_back("2");
if (scanMode_ < 3)
Expand Down Expand Up @@ -1400,7 +1397,7 @@ int CDemoCamera::OnPixelType(MM::PropertyBase* pProp, MM::ActionType eAct)
if(IsCapturing())
return DEVICE_CAMERA_BUSY_ACQUIRING;

string pixelType;
std::string pixelType;
pProp->Get(pixelType);

if (pixelType.compare(g_PixelType_8bit) == 0)
Expand Down Expand Up @@ -2139,7 +2136,7 @@ void CDemoCamera::GenerateSyntheticImage(ImgBuffer& img, double exp)
for (k=0; k<imgWidth; k++)
{
long lIndex = imgWidth*j + k;
unsigned char val = (unsigned char) (g_IntensityFactor_ * min(255.0, (pedestal + dAmp * sin(dPhase_ + dLinePhase + (2.0 * lSinePeriod * k) / lPeriod))));
unsigned char val = (unsigned char) (g_IntensityFactor_ * std::min(255.0, (pedestal + dAmp * sin(dPhase_ + dLinePhase + (2.0 * lSinePeriod * k) / lPeriod))));
if (val > maxDrawnVal) {
maxDrawnVal = val;
}
Expand Down Expand Up @@ -2172,7 +2169,7 @@ void CDemoCamera::GenerateSyntheticImage(ImgBuffer& img, double exp)
for (k=0; k<imgWidth; k++)
{
long lIndex = imgWidth*j + k;
unsigned short val = (unsigned short) (g_IntensityFactor_ * min((double)maxValue, pedestal + dAmp16 * sin(dPhase_ + dLinePhase + (2.0 * lSinePeriod * k) / lPeriod)));
unsigned short val = (unsigned short) (g_IntensityFactor_ * std::min((double)maxValue, pedestal + dAmp16 * sin(dPhase_ + dLinePhase + (2.0 * lSinePeriod * k) / lPeriod)));
if (val > maxDrawnVal) {
maxDrawnVal = val;
}
Expand Down Expand Up @@ -2207,7 +2204,7 @@ void CDemoCamera::GenerateSyntheticImage(ImgBuffer& img, double exp)
for (k=0; k<imgWidth; k++)
{
long lIndex = imgWidth*j + k;
double value = (g_IntensityFactor_ * min(255.0, (pedestal + dAmp * sin(dPhase_ + dLinePhase + (2.0 * lSinePeriod * k) / lPeriod))));
double value = (g_IntensityFactor_ * std::min(255.0, (pedestal + dAmp * sin(dPhase_ + dLinePhase + (2.0 * lSinePeriod * k) / lPeriod))));
if (value > maxDrawnVal) {
maxDrawnVal = value;
}
Expand Down Expand Up @@ -2276,15 +2273,15 @@ void CDemoCamera::GenerateSyntheticImage(ImgBuffer& img, double exp)
{
long lIndex = imgWidth*j + k;
double factor = (2.0 * lSinePeriod * k) / lPeriod;
unsigned char value0 = (unsigned char) min(255.0, (pedestal + dAmp * sin(dPhase_ + dLinePhase + factor)));
unsigned char value0 = (unsigned char) std::min(255.0, (pedestal + dAmp * sin(dPhase_ + dLinePhase + factor)));
theBytes[0] = value0;
if( NULL != pTmpBuffer)
pTmp2[1] = value0;
unsigned char value1 = (unsigned char) min(255.0, (pedestal + dAmp * sin(dPhase_ + dLinePhase*2 + factor)));
unsigned char value1 = (unsigned char) std::min(255.0, (pedestal + dAmp * sin(dPhase_ + dLinePhase*2 + factor)));
theBytes[1] = value1;
if( NULL != pTmpBuffer)
pTmp2[2] = value1;
unsigned char value2 = (unsigned char) min(255.0, (pedestal + dAmp * sin(dPhase_ + dLinePhase*4 + factor)));
unsigned char value2 = (unsigned char) std::min(255.0, (pedestal + dAmp * sin(dPhase_ + dLinePhase*4 + factor)));
theBytes[2] = value2;

if( NULL != pTmpBuffer){
Expand Down Expand Up @@ -2328,9 +2325,9 @@ void CDemoCamera::GenerateSyntheticImage(ImgBuffer& img, double exp)
for (k=0; k<imgWidth; k++)
{
long lIndex = imgWidth*j + k;
unsigned long long value0 = (unsigned short) min(maxPixelValue, (pedestal + dAmp16 * sin(dPhase_ + dLinePhase + (2.0 * lSinePeriod * k) / lPeriod)));
unsigned long long value1 = (unsigned short) min(maxPixelValue, (pedestal + dAmp16 * sin(dPhase_ + dLinePhase*2 + (2.0 * lSinePeriod * k) / lPeriod)));
unsigned long long value2 = (unsigned short) min(maxPixelValue, (pedestal + dAmp16 * sin(dPhase_ + dLinePhase*4 + (2.0 * lSinePeriod * k) / lPeriod)));
unsigned long long value0 = (unsigned short) std::min(maxPixelValue, (pedestal + dAmp16 * sin(dPhase_ + dLinePhase + (2.0 * lSinePeriod * k) / lPeriod)));
unsigned long long value1 = (unsigned short) std::min(maxPixelValue, (pedestal + dAmp16 * sin(dPhase_ + dLinePhase*2 + (2.0 * lSinePeriod * k) / lPeriod)));
unsigned long long value2 = (unsigned short) std::min(maxPixelValue, (pedestal + dAmp16 * sin(dPhase_ + dLinePhase*4 + (2.0 * lSinePeriod * k) / lPeriod)));
unsigned long long tval = value0+(value1<<16)+(value2<<32);
if (tval > maxDrawnVal) {
maxDrawnVal = static_cast<double>(tval);
Expand Down Expand Up @@ -3473,7 +3470,7 @@ int CDemoStage::SetPositionUm(double pos)
void CDemoStage::SetIntensityFactor(double pos)
{
pos = fabs(pos);
g_IntensityFactor_ = max(.1, min(1.0, 1.0 - .2 * log(pos)));
g_IntensityFactor_ = std::max(.1, std::min(1.0, 1.0 - .2 * log(pos)));
}

int CDemoStage::IsStageSequenceable(bool& isSequenceable) const
Expand Down Expand Up @@ -3991,8 +3988,8 @@ gatedVolts_(0),
open_(true),
sequenceRunning_(false),
sequenceIndex_(0),
sentSequence_(vector<double>()),
nascentSequence_(vector<double>())
sentSequence_(std::vector<double>()),
nascentSequence_(std::vector<double>())
{
SetErrorText(ERR_SEQUENCE_INACTIVE, "Sequence triggered, but sequence is not running");

Expand Down Expand Up @@ -4063,7 +4060,7 @@ int DemoDA::SetSignal(double volts)
volt_ = volts;
if (open_)
gatedVolts_ = volts;
stringstream s;
std::stringstream s;
s << "Voltage set to " << volts;
LogMessage(s.str(), false);
return DEVICE_OK;
Expand Down
7 changes: 1 addition & 6 deletions DeviceAdapters/DemoCamera/DemoCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES.

#ifndef _DEMOCAMERA_H_
#define _DEMOCAMERA_H_
#pragma once

#include "DeviceBase.h"
#include "ImgBuffer.h"
Expand Down Expand Up @@ -1193,7 +1192,3 @@ class DemoGalvo : public CGalvoBase<DemoGalvo>, ImgManipulator
int offsetY_;
double vMaxY_;
};



#endif //_DEMOCAMERA_H_
4 changes: 2 additions & 2 deletions DeviceAdapters/DemoCamera/DemoCamera.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<Optimization>Disabled</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;MODULE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>NOMINMAX;WIN32;_DEBUG;_WINDOWS;_USRDLL;MODULE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
<PrecompiledHeader>
Expand All @@ -77,7 +77,7 @@
<Optimization>MaxSpeed</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;MODULE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>NOMINMAX;WIN32;NDEBUG;_WINDOWS;_USRDLL;MODULE_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeTypeInfo>true</RuntimeTypeInfo>
<PrecompiledHeader>
</PrecompiledHeader>
Expand Down
5 changes: 1 addition & 4 deletions DeviceAdapters/DemoCamera/WriteCompactTiffRGB.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#pragma once

#include "stdio.h"
#include "math.h"
Expand Down Expand Up @@ -240,7 +241,3 @@ void GenerateRGBTestImage( const int nx, const int ny, const char color, unsigne
}
}
}




10 changes: 2 additions & 8 deletions MMCore/ConfigGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@
// IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES.
//
// CVS: $Id: ConfigGroup.h 17248 2020-01-25 19:49:51Z nico $
//
#ifndef _CONFIG_GROUP_H_
#define _CONFIG_GROUP_H_

#pragma once

#include "Configuration.h"
#include "Error.h"
Expand Down Expand Up @@ -439,6 +436,3 @@ class PixelSizeConfigGroup : public ConfigGroupBase<PixelSizeConfiguration>
}
}
};

#endif

28 changes: 13 additions & 15 deletions MMCore/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@
#include "Configuration.h"
#include "../MMDevice/MMDevice.h"
#include "Error.h"
#include <assert.h>
#include <sstream>
#include <string>

#include <cstring>
#include <fstream>
#include <sstream>
#include <string>

using namespace std;

string PropertySetting::generateKey(const char* device, const char* prop)
std::string PropertySetting::generateKey(const char* device, const char* prop)
{
string key(device);
std::string key(device);
key += "-";
key += prop;
return key;
Expand All @@ -40,9 +38,9 @@ string PropertySetting::generateKey(const char* device, const char* prop)
/**
* Returns verbose description of the object's contents.
*/
string PropertySetting::getVerbose() const
std::string PropertySetting::getVerbose() const
{
ostringstream txt;
std::ostringstream txt;
txt << deviceLabel_ << ":" << propertyName_ << "=" << value_;
return txt.str();
}
Expand Down Expand Up @@ -93,7 +91,7 @@ PropertySetting Configuration::getSetting(size_t index) const throw (CMMError)

bool Configuration::isPropertyIncluded(const char* device, const char* prop)
{
map<string, int>::iterator it = index_.find(PropertySetting::generateKey(device, prop));
std::map<std::string, int>::iterator it = index_.find(PropertySetting::generateKey(device, prop));
if (it != index_.end())
return true;
else
Expand All @@ -106,7 +104,7 @@ bool Configuration::isPropertyIncluded(const char* device, const char* prop)

PropertySetting Configuration::getSetting(const char* device, const char* prop)
{
map<string, int>::iterator it = index_.find(PropertySetting::generateKey(device, prop));
std::map<std::string, int>::iterator it = index_.find(PropertySetting::generateKey(device, prop));
if (it == index_.end())
{
std::ostringstream errTxt;
Expand All @@ -128,7 +126,7 @@ PropertySetting Configuration::getSetting(const char* device, const char* prop)

bool Configuration::isSettingIncluded(const PropertySetting& ps)
{
map<string, int>::iterator it = index_.find(ps.getKey());
std::map<std::string, int>::iterator it = index_.find(ps.getKey());
if (it != index_.end() && settings_[it->second].getPropertyValue().compare(ps.getPropertyValue()) == 0)
return true;
else
Expand All @@ -143,7 +141,7 @@ bool Configuration::isSettingIncluded(const PropertySetting& ps)

bool Configuration::isConfigurationIncluded(const Configuration& cfg)
{
vector<PropertySetting>::const_iterator it;
std::vector<PropertySetting>::const_iterator it;
for (it=cfg.settings_.begin(); it!=cfg.settings_.end(); ++it)
if (!isSettingIncluded(*it))
return false;
Expand All @@ -156,7 +154,7 @@ bool Configuration::isConfigurationIncluded(const Configuration& cfg)
*/
void Configuration::addSetting(const PropertySetting& setting)
{
map<string, int>::iterator it = index_.find(setting.getKey());
std::map<std::string, int>::iterator it = index_.find(setting.getKey());
if (it != index_.end())
{
// replace
Expand All @@ -175,7 +173,7 @@ void Configuration::addSetting(const PropertySetting& setting)
*/
void Configuration::deleteSetting(const char* device, const char* prop)
{
map<string, int>::iterator it = index_.find(PropertySetting::generateKey(device, prop));
std::map<std::string, int>::iterator it = index_.find(PropertySetting::generateKey(device, prop));
if (it == index_.end())
{
std::ostringstream errTxt;
Expand Down
8 changes: 2 additions & 6 deletions MMCore/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@
// IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES.
// CVS: $Id: Configuration.h 16305 2017-02-11 05:01:12Z mark $
//
#ifndef _CONFIGURATION_H_
#define _CONFIGURATION_H_

#pragma once

#ifdef WIN32
// disable exception scpecification warnings in MSVC
Expand Down Expand Up @@ -120,5 +118,3 @@ class Configuration
std::vector<PropertySetting> settings_;
std::map<std::string, int> index_;
};

#endif //_CONFIGURATION_H_
4 changes: 0 additions & 4 deletions MMCore/CoreCallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1031,11 +1031,7 @@ void CoreCallback::NextPostedError(int& errorCode, char* pMessage, int maxlen, i
if( 0 < maxlen )
{
*pMessage = 0;
#ifdef _WINDOWS
messageLength = min( maxlen, (int) nextError.second.length());
#else
messageLength = std::min( maxlen, (int) nextError.second.length());
#endif
strncpy(pMessage, nextError.second.c_str(), messageLength);
}
}
Expand Down
5 changes: 1 addition & 4 deletions MMCore/CoreCallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES.

#ifndef _CORECALLBACK_H_
#define _CORECALLBACK_H_
#pragma once

#include "Devices/DeviceInstances.h"
#include "CoreUtils.h"
Expand Down Expand Up @@ -147,5 +146,3 @@ class CoreCallback : public MM::Core
int OnPixelSizeChanged(double newPixelSizeUm);
int OnPixelSizeAffineChanged(std::vector<double> newPixelSizeAffine);
};

#endif // _CORECALLBACK_H_
Loading

0 comments on commit 605caee

Please sign in to comment.