From 9ac199f11b18886c9a12bc25feac7193e51d5aed Mon Sep 17 00:00:00 2001 From: Jean-Paul Chaput Date: Sun, 7 Jun 2015 11:05:01 +0200 Subject: [PATCH] Change in policy for duplicate libraries. * Change: In CRL Core, replace duplicated libraries, even when performing a Append/Prepend operation. Also correct a bug in library name uniquification, event if it's no used. The policy in cas of duplicate libraries is not completly clear for me, still. --- crlcore/src/ccore/AllianceFramework.cpp | 4 +-- crlcore/src/ccore/Environment.cpp | 10 +++++-- crlcore/src/ccore/SearchPath.cpp | 37 +++++++++++-------------- crlcore/src/ccore/crlcore/SearchPath.h | 24 ++++++++-------- 4 files changed, 37 insertions(+), 38 deletions(-) diff --git a/crlcore/src/ccore/AllianceFramework.cpp b/crlcore/src/ccore/AllianceFramework.cpp index 581c1b46..847517f6 100644 --- a/crlcore/src/ccore/AllianceFramework.cpp +++ b/crlcore/src/ccore/AllianceFramework.cpp @@ -336,8 +336,8 @@ namespace CRL { AllianceLibrary* library = getAllianceLibrary ( dupLibName, flags ); if (library == NULL) break; - ostringstream oss (libName); - oss << "." << duplicate; + ostringstream oss; + oss << libName << "." << duplicate; dupLibName = oss.str(); } diff --git a/crlcore/src/ccore/Environment.cpp b/crlcore/src/ccore/Environment.cpp index 4cb2b5f6..9bc6bcc6 100644 --- a/crlcore/src/ccore/Environment.cpp +++ b/crlcore/src/ccore/Environment.cpp @@ -702,8 +702,14 @@ namespace CRL { void Environment::addSYSTEM_LIBRARY ( const char* value, const char* libName, unsigned int mode ) { - if ( mode == Prepend ) { _LIBRARIES.prepend(value,libName); return; } - if ( mode == Append ) { _LIBRARIES.append (value,libName); return; } + if ((mode == Prepend) or (mode == Append)) { + size_t duplicate = _LIBRARIES.hasLib(libName); + if (duplicate != SearchPath::npos) _LIBRARIES.remove( duplicate ); + + if (mode == Prepend) _LIBRARIES.prepend(value,libName); + if (mode == Append ) _LIBRARIES.append (value,libName); + return; + } string newLibName = libName; for ( size_t i=0 ; i < _LIBRARIES.getSize() ; ++i ) { diff --git a/crlcore/src/ccore/SearchPath.cpp b/crlcore/src/ccore/SearchPath.cpp index e09119e1..260308b3 100644 --- a/crlcore/src/ccore/SearchPath.cpp +++ b/crlcore/src/ccore/SearchPath.cpp @@ -1,15 +1,9 @@ - // -*- C++ -*- // // This file is part of the Coriolis Software. -// Copyright (c) UPMC/LIP6 2008-2010, All Rights Reserved +// Copyright (c) UPMC 2008-2015, All Rights Reserved // -// =================================================================== -// -// $Id$ -// -// x-----------------------------------------------------------------x -// | | +// +-----------------------------------------------------------------+ // | C O R I O L I S | // | Alliance / Hurricane Interface | // | | @@ -17,21 +11,10 @@ // | E-mail : Jean-Paul.Chaput@asim.lip6.fr | // | =============================================================== | // | C++ Module : "./SearchPath.cpp" | -// | *************************************************************** | -// | U p d a t e s | -// | | -// x-----------------------------------------------------------------x +// +-----------------------------------------------------------------+ -# include "crlcore/SearchPath.h" - - -namespace { - - using namespace std; - - -} // End of anonymous namespace. +#include "crlcore/SearchPath.h" namespace CRL { @@ -106,6 +89,10 @@ namespace CRL { } + void SearchPath::remove ( size_t index ) + { if (index < _paths.size()) _paths.erase( _paths.begin()+index ); } + + void SearchPath::select ( const string& path ) { for ( size_t ipath=0 ; ipath < _paths.size() ; ++ipath ) { @@ -143,6 +130,14 @@ namespace CRL { } + size_t SearchPath::hasLib ( const string& name ) const + { + for ( size_t i=0 ; i < _paths.size() ; i++ ) + if ( _paths[i].getName() == name ) return i; + return npos; + } + + const SearchPath::Element& SearchPath::operator[] ( size_t index ) const { static Element nullElement; diff --git a/crlcore/src/ccore/crlcore/SearchPath.h b/crlcore/src/ccore/crlcore/SearchPath.h index 5da20363..2b315e79 100644 --- a/crlcore/src/ccore/crlcore/SearchPath.h +++ b/crlcore/src/ccore/crlcore/SearchPath.h @@ -1,8 +1,7 @@ - // -*- C++ -*- // // This file is part of the Coriolis Software. -// Copyright (c) UPMC/LIP6 2008-2012, All Rights Reserved +// Copyright (c) UPMC 2008-2015, All Rights Reserved // // +-----------------------------------------------------------------+ // | C O R I O L I S | @@ -15,20 +14,17 @@ // +-----------------------------------------------------------------+ -#ifndef __CRL_SEARCH_PATH__ -# define __CRL_SEARCH_PATH__ +#ifndef CRL_SEARCH_PATH_H +#define CRL_SEARCH_PATH_H - -#include -#include - -#include "hurricane/Commons.h" -#include "hurricane/Slot.h" +#include +#include +#include "hurricane/Commons.h" +#include "hurricane/Slot.h" namespace CRL { - using Hurricane::Record; using Hurricane::_TName; @@ -57,6 +53,7 @@ namespace CRL { inline void append ( const std::string& path, const std::string& name="" ); void prepend ( const std::string& path, const std::string& name=""); void replace ( const std::string& path, const std::string&, size_t index ); + void remove ( size_t index ); size_t locate ( const std::string& file , std::ios::openmode mode =std::ios::in , int first=0 @@ -66,6 +63,7 @@ namespace CRL { inline const std::string& getSelected () const; inline size_t getIndex () const; inline bool hasSelected () const; + size_t hasLib ( const std::string& name ) const; size_t hasPath ( const std::string& path ) const; const Element& operator[] ( size_t index ) const; private: @@ -109,11 +107,11 @@ namespace CRL { inline std::string SearchPath::Element::_getTypeName () const { return "SearchPath::Element"; } -} // End of CRL namespace. +} // CRL namespace. INSPECTOR_P_SUPPORT(CRL::SearchPath); INSPECTOR_V_SUPPORT(CRL::SearchPath::Element); -# endif +#endif // CRL_SEARCH_PATH_H