From cc6263718871a241582bdf3db190e81346f38a42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20W=C3=A4ckerlin?= Date: Thu, 3 Apr 2014 11:21:18 +0000 Subject: [PATCH] replaced mrw::Shared by std::shared_ptr; refs #28 --- doc/examples/cardos-demo.cxx | 1 + doc/examples/create-files-demo.cxx | 1 + doc/examples/suisse-id-demo.hxx | 2 +- src/cardos.hxx | 8 ++++---- src/cryptoki.cxx | 1 + src/cryptoki.hxx | 8 ++++---- src/pcsc.hxx | 31 ++++++++---------------------- src/suisseid.hxx | 19 +++++++++--------- 8 files changed, 30 insertions(+), 41 deletions(-) diff --git a/doc/examples/cardos-demo.cxx b/doc/examples/cardos-demo.cxx index 47401c8..900f125 100644 --- a/doc/examples/cardos-demo.cxx +++ b/doc/examples/cardos-demo.cxx @@ -10,6 +10,7 @@ // #include #include +#include #include #include #include diff --git a/doc/examples/create-files-demo.cxx b/doc/examples/create-files-demo.cxx index 8b4a8ef..2ac8872 100644 --- a/doc/examples/create-files-demo.cxx +++ b/doc/examples/create-files-demo.cxx @@ -14,6 +14,7 @@ #include #include +#include #include #include #include diff --git a/doc/examples/suisse-id-demo.hxx b/doc/examples/suisse-id-demo.hxx index dd4bb1e..851a0bb 100644 --- a/doc/examples/suisse-id-demo.hxx +++ b/doc/examples/suisse-id-demo.hxx @@ -18,7 +18,7 @@ class TextualCycle: public suisseid::StatusCycle { public: // just pass the card to parent - TextualCycle(mrw::Shared card): + TextualCycle(std::shared_ptr card): StatusCycle(card) { } diff --git a/src/cardos.hxx b/src/cardos.hxx index ed8ea70..1b19f87 100644 --- a/src/cardos.hxx +++ b/src/cardos.hxx @@ -424,12 +424,12 @@ namespace cardos { Commands() {} /// Initialize with given smart card reader. - Commands(pcsc::shared_ptr::t r): + Commands(std::shared_ptr r): _reader(r) { } /// Set smart card reader. - void reader(pcsc::shared_ptr::t r) { + void reader(std::shared_ptr r) { _reader = r; } @@ -1549,7 +1549,7 @@ namespace cardos { protected: - pcsc::shared_ptr::t _reader; + std::shared_ptr _reader; }; @@ -1557,7 +1557,7 @@ namespace cardos { /// Represents a CardOS Filesystem Object class Object { public: - typedef pcsc::shared_ptr::t Child; + typedef std::shared_ptr Child; typedef std::vector Children; public: Object(const std::string& p): _path(p) {} diff --git a/src/cryptoki.cxx b/src/cryptoki.cxx index f6dd8ef..17c4388 100644 --- a/src/cryptoki.cxx +++ b/src/cryptoki.cxx @@ -8,6 +8,7 @@ #include #include +#include #include #ifndef WIN32 #include diff --git a/src/cryptoki.hxx b/src/cryptoki.hxx index 9c2b8d1..0269b96 100644 --- a/src/cryptoki.hxx +++ b/src/cryptoki.hxx @@ -18,7 +18,8 @@ #include #include #include -#include +#include +#include // for inline implementations only #include @@ -27,7 +28,6 @@ #include // memset #include // assert #include -#include /*! @defgroup gcryptoki C++ Wrapper around Cryptoki API @@ -1903,7 +1903,7 @@ namespace cryptoki { void login(const std::string& pin, CK_USER_TYPE userType=CKU_USER) { CRYPTOLOG("log"); - _login = new Login(*this, pin, userType); + _login = std::shared_ptr(new Login(*this, pin, userType)); } /// Logout from card @@ -1913,7 +1913,7 @@ namespace cryptoki { _login.reset(); } - mrw::Shared _login; + std::shared_ptr _login; //@} diff --git a/src/pcsc.hxx b/src/pcsc.hxx index 1eb17a3..46ed2b2 100644 --- a/src/pcsc.hxx +++ b/src/pcsc.hxx @@ -56,27 +56,12 @@ #include #include +#include #include #include #include -#if __cplusplus > 199711L - namespace pcsc { - template struct shared_ptr { - typedef std::shared_ptr t; - }; - } -#else - #warning Old compiler (pre 2011): using boost as replacement for std - #include - namespace pcsc { - template struct shared_ptr { - typedef boost::shared_ptr t; - }; - } -#endif - /*! @defgroup gpcsc C++ Wrapper around pcsc-lite API This library is a C++ wrapper to the awful pcsc-lite interface. @@ -200,7 +185,7 @@ namespace pcsc { /*! @note Please note that the Reader is required in the destructor und must therefore live longer than the Transaction instance. */ - Transaction(shared_ptr::t r): + Transaction(std::shared_ptr r): _reader(r), _running(true) { CRYPTOLOG("log"); _reader->beginTransaction(); @@ -218,7 +203,7 @@ namespace pcsc { _running = false; } private: - shared_ptr::t _reader; + std::shared_ptr _reader; bool _running; }; @@ -422,7 +407,7 @@ namespace pcsc { friend class Connection; //! Establishes a connection to the given named cardreader - Reader(const std::string& nm, shared_ptr::t c, + Reader(const std::string& nm, std::shared_ptr c, DWORD mode=SCARD_SHARE_SHARED, DWORD protocol=SCARD_PROTOCOL_T1): name(nm), _connection(c) { @@ -439,7 +424,7 @@ namespace pcsc { //...........................................................variables private: - shared_ptr::t _connection; + std::shared_ptr _connection; SCARDHANDLE _id; DWORD _state; DWORD _protocol; @@ -514,12 +499,12 @@ namespace pcsc { //! Get a reader, open a connection if not already open. /*! First use scan() to get a list of readers, then open a connection to the reader, then access it. */ - static shared_ptr::t reader(const std::string& name, + static std::shared_ptr reader(const std::string& name, Scope s=USER, bool exceptions=true) { CRYPTOLOG("get reader: "<::t + return std::shared_ptr (new Reader(name, - shared_ptr::t + std::shared_ptr (new Connection(s, exceptions)))); } diff --git a/src/suisseid.hxx b/src/suisseid.hxx index e3a846f..c8b898c 100644 --- a/src/suisseid.hxx +++ b/src/suisseid.hxx @@ -12,7 +12,8 @@ #include #include #include -#include +#include +#include /*! @defgroup gsuisseid C++ library to access SuisseID smart cards @@ -185,7 +186,7 @@ namespace suisseid { /** Instance requires a connenction to the reader an a cryptoky library. This is passes automatically when this class is instanciated through suisseid::Scanner. */ - Card(mrw::Shared reader, + Card(std::shared_ptr reader, const cryptoki::Library& cryptoki): cardos::Commands(reader), _cryptoki(cryptoki) { @@ -205,7 +206,7 @@ namespace suisseid { pcsc::Connection::Reader::Transaction lock(card.reader()); [... do some low level stuff ...] @endcode */ - mrw::Shared reader() { + std::shared_ptr reader() { return _reader; } @@ -290,7 +291,7 @@ namespace suisseid { public: /// @copydoc Card::Card - Post(mrw::Shared reader, + Post(std::shared_ptr reader, const cryptoki::Library& cryptoki): Card(reader, cryptoki), _minPinLen(0), _maxPinLen(0) { } @@ -368,7 +369,7 @@ namespace suisseid { }; //! List of cards, returned by @ref suisseid::Scanner::scan. - typedef std::vector > Cards; + typedef std::vector > Cards; //! Auxiliary SuisseID card manager. /** Use this manager to scan your system for SuisseID cards. @@ -418,7 +419,7 @@ namespace suisseid { CRYPTOLOG("number of cryptoki-readers for "<<*reader <<": "< + res.push_back(std::shared_ptr (new Post(pcsc::Connection::reader(*reader), _cryptoki))); } @@ -435,7 +436,7 @@ namespace suisseid { public: - StatusCycle(mrw::Shared card, unsigned int maxRetries = 20): + StatusCycle(std::shared_ptr card, unsigned int maxRetries = 20): _card(card), _maxRetries(maxRetries), _counter(0) { } @@ -449,7 +450,7 @@ namespace suisseid { protected: - mrw::Shared card() { + std::shared_ptr card() { return _card; } @@ -595,7 +596,7 @@ namespace suisseid { return start(); } - mrw::Shared _card; + std::shared_ptr _card; unsigned int _maxRetries; unsigned int _counter;