diff options
author | Julien Nabet <serval2412@yahoo.fr> | 2017-10-12 20:32:17 +0200 |
---|---|---|
committer | Julien Nabet <serval2412@yahoo.fr> | 2017-10-13 00:19:34 +0200 |
commit | 2ea531c0578bb7f0a34ec7de0aaea595e0387928 (patch) | |
tree | 985555668bd79af558c91d7e40b239f710c5ed6a /jvmfwk | |
parent | 923cea6817e29405a8cdf3b3f608fef84aeb4ec1 (diff) |
Use loop ranges in jvmfwk
to simplify and avoid all the typedefs
Change-Id: Ia14337dd71b55fc24f162b5436af76aeeb8d2575
Reviewed-on: https://gerrit.libreoffice.org/43346
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
Diffstat (limited to 'jvmfwk')
-rw-r--r-- | jvmfwk/plugins/sunmajor/pluginlib/gnujre.cxx | 50 | ||||
-rw-r--r-- | jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx | 40 | ||||
-rw-r--r-- | jvmfwk/plugins/sunmajor/pluginlib/util.cxx | 33 | ||||
-rw-r--r-- | jvmfwk/plugins/sunmajor/pluginlib/vendorbase.cxx | 37 | ||||
-rw-r--r-- | jvmfwk/source/elements.cxx | 15 | ||||
-rw-r--r-- | jvmfwk/source/framework.cxx | 26 |
6 files changed, 84 insertions, 117 deletions
diff --git a/jvmfwk/plugins/sunmajor/pluginlib/gnujre.cxx b/jvmfwk/plugins/sunmajor/pluginlib/gnujre.cxx index 4485828a8926..22285bb0c18c 100644 --- a/jvmfwk/plugins/sunmajor/pluginlib/gnujre.cxx +++ b/jvmfwk/plugins/sunmajor/pluginlib/gnujre.cxx @@ -97,7 +97,6 @@ bool GnuInfo::initialize(vector<pair<OUString, OUString> > props) //javax.accessibility.assistive_technologies from system properties OUString sJavaLibraryPath; - typedef vector<pair<OUString, OUString> >::const_iterator it_prop; OUString const sVendorProperty("java.vendor"); OUString const sVersionProperty("java.version"); OUString const sJavaHomeProperty("java.home"); @@ -112,28 +111,27 @@ bool GnuInfo::initialize(vector<pair<OUString, OUString> > props) bool bJavaLibraryPath = false; bool bAccess = false; - typedef vector<pair<OUString, OUString> >::const_iterator it_prop; - for (it_prop i = props.begin(); i != props.end(); ++i) + for (auto const& prop : props) { - if(! bVendor && sVendorProperty == i->first) + if(! bVendor && sVendorProperty == prop.first) { - m_sVendor = i->second; + m_sVendor = prop.second; bVendor = true; } - else if (!bVersion && sVersionProperty == i->first) + else if (!bVersion && sVersionProperty == prop.first) { - m_sVersion = i->second; + m_sVersion = prop.second; bVersion = true; } - else if (!bHome && sGNUHomeProperty == i->first) + else if (!bHome && sGNUHomeProperty == prop.first) { - m_sHome = i->second; + m_sHome = prop.second; bHome = true; } - else if (!bJavaHome && sJavaHomeProperty == i->first) + else if (!bJavaHome && sJavaHomeProperty == prop.first) { OUString fileURL; - if (osl_getFileURLFromSystemPath(i->second.pData,& fileURL.pData) == + if (osl_getFileURLFromSystemPath(prop.second.pData,& fileURL.pData) == osl_File_E_None) { //make sure that the drive letter have all the same case @@ -146,15 +144,15 @@ bool GnuInfo::initialize(vector<pair<OUString, OUString> > props) } } } - else if (!bJavaLibraryPath && sJavaLibraryPathProperty == i->first) + else if (!bJavaLibraryPath && sJavaLibraryPathProperty == prop.first) { sal_Int32 nIndex = 0; - osl_getFileURLFromSystemPath(i->second.getToken(0, ':', nIndex).pData, &sJavaLibraryPath.pData); + osl_getFileURLFromSystemPath(prop.second.getToken(0, ':', nIndex).pData, &sJavaLibraryPath.pData); bJavaLibraryPath = true; } - else if (!bAccess && sAccessProperty == i->first) + else if (!bAccess && sAccessProperty == prop.first) { - if (!i->second.isEmpty()) + if (!prop.second.isEmpty()) { m_bAccessibility = true; bAccess = true; @@ -179,11 +177,10 @@ bool GnuInfo::initialize(vector<pair<OUString, OUString> > props) vector<OUString> libpaths = getVectorFromCharArray(arRtPaths, size); bool bRt = false; - typedef vector<OUString>::const_iterator i_path; - for(i_path ip = libpaths.begin(); ip != libpaths.end(); ++ip) + for (auto const& libpath : libpaths) { //Construct an absolute path to the possible runtime - OUString usRt= m_sHome + *ip; + OUString usRt= m_sHome + libpath; DirectoryItem item; if(DirectoryItem::get(usRt, item) == File::E_None) { @@ -197,10 +194,10 @@ bool GnuInfo::initialize(vector<pair<OUString, OUString> > props) if (!bRt) { m_sHome = m_sJavaHome; - for(i_path ip = libpaths.begin(); ip != libpaths.end(); ++ip) + for (auto const& libpath : libpaths) { //Construct an absolute path to the possible runtime - OUString usRt= m_sHome + *ip; + OUString usRt= m_sHome + libpath; DirectoryItem item; if(DirectoryItem::get(usRt, item) == File::E_None) { @@ -216,10 +213,10 @@ bool GnuInfo::initialize(vector<pair<OUString, OUString> > props) if (!bRt && m_sJavaHome != sJavaLibraryPath) { m_sHome = sJavaLibraryPath; - for(i_path ip = libpaths.begin(); ip != libpaths.end(); ++ip) + for (auto const& libpath : libpaths) { //Construct an absolute path to the possible runtime - OUString usRt= m_sHome + *ip; + OUString usRt= m_sHome + libpath; DirectoryItem item; if(DirectoryItem::get(usRt, item) == File::E_None) { @@ -236,10 +233,10 @@ bool GnuInfo::initialize(vector<pair<OUString, OUString> > props) if (!bRt && m_sJavaHome != "file:///usr/lib") { m_sHome = "file:///usr/lib64"; - for(i_path ip = libpaths.begin(); ip != libpaths.end(); ++ip) + for (auto const& libpath : libpaths) { //Construct an absolute path to the possible runtime - OUString usRt= m_sHome + *ip; + OUString usRt= m_sHome + libpath; DirectoryItem item; if(DirectoryItem::get(usRt, item) == File::E_None) { @@ -263,9 +260,9 @@ bool GnuInfo::initialize(vector<pair<OUString, OUString> > props) bool bLdPath = true; int c = 0; - for(i_path il = ld_paths.begin(); il != ld_paths.end(); ++il, ++c) + for (auto const& ld_path : ld_paths) { - OUString usAbsUrl= m_sHome + *il; + OUString usAbsUrl= m_sHome + ld_path; // convert to system path OUString usSysPath; if(File::getSystemPathFromFileURL(usAbsUrl, usSysPath) == File::E_None) @@ -280,6 +277,7 @@ bool GnuInfo::initialize(vector<pair<OUString, OUString> > props) bLdPath = false; break; } + ++c; } return bLdPath; } diff --git a/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx b/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx index f97dbce54a38..21050dd8f50d 100644 --- a/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx +++ b/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx @@ -313,31 +313,28 @@ javaPluginError jfw_plugin_getAllJavaInfos( addAllJREInfos(checkJavaHomeAndPath, infos); vector<rtl::Reference<VendorBase> > vecVerifiedInfos; - typedef vector<rtl::Reference<VendorBase> >::iterator it; - for (it i= vecInfos.begin(); i != vecInfos.end(); ++i) + for (auto const& vecInfo : vecInfos) { - const rtl::Reference<VendorBase>& cur = *i; - if (sVendor != cur->getVendor()) + if (sVendor != vecInfo->getVendor()) continue; javaPluginError err = checkJavaVersionRequirements( - cur, sMinVersion, sMaxVersion, arExcludeList); + vecInfo, sMinVersion, sMaxVersion, arExcludeList); if (err == javaPluginError::FailedVersion || err == javaPluginError::WrongArch) continue; else if (err == javaPluginError::WrongVersionFormat) return err; - vecVerifiedInfos.push_back(*i); + vecVerifiedInfos.push_back(vecInfo); } //Now vecVerifiedInfos contains all those JREs which meet the version requirements //Transfer them into the array that is passed out. parJavaInfo->clear(); - typedef vector<rtl::Reference<VendorBase> >::const_iterator cit; - for (cit ii = vecVerifiedInfos.begin(); ii != vecVerifiedInfos.end(); ++ii) + for (auto const& vecVerifiedInfo : vecVerifiedInfos) { - parJavaInfo->push_back(createJavaInfo(*ii)); + parJavaInfo->push_back(createJavaInfo(vecVerifiedInfo)); } return javaPluginError::NONE; @@ -391,11 +388,10 @@ javaPluginError jfw_plugin_getJavaInfoFromJavaHome( assert(infoJavaHome.size() == 1); //Check if the detected JRE matches the version requirements - typedef std::vector<pair<OUString, jfw::VersionInfo>>::const_iterator ci_pl; - for (ci_pl vendorInfo = vecVendorInfos.begin(); vendorInfo != vecVendorInfos.end(); ++vendorInfo) + for (auto const& vendorInfo : vecVendorInfos) { - const OUString& vendor = vendorInfo->first; - jfw::VersionInfo versionInfo = vendorInfo->second; + const OUString& vendor = vendorInfo.first; + jfw::VersionInfo versionInfo = vendorInfo.second; if (vendor == infoJavaHome[0]->getVendor()) { @@ -428,28 +424,24 @@ javaPluginError jfw_plugin_getJavaInfosFromPath( vector<std::unique_ptr<JavaInfo>> vecVerifiedInfos; // copy infos of JREs that meet version requirements to vecVerifiedInfos - typedef vector<rtl::Reference<VendorBase> >::iterator it; - for (it i= vecInfosFromPath.begin(); i != vecInfosFromPath.end(); ++i) + for (auto const& infosFromPath : vecInfosFromPath) { - const rtl::Reference<VendorBase>& currentInfo = *i; - - typedef std::vector<pair<OUString, jfw::VersionInfo>>::const_iterator ci_pl; - for (ci_pl vendorInfo = vecVendorInfos.begin(); vendorInfo != vecVendorInfos.end(); ++vendorInfo) + for (auto const& vendorInfo : vecVendorInfos) { - const OUString& vendor = vendorInfo->first; - jfw::VersionInfo const & versionInfo = vendorInfo->second; + const OUString& vendor = vendorInfo.first; + jfw::VersionInfo const & versionInfo = vendorInfo.second; - if (vendor == currentInfo->getVendor()) + if (vendor == infosFromPath->getVendor()) { javaPluginError errorcode = checkJavaVersionRequirements( - currentInfo, + infosFromPath, versionInfo.sMinVersion, versionInfo.sMaxVersion, versionInfo.vecExcludeVersions); if (errorcode == javaPluginError::NONE) { - vecVerifiedInfos.push_back(createJavaInfo(currentInfo)); + vecVerifiedInfos.push_back(createJavaInfo(infosFromPath)); } } } diff --git a/jvmfwk/plugins/sunmajor/pluginlib/util.cxx b/jvmfwk/plugins/sunmajor/pluginlib/util.cxx index 7513716d4f90..79b3bcb45d76 100644 --- a/jvmfwk/plugins/sunmajor/pluginlib/util.cxx +++ b/jvmfwk/plugins/sunmajor/pluginlib/util.cxx @@ -584,22 +584,18 @@ void addJavaInfoFromWinReg( if(getSDKInfoFromRegistry(vecJavaHome)) { // create impl objects - typedef std::vector<OUString>::iterator ItHome; - for(ItHome it_home= vecJavaHome.begin(); it_home != vecJavaHome.end(); - ++it_home) + for (auto const& javaHome : vecJavaHome) { - getAndAddJREInfoByPath(*it_home, allInfos, addedInfos); + getAndAddJREInfoByPath(javaHome, allInfos, addedInfos); } } vecJavaHome.clear(); if(getJREInfoFromRegistry(vecJavaHome)) { - typedef std::vector<OUString>::iterator ItHome; - for(ItHome it_home= vecJavaHome.begin(); it_home != vecJavaHome.end(); - ++it_home) + for (auto const& javaHome : vecJavaHome) { - getAndAddJREInfoByPath(*it_home, allInfos, addedInfos); + getAndAddJREInfoByPath(javaHome, allInfos, addedInfos); } } } @@ -765,13 +761,12 @@ void addJREInfoFromBinPath( if (path.endsWith("/")) sBinPath = path.copy(0, path.getLength() - 1); - typedef vector<OUString>::const_iterator c_it; - for (c_it i = vecPaths.begin(); i != vecPaths.end(); ++i) + for (auto const& looppath : vecPaths) { //the map contains e.g. jre/bin/java.exe //get the directory where the executable is contained OUString sHome; - sal_Int32 index = i->lastIndexOf('/'); + sal_Int32 index = looppath.lastIndexOf('/'); if (index == -1) { //map contained only : "java.exe, then the argument @@ -781,7 +776,7 @@ void addJREInfoFromBinPath( else { // jre/bin/jre -> jre/bin - OUString sMapPath = i->copy(0, index); + OUString sMapPath = looppath.copy(0, index); index = sBinPath.lastIndexOf(sMapPath); if (index != -1 && (index + sMapPath.getLength() == sBinPath.getLength()) @@ -926,8 +921,7 @@ rtl::Reference<VendorBase> getJREInfoByPath( vecPaths = getVectorFromCharArray(arExePaths, size); bool bBreak = false; - typedef vector<OUString>::const_iterator c_it; - for (c_it i = vecPaths.begin(); i != vecPaths.end(); ++i) + for (auto const& looppath : vecPaths) { //if the path is a link, then resolve it //check if the executable exists at all @@ -936,9 +930,9 @@ rtl::Reference<VendorBase> getJREInfoByPath( //sizeof counts the terminating 0 OUString sFullPath; if (path.getLength() == sizeof("file:///") - 1) - sFullPath = sResolvedDir + (*i); + sFullPath = sResolvedDir + looppath; else - sFullPath = sResolvedDir + "/" + (*i); + sFullPath = sResolvedDir + "/" + looppath; sFilePath = resolveFilePath(sFullPath); @@ -1026,14 +1020,13 @@ rtl::Reference<VendorBase> getJREInfoByPath( } //find java.vendor property - typedef vector<pair<OUString, OUString> >::const_iterator c_ip; OUString sVendorName; - for (c_ip i = props.begin(); i != props.end(); ++i) + for (auto const& prop : props) { - if (i->first == "java.vendor") + if (prop.first == "java.vendor") { - sVendorName = i->second; + sVendorName = prop.second; break; } } diff --git a/jvmfwk/plugins/sunmajor/pluginlib/vendorbase.cxx b/jvmfwk/plugins/sunmajor/pluginlib/vendorbase.cxx index b3e5a4c43de2..3a4c65ca0b37 100644 --- a/jvmfwk/plugins/sunmajor/pluginlib/vendorbase.cxx +++ b/jvmfwk/plugins/sunmajor/pluginlib/vendorbase.cxx @@ -58,32 +58,29 @@ bool VendorBase::initialize(vector<pair<OUString, OUString> > props) //get java.vendor, java.version, java.home, //javax.accessibility.assistive_technologies from system properties - typedef vector<pair<OUString, OUString> >::const_iterator it_prop; - bool bVersion = false; bool bVendor = false; bool bHome = false; bool bAccess = false; bool bArch = false; - typedef vector<pair<OUString, OUString> >::const_iterator it_prop; - for (it_prop i = props.begin(); i != props.end(); ++i) + for (auto const& prop : props) { - if(! bVendor && i->first == "java.vendor") + if(! bVendor && prop.first == "java.vendor") { - m_sVendor = i->second; + m_sVendor = prop.second; bVendor = true; } - else if (!bVersion && i->first == "java.version") + else if (!bVersion && prop.first == "java.version") { - m_sVersion = i->second; + m_sVersion = prop.second; bVersion = true; } - else if (!bHome && i->first == "java.home") + else if (!bHome && prop.first == "java.home") { #ifndef JVM_ONE_PATH_CHECK OUString fileURL; - if (osl_getFileURLFromSystemPath(i->second.pData,& fileURL.pData) == + if (osl_getFileURLFromSystemPath(prop.second.pData,& fileURL.pData) == osl_File_E_None) { //make sure that the drive letter have all the same case @@ -96,19 +93,19 @@ bool VendorBase::initialize(vector<pair<OUString, OUString> > props) } } #else - m_sHome = i->second; + m_sHome = prop.second; bHome = true; #endif } - else if (!bArch && i->first == "os.arch") + else if (!bArch && prop.first == "os.arch") { - m_sArch = i->second; + m_sArch = prop.second; bArch = true; } else if (!bAccess - && i->first == "javax.accessibility.assistive_technologies") + && prop.first == "javax.accessibility.assistive_technologies") { - if (!i->second.isEmpty()) + if (!prop.second.isEmpty()) { m_bAccessibility = true; bAccess = true; @@ -130,11 +127,10 @@ bool VendorBase::initialize(vector<pair<OUString, OUString> > props) vector<OUString> libpaths = getVectorFromCharArray(arRtPaths, size); bool bRt = false; - typedef vector<OUString>::const_iterator i_path; - for(i_path ip = libpaths.begin(); ip != libpaths.end(); ++ip) + for (auto const& libpath : libpaths) { //Construct an absolute path to the possible runtime - OUString usRt= m_sHome + *ip; + OUString usRt= m_sHome + libpath; DirectoryItem item; if(DirectoryItem::get(usRt, item) == File::E_None) { @@ -155,9 +151,9 @@ bool VendorBase::initialize(vector<pair<OUString, OUString> > props) bool bLdPath = true; int c = 0; - for(i_path il = ld_paths.begin(); il != ld_paths.end(); ++il, ++c) + for (auto const& ld_path : ld_paths) { - OUString usAbsUrl= m_sHome + *il; + OUString usAbsUrl= m_sHome + ld_path; // convert to system path OUString usSysPath; if(File::getSystemPathFromFileURL(usAbsUrl, usSysPath) == File::E_None) @@ -172,6 +168,7 @@ bool VendorBase::initialize(vector<pair<OUString, OUString> > props) bLdPath = false; break; } + ++c; } return bLdPath; } diff --git a/jvmfwk/source/elements.cxx b/jvmfwk/source/elements.cxx index 1807f636166b..2e1109aa9f69 100644 --- a/jvmfwk/source/elements.cxx +++ b/jvmfwk/source/elements.cxx @@ -493,11 +493,10 @@ void NodeJava::write() const xmlAddChild(vmParameters, nodeCrLf); } - typedef std::vector<OUString>::const_iterator cit; - for (cit i = m_vmParameters->begin(); i != m_vmParameters->end(); ++i) + for (auto const & vmParameter : *m_vmParameters) { xmlNewTextChild(vmParameters, nullptr, reinterpret_cast<xmlChar const *>("param"), - CXmlCharPtr(*i)); + CXmlCharPtr(vmParameter)); //add a new line xmlNode * nodeCrLf = xmlNewText(reinterpret_cast<xmlChar const *>("\n")); xmlAddChild(vmParameters, nodeCrLf); @@ -534,11 +533,10 @@ void NodeJava::write() const xmlAddChild(jreLocationsNode, nodeCrLf); } - typedef std::vector<OUString>::const_iterator cit; - for (cit i = m_JRELocations->begin(); i != m_JRELocations->end(); ++i) + for (auto const & JRELocation : *m_JRELocations) { xmlNewTextChild(jreLocationsNode, nullptr, reinterpret_cast<xmlChar const *>("location"), - CXmlCharPtr(*i)); + CXmlCharPtr(JRELocation)); //add a new line xmlNode * nodeCrLf = xmlNewText(reinterpret_cast<xmlChar const *>("\n")); xmlAddChild(jreLocationsNode, nodeCrLf); @@ -986,10 +984,9 @@ void MergedSettings::merge(const NodeJava & share, const NodeJava & user) ::std::vector< OString> MergedSettings::getVmParametersUtf8() const { ::std::vector< OString> ret; - typedef ::std::vector< OUString>::const_iterator cit; - for (cit i = m_vmParams.begin(); i != m_vmParams.end(); ++i) + for (auto const & vmParam : m_vmParams) { - ret.push_back( OUStringToOString(*i, RTL_TEXTENCODING_UTF8)); + ret.push_back( OUStringToOString(vmParam, RTL_TEXTENCODING_UTF8)); } return ret; } diff --git a/jvmfwk/source/framework.cxx b/jvmfwk/source/framework.cxx index c03a3cac30e3..6da84fb6576f 100644 --- a/jvmfwk/source/framework.cxx +++ b/jvmfwk/source/framework.cxx @@ -263,10 +263,9 @@ javaFrameworkError jfw_startVM( //add the options set by options dialog int index = 2; - typedef std::vector<OString>::const_iterator cit; - for (cit i = vmParams.begin(); i != vmParams.end(); ++i) + for (auto const & vmParam : vmParams) { - arOpt[index].optionString = const_cast<sal_Char*>(i->getStr()); + arOpt[index].optionString = const_cast<sal_Char*>(vmParam.getStr()); arOpt[index].extraInfo = nullptr; index ++; } @@ -342,10 +341,8 @@ javaFrameworkError jfw_findAndSelectJRE(std::unique_ptr<JavaInfo> *pInfo) // save vendors and respective version requirements pair-wise in a vector std::vector<std::pair<OUString, jfw::VersionInfo>> versionInfos; - typedef std::vector<OUString>::const_iterator ciVendor; - for (ciVendor i = vecVendors.begin(); i != vecVendors.end(); ++i) + for (auto const & vendor : vecVendors) { - const OUString & vendor = *i; jfw::VersionInfo versionInfo = aVendorSettings.getVersionInformation(vendor); @@ -407,10 +404,8 @@ javaFrameworkError jfw_findAndSelectJRE(std::unique_ptr<JavaInfo> *pInfo) { //Use every vendor to get Java installations. At the first usable //Java the loop will break - typedef std::vector<OUString>::const_iterator ci_pl; - for (ci_pl i = vecVendors.begin(); i != vecVendors.end(); ++i) + for (auto const & vendor : vecVendors) { - const OUString & vendor = *i; jfw::VersionInfo versionInfo = aVendorSettings.getVersionInformation(vendor); @@ -465,19 +460,16 @@ javaFrameworkError jfw_findAndSelectJRE(std::unique_ptr<JavaInfo> *pInfo) const std::vector<OUString> & vecJRELocations = settings.getJRELocations(); //use every plug-in to determine the JavaInfo objects - for (ci_pl i = vecVendors.begin(); i != vecVendors.end(); ++i) + for (auto const & vendor : vecVendors) { - const OUString & vendor = *i; jfw::VersionInfo versionInfo = aVendorSettings.getVersionInformation(vendor); - typedef std::vector<OUString>::const_iterator citLoc; - for (citLoc it = vecJRELocations.begin(); - it != vecJRELocations.end(); ++it) + for (auto const & JRELocation : vecJRELocations) { std::unique_ptr<JavaInfo> aInfo; javaPluginError err = jfw_plugin_getJavaInfoByPath( - *it, + JRELocation, vendor, versionInfo.sMinVersion, versionInfo.sMaxVersion, @@ -629,10 +621,8 @@ javaFrameworkError jfw_getJavaInfoByPath(OUString const & pPath, std::unique_ptr //Use every plug-in library to determine if the path represents a //JRE. If a plugin recognized it then the loop will break - typedef std::vector<OUString>::const_iterator ci_pl; - for (ci_pl i = vecVendors.begin(); i != vecVendors.end(); ++i) + for (auto const & vendor : vecVendors) { - const OUString & vendor = *i; jfw::VersionInfo versionInfo = aVendorSettings.getVersionInformation(vendor); |