Repository.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *
00003  * Copyright (C) 2009-2010 Cassio Neri Moreira
00004  *
00005  * This file is part of the KeyValue library.
00006  *
00007  * The KeyValue library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License as published
00009  * by the Free Software Foundation, either version 3 of the License, or (at
00010  * your option) any later version.
00011  *
00012  * The KeyValue library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
00015  * Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License along
00018  * with KeyValue. If not, see <http://www.gnu.org/licenses/>.
00019  *
00020  * If you modify this library, or any covered work, by linking or combining
00021  * it with Excel (or a modified version of that program), containing parts
00022  * covered by the terms of End-User License Agreement for Microsoft
00023  * Software, the licensors of KeyValue grant you additional permission to
00024  * convey the resulting work.
00025  *
00026  **************************************************************************/
00027 
00034 #ifndef KEYVALUE_MNGT_REPOSITORY_H_
00035 #define KEYVALUE_MNGT_REPOSITORY_H_
00036 
00037 #include <map>
00038 
00039 #include <boost/utility.hpp>
00040 
00041 #include "keyvalue/extern/SharedPtr.h"
00042 #include "keyvalue/sys/exception/Exception.h"
00043 #include "keyvalue/value/Vector.h"
00044 
00045 namespace keyvalue {
00046 
00047 // Forward declarations
00048 
00049 class DataSet;
00050 
00058 class Repository : private boost::noncopyable {
00059 
00060 public:
00061 
00077   void
00078   add(shared_ptr<DataSet> dataSet);
00079 
00088   bool
00089   erase(const string& name);
00090 
00096   size_t
00097   clear();
00098 
00107   shared_ptr<DataSet>
00108   find(const string& name) const;
00109 
00119   shared_ptr<DataSet>
00120   getDataSet(const string& name) const;
00121 
00127   size_t
00128   getSize() const;
00129 
00135   value::Vector
00136   getList() const;
00137 
00141   class NotFound : public RuntimeError {
00142 
00143   public:
00144 
00145     /***
00146      * @brief   Constructor stores the name of DataSet which was not found.
00147      *
00148      * @param   name  : Name of DataSet which was not found.
00149      */
00150     explicit
00151     NotFound(string name);
00152 
00153     ~NotFound() throw();
00154 
00155     /***
00156      * @brief   Gets the name of DataSet which was not found.
00157      *
00158      * @return  The name od DataSet which was not found.
00159      */
00160     const string&
00161     getName() const;
00162 
00163   private:
00164 
00165     const string name_;
00166   };
00167 
00168 private:
00169 
00170   typedef std::map <string, shared_ptr<DataSet> > Map_;
00171   typedef Map_::value_type                        Pair_;
00172   Map_                                            map_;
00173 
00174 }; // class Repository
00175 
00176 } // namespace keyvalue
00177 
00178 #endif // KEYVALUE_MNGT_REPOSITORY_H_