Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[s4u] Do not use containers of references
authorGabriel Corona <gabriel.corona@loria.fr>
Fri, 15 Jan 2016 11:07:38 +0000 (12:07 +0100)
committerGabriel Corona <gabriel.corona@loria.fr>
Fri, 15 Jan 2016 11:07:38 +0000 (12:07 +0100)
Containers are not allowes to hold references.

examples/s4u/io/s4u_io_test.cpp
include/simgrid/s4u/host.hpp
src/s4u/s4u_host.cpp

index 846ac4c..4f2e993 100644 (file)
@@ -16,13 +16,13 @@ public:
        myHost(const char*procname, simgrid::s4u::Host *host,int argc, char **argv)
 : simgrid::s4u::Actor(procname,host,argc,argv){}
 
-       void show_info(boost::unordered_map <std::string, simgrid::s4u::Storage &> &mounts) {
+       void show_info(boost::unordered_map <std::string, simgrid::s4u::Storage*> &mounts) {
                XBT_INFO("Storage info on %s:",
                        simgrid::s4u::Host::current()->name().c_str());
 
                for (const auto&kv : mounts) {
                        const char* mountpoint = kv.first.c_str();
-                       simgrid::s4u::Storage &storage = kv.second;
+                       simgrid::s4u::Storage &storage = *kv.second;
 
                        // Retrieve disk's information
                        sg_size_t free_size = storage.size_free();
@@ -35,7 +35,7 @@ public:
        }
 
        int main(int argc, char **argv) {
-               boost::unordered_map <std::string, simgrid::s4u::Storage &> &mounts =
+               boost::unordered_map <std::string, simgrid::s4u::Storage *>& mounts =
                        simgrid::s4u::Host::current()->mountedStorages();
 
                show_info(mounts);
index d5c4834..3d32534 100644 (file)
@@ -94,11 +94,11 @@ public:
         *      Do not change the returned value in any way.
         */
        // TODO, do not use Storage&, this looks dangerous!
-       boost::unordered_map<std::string, Storage&> &mountedStorages();
+       boost::unordered_map<std::string, Storage*> &mountedStorages();
 
 private:
        simgrid::xbt::string name_ = "noname";
-       boost::unordered_map<std::string, Storage&> *mounts = NULL; // caching
+       boost::unordered_map<std::string, Storage*> *mounts = NULL; // caching
        void* p_userdata = NULL;
 
 public:
index 9c7ceba..8701353 100644 (file)
@@ -76,9 +76,9 @@ int Host::getNbPStates() const {
        return this->pimpl_cpu->getNbPStates();
 }
 
-boost::unordered_map<std::string, Storage&> &Host::mountedStorages() {
+boost::unordered_map<std::string, Storage*> &Host::mountedStorages() {
        if (mounts == NULL) {
-               mounts = new boost::unordered_map<std::string, Storage&> ();
+               mounts = new boost::unordered_map<std::string, Storage*> ();
 
                xbt_dict_t dict = this->getMountedStorageList();
 
@@ -86,7 +86,7 @@ boost::unordered_map<std::string, Storage&> &Host::mountedStorages() {
                char *mountname;
                char *storagename;
                xbt_dict_foreach(dict, cursor, mountname, storagename) {
-                       mounts->insert({mountname, Storage::byName(storagename)});
+                       mounts->insert({mountname, &Storage::byName(storagename)});
                }
                xbt_dict_free(&dict);
        }