Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge pull request #1 from mquinson/master
[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         p_name = name;
18         p_inferior = inferior;
19
20         storages->insert({name, this});
21 }
22
23 Storage::~Storage() {
24         // TODO Auto-generated destructor stub
25 }
26
27 smx_storage_t Storage::inferior() {
28         return p_inferior;
29 }
30 Storage &Storage::byName(const char*name) {
31         s4u::Storage *res = NULL;
32         try {
33                 res = storages->at(name);
34         } catch (std::out_of_range& e) {
35                 smx_storage_t inferior = xbt_lib_get_elm_or_null(storage_lib,name);
36                 if (inferior == NULL)
37                         xbt_die("Storage %s does not exist. Please only use the storages that are defined in your platform.", name);
38
39                 res = new Storage(name,inferior);
40         }
41         return *res;
42 }
43
44 const char*Storage::name() {
45         return p_name.c_str();
46 }
47
48 sg_size_t Storage::size_free() {
49         return simcall_storage_get_free_size(p_inferior);
50 }
51 sg_size_t Storage::size_used() {
52         return simcall_storage_get_used_size(p_inferior);
53 }
54 sg_size_t Storage::size() {
55         return SIMIX_storage_get_size(p_inferior);
56 }
57
58 } /* namespace s4u */
59 } /* namespace simgrid */