diff options
| author | Vincent Richard <[email protected]> | 2004-12-26 21:23:29 +0100 |
|---|---|---|
| committer | Vincent Richard <[email protected]> | 2004-12-26 21:23:29 +0100 |
| commit | 4ce991d3b1bd97fbb896d17fb8f36f6650429a22 (patch) | |
| tree | 2db6e072b862dd809d4acd8c571a1b859fdcb484 /src/utility | |
| parent | Allow creating a service from an URL. (diff) | |
| download | vmime-4ce991d3b1bd97fbb896d17fb8f36f6650429a22.tar.gz vmime-4ce991d3b1bd97fbb896d17fb8f36f6650429a22.zip | |
Moved all header files to 'vmime/' directory.
Diffstat (limited to 'src/utility')
| -rw-r--r-- | src/utility/file.hpp | 257 | ||||
| -rw-r--r-- | src/utility/md5.cpp | 2 | ||||
| -rw-r--r-- | src/utility/md5.hpp | 68 | ||||
| -rw-r--r-- | src/utility/path.cpp | 2 | ||||
| -rw-r--r-- | src/utility/path.hpp | 161 | ||||
| -rw-r--r-- | src/utility/random.cpp | 4 | ||||
| -rw-r--r-- | src/utility/random.hpp | 77 | ||||
| -rw-r--r-- | src/utility/singleton.cpp | 2 | ||||
| -rw-r--r-- | src/utility/singleton.hpp | 92 | ||||
| -rw-r--r-- | src/utility/smartPtr.hpp | 166 | ||||
| -rw-r--r-- | src/utility/stream.cpp | 4 | ||||
| -rw-r--r-- | src/utility/stream.hpp | 274 | ||||
| -rw-r--r-- | src/utility/stringProxy.cpp | 2 | ||||
| -rw-r--r-- | src/utility/stringProxy.hpp | 90 | ||||
| -rw-r--r-- | src/utility/stringUtils.cpp | 2 | ||||
| -rw-r--r-- | src/utility/stringUtils.hpp | 131 |
16 files changed, 9 insertions, 1325 deletions
diff --git a/src/utility/file.hpp b/src/utility/file.hpp deleted file mode 100644 index 6697d3d7..00000000 --- a/src/utility/file.hpp +++ /dev/null @@ -1,257 +0,0 @@ -// -// VMime library (http://vmime.sourceforge.net) -// Copyright (C) 2002-2004 Vincent Richard <[email protected]> -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License as -// published by the Free Software Foundation; either version 2 of -// the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -// - -#ifndef VMIME_UTILITY_FILE_HPP_INCLUDED -#define VMIME_UTILITY_FILE_HPP_INCLUDED - - -#include "config.hpp" - -#include "utility/path.hpp" -#include "utility/stream.hpp" - - -#if VMIME_HAVE_FILESYSTEM_FEATURES - - -namespace vmime { -namespace utility { - - -class file; - - -/** File list iterator (see file::getFiles). - */ - -class fileIterator -{ -public: - - virtual ~fileIterator() { } - - /** Check whether the cursor has reach the end of the list. - * - * @return true if you can call nextElement(), or false - * if no more file is available - */ - virtual const bool hasMoreElements() const = 0; - - /** Return the next file in the list. - * - * @return next file or NULL - */ - virtual file* nextElement() = 0; -}; - - -/** Write to a file. - */ - -class fileWriter -{ -public: - - virtual ~fileWriter() { } - - virtual utility::outputStream* getOutputStream() = 0; -}; - - -/** Read from a file. - */ - -class fileReader -{ -public: - - virtual ~fileReader() { } - - virtual utility::inputStream* getInputStream() = 0; -}; - - -/** Abstract representation of a file or directory. - */ - -class file -{ -public: - - typedef utility::path path; - typedef unsigned long length_type; - - - virtual ~file() { } - - - /** Create the file pointed by this file object. - * - * @throw exceptions::filesystem_exception if an error occurs - */ - virtual void createFile() = 0; - - /** Create the directory pointed by this file object. - * - * @param createAll if set to true, recursively create all - * parent directories if they do not exist - * @throw exceptions::filesystem_exception if an error occurs - */ - virtual void createDirectory(const bool createAll = false) = 0; - - /** Test whether this is a file. - * - * @return true if this is a file, false otherwise - */ - virtual const bool isFile() const = 0; - - /** Test whether this is a directory. - * - * @return true if this is a directory, false otherwise - */ - virtual const bool isDirectory() const = 0; - - /** Test whether this file is readible. - * - * @return true if we can read this file, false otherwise - */ - virtual const bool canRead() const = 0; - - /** Test whether this file is writeable. - * - * @return true if we can write to this file, false otherwise - */ - virtual const bool canWrite() const = 0; - - /** Return the length of this file. - * - * @return file size (in bytes) - */ - virtual const length_type getLength() = 0; - - /** Return the full path of this file/directory. - * - * @return full path of the file - */ - virtual const path& getFullPath() const = 0; - - /** Test whether this file/directory exists. - * - * @return true if the file exists, false otherwise - */ - virtual const bool exists() const = 0; - - /** Return the parent directory of this file/directory. - * - * @return parent directory (or NULL if root) - */ - virtual const file* getParent() const = 0; - - /** Rename the file/directory. - * - * @param newName full path of the new file - * @throw exceptions::filesystem_exception if an error occurs - */ - virtual void rename(const path& newName) = 0; - - /** Deletes this file/directory. - * If this is a directory, it must be empty. - * - * @throw exceptions::filesystem_exception if an error occurs - */ - virtual void remove() = 0; - - /** Return an object capable of writing to this file. - * - * @return file writer object - */ - virtual fileWriter* getFileWriter() = 0; - - /** Return an object capable of reading from this file. - * - * @return file reader object - */ - virtual fileReader* getFileReader() = 0; - - /** Enumerate files contained in this directory. - * - * @return file iterator to enumerate files - * @throw exceptions::not_a_directory if this is not a directory, - * exceptions::filesystem_exception if another error occurs - */ - virtual fileIterator* getFiles() const = 0; -}; - - -/** Constructs 'file' objects. - */ - -class fileSystemFactory -{ -public: - - virtual ~fileSystemFactory() { } - - /** Create a new file object from the specified path. - * - * @param path full path (absolute) of the file - * @return new file object for the path - */ - virtual file* create(const file::path& path) const = 0; - - /** Parse a path contained in a string. - * - * @param str string containing a path in a system-dependant representation - * @return path object (abstract representation) - */ - virtual const file::path stringToPath(const string& str) const = 0; - - /** Return the system-dependant string representation for the specified path. - * - * @param path abstract representation of the path - * @return string representation of the path - */ - virtual const string pathToString(const file::path& path) const = 0; - - /** Test whether the specified path component is syntactically - * valid (ie: does not contain any 'special' character). - * - * @param comp path component to test - * @return true if the component is valid, false otherwise - */ - virtual const bool isValidPathComponent(const file::path::component& comp) const = 0; - - /** Test whether the specified path is syntactically valid - * (ie: components do not contain any 'special' character). - * - * @param path path to test - * @return true if the path is valid, false otherwise - */ - virtual const bool isValidPath(const file::path& path) const = 0; -}; - - -} // utility -} // vmime - - -#endif // VMIME_HAVE_FILESYSTEM_FEATURES - - -#endif // VMIME_UTILITY_FILE_HPP_INCLUDED diff --git a/src/utility/md5.cpp b/src/utility/md5.cpp index 9a1d4129..53bf17ae 100644 --- a/src/utility/md5.cpp +++ b/src/utility/md5.cpp @@ -44,7 +44,7 @@ // These notices must be retained in any copies of any part of this // documentation and/or software. -#include "utility/md5.hpp" +#include "vmime/utility/md5.hpp" namespace vmime { diff --git a/src/utility/md5.hpp b/src/utility/md5.hpp deleted file mode 100644 index dc9bb384..00000000 --- a/src/utility/md5.hpp +++ /dev/null @@ -1,68 +0,0 @@ -// -// VMime library (http://vmime.sourceforge.net) -// Copyright (C) 2002-2004 Vincent Richard <[email protected]> -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License as -// published by the Free Software Foundation; either version 2 of -// the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -// - -#ifndef VMIME_UTILITY_MD5_HPP_INCLUDED -#define VMIME_UTILITY_MD5_HPP_INCLUDED - - -#include "base.hpp" -#include "config.hpp" - - -namespace vmime { -namespace utility { - - -class md5 -{ -public: - - md5(); - md5(const vmime_uint8* const in, const unsigned long length); - md5(const string& in); - -public: - - const string hex(); - const vmime_uint8* hash(); - - void update(const vmime_uint8* data, unsigned long len); - void update(const string& in); - -protected: - - void init(); - void transformHelper(); - void transform(); - void finalize(); - - vmime_uint32 m_hash[4]; - - unsigned long m_byteCount; - vmime_uint8 m_block[64]; - - bool m_finalized; -}; - - -} // utility -} // vmime - - -#endif // VMIME_UTILITY_MD5_HPP_INCLUDED diff --git a/src/utility/path.cpp b/src/utility/path.cpp index 6455145d..b7651615 100644 --- a/src/utility/path.cpp +++ b/src/utility/path.cpp @@ -17,7 +17,7 @@ // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // -#include "utility/path.hpp" +#include "vmime/utility/path.hpp" #include <algorithm> diff --git a/src/utility/path.hpp b/src/utility/path.hpp deleted file mode 100644 index 01e78935..00000000 --- a/src/utility/path.hpp +++ /dev/null @@ -1,161 +0,0 @@ -// -// VMime library (http://vmime.sourceforge.net) -// Copyright (C) 2002-2004 Vincent Richard <[email protected]> -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License as -// published by the Free Software Foundation; either version 2 of -// the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -// - -#ifndef VMIME_UTILITY_PATH_HPP_INCLUDED -#define VMIME_UTILITY_PATH_HPP_INCLUDED - - -#include <vector> - -#include "types.hpp" -#include "word.hpp" - - -namespace vmime { -namespace utility { - - -/** Abstract representation of a path (filesystem, mailbox, etc). - */ - -class path -{ -public: - - typedef vmime::word component; - typedef std::vector <component> list; - - // Construct a path - path(); - path(const component& c); - path(const path& p); - path(const string& s); - - // Append a component to a path - path operator/(const path& p) const; - path operator/(const component& c) const; - - path& operator/=(const path& p); - path& operator/=(const component& c); - - // Return the parent path - path getParent() const; - - // Assignment - path& operator=(const path& p); - path& operator=(const component& c); - - // Path comparison - const bool operator==(const path& p) const; - const bool operator!=(const path& p) const; - - /** Append a component to the path. - * - * @param c component to add - */ - void appendComponent(const component& c); - - /** Return the component at the specified position. - * - * @param pos position - * @return component at position 'pos' - */ - const component& getComponentAt(const int pos) const; - - /** Return the component at the specified position. - * - * @param pos position - * @return component at position 'pos' - */ - component& getComponentAt(const int pos); - - /** Test whether this path is empty (root). - * - * @return true if the path is empty (no components = root) - */ - const bool isEmpty() const; - - /** Return the last component of this path (const version). - * - * @return last component - */ - const component getLastComponent() const; - - /** Return the last component of this path (non-const version). - * - * @return last component - */ - component& getLastComponent(); - - /** Return the number of components in this path. - * - * @return number of components - */ - const int getSize() const; - - /** Return the specified component of the path (const version). - * - * @param x index of the component - * @return component at the specified index - */ - const component& operator[](const int x) const; - - /** Return the specified component of the path (non-const version). - * - * @param x index of the component - * @return component at the specified index - */ - component& operator[](const int x); - - /** Test whether this path is a direct parent of another one. - * - * @param p other path - * @return true if the specified path is a child - * of this path, false otherwise - */ - const bool isDirectParentOf(const path& p) const; - - /** Test whether this path is a parent of another one. - * - * @param p other path - * @return true if the specified path is a child (direct or - * indirect) of this path, false otherwise - */ - const bool isParentOf(const path& p) const; - - /** Rename a parent component in the path. - * Example: path("a/b/c/d").renameParent("a/b", "x/y/z") - * will return path("x/y/z/c/d"). - * - * @param oldPath old parent path - * @param newPath new parent path - */ - void renameParent(const path& oldPath, const path& newPath); - -private: - - list m_list; -}; - - -} // utility -} // vmime - - -#endif // VMIME_UTILITY_PATH_HPP_INCLUDED diff --git a/src/utility/random.cpp b/src/utility/random.cpp index 43e5703c..7c82d78c 100644 --- a/src/utility/random.cpp +++ b/src/utility/random.cpp @@ -17,8 +17,8 @@ // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // -#include "utility/random.hpp" -#include "platformDependant.hpp" +#include "vmime/utility/random.hpp" +#include "vmime/platformDependant.hpp" #include <ctime> diff --git a/src/utility/random.hpp b/src/utility/random.hpp deleted file mode 100644 index 442905a5..00000000 --- a/src/utility/random.hpp +++ /dev/null @@ -1,77 +0,0 @@ -// -// VMime library (http://vmime.sourceforge.net) -// Copyright (C) 2002-2004 Vincent Richard <[email protected]> -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License as -// published by the Free Software Foundation; either version 2 of -// the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -// - -#ifndef VMIME_UTILITY_RANDOM_HPP_INCLUDED -#define VMIME_UTILITY_RANDOM_HPP_INCLUDED - - -#include "types.hpp" - - -namespace vmime { -namespace utility { - - -/** Pseudo-random number generator. - */ - -class random -{ -public: - - /** Return a new random number. - * - * @return random number - */ - static const unsigned int getNext(); - - /** Return the current time as a number (may be used to - * build "random" strings). - * - * @return time as a number - */ - static const unsigned int getTime(); - - /** Return the current process number (may be user to - * build "random" strings). - * - * @return process number - */ - static const unsigned int getProcess(); - - /** Return a random character string with the specified length. - * - * @param length length of the string to generate - * @param randomChars list of characters to use - * @return random string - */ - static const string getString(const int length, const string& randomChars - = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"); - -protected: - - static unsigned int m_next; -}; - - -} // utility -} // vmime - - -#endif // VMIME_UTILITY_RANDOM_HPP_INCLUDED diff --git a/src/utility/singleton.cpp b/src/utility/singleton.cpp index c960a64a..a429c41f 100644 --- a/src/utility/singleton.cpp +++ b/src/utility/singleton.cpp @@ -17,7 +17,7 @@ // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // -#include "singleton.hpp" +#include "vmime/utility/singleton.hpp" namespace vmime { diff --git a/src/utility/singleton.hpp b/src/utility/singleton.hpp deleted file mode 100644 index 33def75b..00000000 --- a/src/utility/singleton.hpp +++ /dev/null @@ -1,92 +0,0 @@ -// -// VMime library (http://vmime.sourceforge.net) -// Copyright (C) 2002-2004 Vincent Richard <[email protected]> -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License as -// published by the Free Software Foundation; either version 2 of -// the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -// - -#ifndef VMIME_UTILITY_SINGLETON_HPP_INCLUDED -#define VMIME_UTILITY_SINGLETON_HPP_INCLUDED - - -#include <list> - - -namespace vmime { -namespace utility { - - -// Singleton abstract base class. - -class abstractSingleton -{ - friend class singletonManager; - -protected: - - abstractSingleton() { } - virtual ~abstractSingleton() { } -}; - - -// Singleton manager -// (for automatic clean-up of all instanciated singletons). - -class singletonManager -{ -public: - - static singletonManager* getInstance(); - - void manage(abstractSingleton* s); - -private: - - singletonManager(); - ~singletonManager(); - - std::list <abstractSingleton*> m_list; -}; - - -// A singleton template. - -template <class TYPE> -class singleton : public abstractSingleton -{ -protected: - - singleton() { } - ~singleton() { } - -public: - - static TYPE* getInstance() - { - static TYPE* inst = NULL; - - if (!inst) - singletonManager::getInstance()->manage(inst = new TYPE()); - - return (inst); - } -}; - - -} // utility -} // vmime - - -#endif // VMIME_UTILITY_SINGLETON_HPP_INCLUDED diff --git a/src/utility/smartPtr.hpp b/src/utility/smartPtr.hpp deleted file mode 100644 index 9905ae2f..00000000 --- a/src/utility/smartPtr.hpp +++ /dev/null @@ -1,166 +0,0 @@ -// -// VMime library (http://vmime.sourceforge.net) -// Copyright (C) 2002-2004 Vincent Richard <[email protected]> -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License as -// published by the Free Software Foundation; either version 2 of -// the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -// - -#ifndef VMIME_UTILITY_SMARTPTR_HPP_INCLUDED -#define VMIME_UTILITY_SMARTPTR_HPP_INCLUDED - - -namespace vmime { -namespace utility { - - -/** Simple auto-delete pointer. - */ - -template <class T> -class auto_ptr -{ -private: - - T* const m_ptr; - -public: - - auto_ptr(T* const ptr) : m_ptr(ptr) { } - ~auto_ptr() { delete (m_ptr); } - - operator T*() { return (m_ptr); } - - T* const operator ->() { return (m_ptr); } - T& operator *() { return (*m_ptr); } -}; - - -/** Smart auto-delete, referencable and copiable pointer. - */ - -template <class T> -class smart_ptr -{ -private: - - struct data - { - int refCount; - T* ptr; - }; - - data* m_data; - - - typedef std::map <T*, data*> MapType; - static MapType sm_map; - -public: - - smart_ptr() : m_data(NULL) { } - smart_ptr(T* const ptr) : m_data(NULL) { if (ptr) { attach(ptr); } } - smart_ptr(smart_ptr& ptr) : m_data(NULL) { if (ptr.m_data) { attach(ptr); } } - - ~smart_ptr() { detach(); } - - smart_ptr& operator=(smart_ptr& ptr) - { - attach(ptr); - return (*this); - } - - smart_ptr& operator=(T* const ptr) - { - if (!ptr) - detach(); - else - attach(ptr); - - return (*this); - } - - operator T*() { return (m_data ? m_data->ptr : NULL); } - operator const T*() { return (m_data ? m_data->ptr : NULL); } - - T& operator *() { return (*(m_data->ptr)); } - T* operator ->() { return (m_data->ptr); } - - const T* const ptr() const { return (m_data ? m_data->ptr : NULL); } - T* const ptr() { return (m_data ? m_data->ptr : NULL); } - -private: - - void detach() - { - if (m_data) - { - if (m_data->refCount == 1) - { - typename MapType::iterator it = sm_map.find(m_data->ptr); - if (it != sm_map.end()) sm_map.erase(it); - - delete (m_data->ptr); - delete (m_data); - } - else - { - m_data->refCount--; - } - - m_data = NULL; - } - } - - void attach(T* const ptr) - { - detach(); - - typename MapType::iterator it = sm_map.find(ptr); - - if (it != sm_map.end()) - { - (*it).second->refCount++; - } - else - { - m_data = new data; - m_data->refCount = 1; - m_data->ptr = ptr; - - sm_map.insert(typename MapType::value_type(ptr, m_data)); - } - } - - void attach(smart_ptr <T>& ptr) - { - data* newData = ptr.m_data; - if (newData) newData->refCount++; - - detach(); - - m_data = newData; - } -}; - - -template <class T> -typename smart_ptr <T>::MapType smart_ptr <T>::sm_map; - - -} // utility -} // vmime - - -#endif // VMIME_UTILITY_SMARTPTR_HPP_INCLUDED diff --git a/src/utility/stream.cpp b/src/utility/stream.cpp index 38d12e9f..ede2332b 100644 --- a/src/utility/stream.cpp +++ b/src/utility/stream.cpp @@ -17,8 +17,8 @@ // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // -#include "utility/stream.hpp" -#include "utility/stringProxy.hpp" +#include "vmime/utility/stream.hpp" +#include "vmime/utility/stringProxy.hpp" #include <algorithm> // for std::copy #include <iterator> // for std::back_inserter diff --git a/src/utility/stream.hpp b/src/utility/stream.hpp deleted file mode 100644 index f05df243..00000000 --- a/src/utility/stream.hpp +++ /dev/null @@ -1,274 +0,0 @@ -// -// VMime library (http://vmime.sourceforge.net) -// Copyright (C) 2002-2004 Vincent Richard <[email protected]> -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License as -// published by the Free Software Foundation; either version 2 of -// the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -// - -#ifndef VMIME_UTILITY_STREAM_HPP_INCLUDED -#define VMIME_UTILITY_STREAM_HPP_INCLUDED - - -#include <istream> -#include <ostream> - -#include "types.hpp" - - -namespace vmime { -namespace utility { - - -class stringProxy; - - -/** Base class for input/output stream. - */ - -class stream -{ -public: - - virtual ~stream() { } - - /** Type used to read/write one byte in the stream. - */ - typedef string::value_type value_type; - - /** Type used for lengths in streams. - */ - typedef string::size_type size_type; -}; - - - -/** Simple output stream. - */ - -class outputStream : public stream -{ -public: - - /** Write data to the stream. - * - * @param data buffer containing data to write - * @param count number of bytes to write - */ - virtual void write(const value_type* const data, const size_type count) = 0; -}; - - - -/** Simple input stream. - */ - -class inputStream : public stream -{ -public: - - /** Test for end of stream (no more data to read). - * - * @return true if we have reached the end of stream, false otherwise - */ - virtual const bool eof() const = 0; - - /** Set the read pointer to the beginning of the stream. - * - * @warning WARNING: this may not work for all stream types. - */ - virtual void reset() = 0; - - /** Read data from the stream. - * - * @param data will receive the data read - * @param count maximum number of bytes to read - * @return number of bytes read - */ - virtual const size_type read(value_type* const data, const size_type count) = 0; - - /** Skip a number of bytes. - * - * @param count maximum number of bytes to ignore - * @return number of bytes skipped - */ - virtual const size_type skip(const size_type count) = 0; -}; - - - -// Helpers functions - -outputStream& operator<<(outputStream& os, const string& str); -outputStream& operator<<(outputStream& os, const stream::value_type c); - - -template <int N> -outputStream& operator<<(outputStream& os, const char (&str)[N]) -{ - os.write(str, N - 1); - return (os); -} - - -/** Copy data from one stream into another stream using a buffered method. - * - * @param is input stream (source data) - * @param os output stream (destination for data) - * @return number of bytes copied - */ - -const stream::size_type bufferedStreamCopy(inputStream& is, outputStream& os); - - - -// Adapters - - -/** An adapter class for C++ standard output streams. - */ - -class outputStreamAdapter : public outputStream -{ -public: - - /** @param os output stream to wrap - */ - outputStreamAdapter(std::ostream& os); - - void write(const value_type* const data, const size_type count); - -private: - - std::ostream& m_stream; -}; - - -/** An adapter class for string output. - */ - -class outputStreamStringAdapter : public outputStream -{ -public: - - outputStreamStringAdapter(string& buffer); - - void write(const value_type* const data, const size_type count); - -private: - - string& m_buffer; -}; - - -/** An adapter class for C++ standard input streams. - */ - -class inputStreamAdapter : public inputStream -{ -public: - - /** @param is input stream to wrap - */ - inputStreamAdapter(std::istream& is); - - const bool eof() const; - void reset(); - const size_type read(value_type* const data, const size_type count); - const size_type skip(const size_type count); - -private: - - std::istream& m_stream; -}; - - -/** An adapter class for string input. - */ - -class inputStreamStringAdapter : public inputStream -{ -public: - - inputStreamStringAdapter(const string& buffer); - inputStreamStringAdapter(const string& buffer, const string::size_type begin, const string::size_type end); - - const bool eof() const; - void reset(); - const size_type read(value_type* const data, const size_type count); - const size_type skip(const size_type count); - -private: - - const string m_buffer; // do _NOT_ keep a reference... - const string::size_type m_begin; - const string::size_type m_end; - string::size_type m_pos; -}; - - -/** An adapter class for stringProxy input. - */ - -class inputStreamStringProxyAdapter : public inputStream -{ -public: - - /** @param buffer stringProxy object to wrap - */ - inputStreamStringProxyAdapter(const stringProxy& buffer); - - const bool eof() const; - void reset(); - const size_type read(value_type* const data, const size_type count); - const size_type skip(const size_type count); - -private: - - const stringProxy& m_buffer; - string::size_type m_pos; -}; - - -/** An adapter class for pointer to C++ standard input stream. - */ - -class inputStreamPointerAdapter : public inputStream -{ -public: - - /** @param is input stream to wrap - * @param own if set to 'true', the pointer will be deleted when - * this object is destroyed - */ - inputStreamPointerAdapter(std::istream* is, const bool own = true); - ~inputStreamPointerAdapter(); - - const bool eof() const; - void reset(); - const size_type read(value_type* const data, const size_type count); - const size_type skip(const size_type count); - -private: - - std::istream* m_stream; - const bool m_own; -}; - - -} // utility -} // vmime - - -#endif // VMIME_UTILITY_STREAM_HPP_INCLUDED diff --git a/src/utility/stringProxy.cpp b/src/utility/stringProxy.cpp index 463b11b7..3569f411 100644 --- a/src/utility/stringProxy.cpp +++ b/src/utility/stringProxy.cpp @@ -17,7 +17,7 @@ // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // -#include "utility/stringProxy.hpp" +#include "vmime/utility/stringProxy.hpp" #include <iterator> #include <algorithm> diff --git a/src/utility/stringProxy.hpp b/src/utility/stringProxy.hpp deleted file mode 100644 index 97a27ecd..00000000 --- a/src/utility/stringProxy.hpp +++ /dev/null @@ -1,90 +0,0 @@ -// -// VMime library (http://vmime.sourceforge.net) -// Copyright (C) 2002-2004 Vincent Richard <[email protected]> -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License as -// published by the Free Software Foundation; either version 2 of -// the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -// - -#ifndef VMIME_UTILITY_STRINGPROXY_HPP_INCLUDED -#define VMIME_UTILITY_STRINGPROXY_HPP_INCLUDED - - -#include <limits> - -#include "types.hpp" -#include "utility/stream.hpp" - - -namespace vmime { -namespace utility { - - -/** This class is a proxy for the string class. This takes - * advantage of the COW (copy-on-write) system that might - * be used in "std::string" implementation. - */ - -class stringProxy -{ -public: - - typedef string::size_type size_type; - typedef string string_type; - - - // Consruction - stringProxy(); - stringProxy(const stringProxy& s); - stringProxy(const string_type& s, const size_type start = 0, const size_type end = std::numeric_limits <size_type>::max()); - - // Assignment - void set(const string_type& s, const size_type start = 0, const size_type end = std::numeric_limits <size_type>::max()); - void detach(); - - stringProxy& operator=(const stringProxy& s); - stringProxy& operator=(const string_type& s); - - // Extract some portion (or whole) of the string - // and output it into a stream. - void extract(outputStream& os, const size_type start = 0, const size_type end = std::numeric_limits <size_type>::max()) const; - - // Return the "virtual" length of the string - const size_type length() const; - - // Return the boundaries of the "virtual" string - const size_type start() const; - const size_type end() const; - - string::const_iterator it_begin() const { return (m_buffer.begin() + m_start); } - string::const_iterator it_end() const { return (m_buffer.begin() + m_end); } - -private: - - string_type m_buffer; - - size_type m_start; - size_type m_end; -}; - - -std::ostream& operator<<(std::ostream& os, const stringProxy& s); -outputStream& operator<<(outputStream& os, const stringProxy& s); - - -} // utility -} // vmime - - -#endif // VMIME_UTILITY_STRINGPROXY_HPP_INCLUDED diff --git a/src/utility/stringUtils.cpp b/src/utility/stringUtils.cpp index ab6e06c1..59e9bffd 100644 --- a/src/utility/stringUtils.cpp +++ b/src/utility/stringUtils.cpp @@ -17,7 +17,7 @@ // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // -#include "utility/stringUtils.hpp" +#include "vmime/utility/stringUtils.hpp" namespace vmime diff --git a/src/utility/stringUtils.hpp b/src/utility/stringUtils.hpp deleted file mode 100644 index 95b94a52..00000000 --- a/src/utility/stringUtils.hpp +++ /dev/null @@ -1,131 +0,0 @@ -// -// VMime library (http://vmime.sourceforge.net) -// Copyright (C) 2002-2004 Vincent Richard <[email protected]> -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License as -// published by the Free Software Foundation; either version 2 of -// the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -// - -#ifndef VMIME_STRINGUTILS_HPP_INCLUDED -#define VMIME_STRINGUTILS_HPP_INCLUDED - - -#include "types.hpp" -#include "base.hpp" - -#include <sstream> - - -namespace vmime -{ - - -/** Miscellaneous functions related to strings. - */ - -class stringUtils -{ -public: - - /** Test two strings for equality (case insensitive). - * \warning Use this with ASCII-only strings. - * - * @param s1 first string - * @param s2 second string (must be in lower-case!) - * @param n length of the second string - * @return true if the two strings compare equally, false otherwise - */ - static const bool isStringEqualNoCase(const string& s1, const char* s2, const string::size_type n); - - /** Test two strings for equality (case insensitive). - * \warning Use this with ASCII-only strings. - * - * @param s1 first string - * @param s2 second string - * @return true if the two strings compare equally, false otherwise - */ - static const bool isStringEqualNoCase(const string& s1, const string& s2); - - /** Test two strings for equality (case insensitive). - * \warning Use this with ASCII-only strings. - * - * @param begin start position of the first string - * @param end end position of the first string - * @param s second string (must be in lower-case!) - * @param n length of the second string - * @return true if the two strings compare equally, false otherwise - */ - static const bool isStringEqualNoCase(const string::const_iterator begin, const string::const_iterator end, const char* s, const string::size_type n); - - /** Transform all the characters in a string to lower-case. - * \warning Use this with ASCII-only strings. - * - * @param str the string to transform - * @return a new string in lower-case - */ - static const string toLower(const string& str); - - /** Strip the space characters (SPC, TAB, CR, LF) at the beginning - * and at the end of the specified string. - * - * @param str string in which to strip spaces - * @return a new string with space characters removed - */ - static const string trim(const string& str); - - /** Return the number of 7-bit US-ASCII characters in a string. - * - * @param begin start position - * @param end end position - * @return number of ASCII characters - */ - static const string::size_type countASCIIchars(const string::const_iterator begin, const string::const_iterator end); - - /** Convert the specified value to a string value. - * - * @param value to convert - * @return value converted from type 'TYPE' - */ - template <class TYPE> - static const string toString(const TYPE& value) - { - std::ostringstream oss; - oss << value; - - return (oss.str()); - } - - /** Convert the specified string value to a value of - * the specified type. - * - * @param value value to convert - * @return value converted into type 'TYPE' - */ - template <class TYPE> - static const TYPE fromString(const string& value) - { - TYPE ret; - - std::istringstream iss(value); - iss >> ret; - - return (ret); - } -}; - - -} // vmime - - -#endif // VMIME_STRINGUTILS_HPP_INCLUDED |
