* ./crlcore/src/crlcore:

- New: In Environment, adds a method getLIBRARYPath() to directly access the
        path of an element in the SearchPath. Also added to the Python interface.
          This is a quick alternative to fully export SearchPath and it's element
        into the Python interface.
This commit is contained in:
Jean-Paul Chaput 2013-09-16 08:28:24 +00:00
parent c5270ec605
commit 766132a2da
3 changed files with 48 additions and 27 deletions

View File

@ -2,7 +2,7 @@
// -*- C++ -*- // -*- C++ -*-
// //
// This file is part of the Coriolis Software. // This file is part of the Coriolis Software.
// Copyright (c) UPMC/LIP6 2008-2012, All Rights Reserved // Copyright (c) UPMC 2008-2013, All Rights Reserved
// //
// +-----------------------------------------------------------------+ // +-----------------------------------------------------------------+
// | C O R I O L I S | // | C O R I O L I S |
@ -15,16 +15,14 @@
// +-----------------------------------------------------------------+ // +-----------------------------------------------------------------+
#include <cctype> #include <cctype>
#include <cstdlib> #include <cstdlib>
#include <map> #include <map>
#include <iomanip> #include <iomanip>
#include <QXmlStreamReader>
#include <QXmlStreamReader> #include "crlcore/Utilities.h"
#include "crlcore/XmlParser.h"
#include "crlcore/Utilities.h" #include "crlcore/Environment.h"
#include "crlcore/XmlParser.h"
#include "crlcore/Environment.h"
namespace { namespace {
@ -750,6 +748,13 @@ namespace CRL {
} }
string Environment::getLIBRARYPath ( size_t i )
{
if (i >= _LIBRARIES.getSize()) return "";
return _LIBRARIES[i].getPath();
}
string Environment::_getString () const string Environment::_getString () const
{ return "<Environment>"; } { return "<Environment>"; }

View File

@ -2,7 +2,7 @@
// -*- C++ -*- // -*- C++ -*-
// //
// This file is part of the Coriolis Software. // This file is part of the Coriolis Software.
// Copyright (c) UPMC/LIP6 2008-2012, All Rights Reserved // Copyright (c) UPMC 2008-2013, All Rights Reserved
// //
// +-----------------------------------------------------------------+ // +-----------------------------------------------------------------+
// | C O R I O L I S | // | C O R I O L I S |
@ -15,13 +15,12 @@
// +-----------------------------------------------------------------+ // +-----------------------------------------------------------------+
#ifndef __CRL_ENVIRONMENT__ #ifndef CRL_ENVIRONMENT
#define __CRL_ENVIRONMENT__ #define CRL_ENVIRONMENT
#include <regex.h> #include <regex.h>
#include <string>
#include <string> #include <crlcore/SearchPath.h>
#include <crlcore/SearchPath.h>
namespace CRL { namespace CRL {
@ -30,14 +29,12 @@ namespace CRL {
class Environment { class Environment {
public: public:
enum AddMode { Append=1, Prepend=2, Replace=3 }; enum AddMode { Append=1, Prepend=2, Replace=3 };
public: public:
// Internal: Static Methods. // Internal: Static Methods.
static const char* getEnv ( const char* variable, const char* defaultValue ); static const char* getEnv ( const char* variable, const char* defaultValue );
// Constructors & destructors. // Constructors & destructors.
Environment (); Environment ();
~Environment (); ~Environment ();
// Accessors. // Accessors.
inline const std::string& getCORIOLIS_TOP () const; inline const std::string& getCORIOLIS_TOP () const;
inline const std::string& getDisplayStyle () const; inline const std::string& getDisplayStyle () const;
@ -56,14 +53,13 @@ namespace CRL {
inline const std::string& getPad () const; inline const std::string& getPad () const;
inline const std::string& getCATALOG () const; inline const std::string& getCATALOG () const;
inline SearchPath& getLIBRARIES (); inline SearchPath& getLIBRARIES ();
std::string getLIBRARYPath ( size_t i );
// Predicates. // Predicates.
bool isPOWER ( const char* name ) const; bool isPOWER ( const char* name ) const;
bool isGROUND ( const char* name ) const; bool isGROUND ( const char* name ) const;
bool isCLOCK ( const char* name ) const; bool isCLOCK ( const char* name ) const;
bool isBLOCKAGE ( const char* name ) const; bool isBLOCKAGE ( const char* name ) const;
bool isPad ( const char* name ) const; bool isPad ( const char* name ) const;
// Modifiers. // Modifiers.
void validate () const; void validate () const;
void loadFromXml ( const std::string& path="", bool warnNotFound=true ); void loadFromXml ( const std::string& path="", bool warnNotFound=true );
@ -85,13 +81,11 @@ namespace CRL {
inline void setCATALOG ( const char* value ); inline void setCATALOG ( const char* value );
inline void setWORKING_LIBRARY ( const char* value ); inline void setWORKING_LIBRARY ( const char* value );
void addSYSTEM_LIBRARY ( const char* value, const char* libName, unsigned int mode=Append ); void addSYSTEM_LIBRARY ( const char* value, const char* libName, unsigned int mode=Append );
// Methods. // Methods.
std::string getPrint () const; std::string getPrint () const;
inline std::string _getTypeName () const; inline std::string _getTypeName () const;
std::string _getString () const; std::string _getString () const;
Record* _getRecord () const; Record* _getRecord () const;
protected: protected:
// Internal: Attributes. // Internal: Attributes.
std::string _CORIOLIS_TOP; std::string _CORIOLIS_TOP;
@ -117,7 +111,6 @@ namespace CRL {
regex_t _BlockageRegex; regex_t _BlockageRegex;
regex_t _padRegex; regex_t _padRegex;
bool _inConstructor; bool _inConstructor;
private: private:
void _setRegex ( regex_t* regex, const std::string& pattern, const char* name ); void _setRegex ( regex_t* regex, const std::string& pattern, const char* name );
}; };
@ -156,10 +149,10 @@ namespace CRL {
inline std::string Environment::_getTypeName () const { return "Environment"; } inline std::string Environment::_getTypeName () const { return "Environment"; }
} // End of CRL namespace. } // CRL namespace.
INSPECTOR_P_SUPPORT(CRL::Environment); INSPECTOR_P_SUPPORT(CRL::Environment);
# endif #endif

View File

@ -154,6 +154,27 @@ extern "C" {
} }
PyObject* PyEnvironment_getLIBRARYPath ( PyEnvironment* self, PyObject* args )
{
trace << "PyEnvironment_getLIBRARYPath()" << endl;
HTRY
METHOD_HEAD("Environment.getLIBRARYPath()")
int index = 0;
if (PyArg_ParseTuple( args, "i:Environment.addLIBRARYPath", &index )) {
string path = env->getLIBRARYPath( index );
if (path.size()) return Py_BuildValue( "s", path.c_str() );
} else {
PyErr_SetString( ConstructorError, "invalid number of parameters for Environment.getLIBRARYPath." );
return NULL;
}
HCATCH
Py_RETURN_NONE;
}
static PyObject* PyEnvironment_Repr ( PyEnvironment* self ) static PyObject* PyEnvironment_Repr ( PyEnvironment* self )
{ {
if ( self->ACCESS_OBJECT == NULL ) if ( self->ACCESS_OBJECT == NULL )
@ -245,6 +266,8 @@ extern "C" {
, "Gets the pad cell recognition regular expression." } , "Gets the pad cell recognition regular expression." }
, { "getCATALOG" , (PyCFunction)PyEnvironment_getCATALOG , METH_NOARGS , { "getCATALOG" , (PyCFunction)PyEnvironment_getCATALOG , METH_NOARGS
, "Gets the catalog file name." } , "Gets the catalog file name." }
, { "getLIBRARYPath" , (PyCFunction)PyEnvironment_getLIBRARYPath , METH_VARARGS
, "Gets the path of the library at the given index." }
, { "getPrint" , (PyCFunction)PyEnvironment_getPrint , METH_NOARGS , { "getPrint" , (PyCFunction)PyEnvironment_getPrint , METH_NOARGS
, "Display the environment in a terminal fashion formating." } , "Display the environment in a terminal fashion formating." }
, { "isPOWER" , (PyCFunction)PyEnvironment_isPOWER , METH_VARARGS , { "isPOWER" , (PyCFunction)PyEnvironment_isPOWER , METH_VARARGS