Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
7f52311364c0e48dcd5e9cd706f032fa6c3818ed
[simgrid.git] / src / s4u / s4u_storage.cpp
1 /* Copyright (c) 2006-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "simgrid/s4u/storage.hpp"
8
9 #include "xbt/lib.h"
10 extern xbt_lib_t storage_lib;
11
12 namespace simgrid {
13 namespace s4u {
14
15 boost::unordered_map <std::string, Storage *> *Storage::storages_ = new boost::unordered_map<std::string, Storage*> ();
16 Storage::Storage(std::string name, smx_storage_t inferior) :
17     name_(name), pimpl_(inferior)
18 {
19   size_ = SIMIX_storage_get_size(pimpl_);
20   storages_->insert({name, this});
21 }
22
23 Storage::~Storage() = default;
24
25 smx_storage_t Storage::inferior() {
26   return pimpl_;
27 }
28 Storage &Storage::byName(const char*name) {
29   s4u::Storage *res = nullptr;
30   try {
31     res = storages_->at(name);
32   } catch (std::out_of_range& e) {
33     smx_storage_t inferior = xbt_lib_get_elm_or_null(storage_lib,name);
34     if (inferior == nullptr)
35       xbt_die("Storage %s does not exist. Please only use the storages that are defined in your platform.", name);
36
37     res = new Storage(name,inferior);
38   }
39   return *res;
40 }
41
42 const char* Storage::name()
43 {
44   return name_.c_str();
45 }
46
47 sg_size_t Storage::sizeFree()
48 {
49   return simcall_storage_get_free_size(pimpl_);
50 }
51
52 sg_size_t Storage::sizeUsed()
53 {
54   return simcall_storage_get_used_size(pimpl_);
55 }
56
57 sg_size_t Storage::size() {
58   return size_;
59 }
60
61 xbt_dict_t Storage::properties()
62 {
63   return simcall_storage_get_properties(pimpl_);
64 }
65
66 xbt_dict_t Storage::content()
67 {
68   return simcall_storage_get_content(pimpl_);
69 }
70
71 } /* namespace s4u */
72 } /* namespace simgrid */