Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
07f18df8a7132613b2cb2091965fd7705894a8eb
[simgrid.git] / src / mc / AddressSpace.hpp
1 /* Copyright (c) 2008-2014. 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 #ifndef MC_ADDRESS_SPACE_H
8 #define MC_ADDRESS_SPACE_H
9
10 #include <cstdint>
11 #include <type_traits>
12
13 #include <xbt/misc.h>
14
15 #include <stdint.h>
16
17 #include "mc_forward.h"
18
19 namespace simgrid {
20 namespace mc {
21
22 /** Process index used when no process is available
23  *
24  *  The expected behaviour is that if a process index is needed it will fail.
25  * */
26 const int ProcessIndexMissing = -1;
27
28 /** Process index used when we don't care about the process index
29  * */
30 const int ProcessIndexDisabled = -2;
31
32 /** Constant used when any process will do.
33  *
34  *  This is is index of the first process.
35  */
36 const int ProcessIndexAny = 0;
37
38 class AddressSpace {
39 public:
40   enum ReadMode {
41     Normal,
42     /** Allows the `read_bytes` to return a pointer to another buffer
43      *  where the data ins available instead of copying the data into the buffer
44      */
45     Lazy
46   };
47   virtual ~AddressSpace();
48   virtual const void* read_bytes(void* buffer, std::size_t size,
49     std::uint64_t address, int process_index = ProcessIndexAny,
50     ReadMode mode = Normal) = 0;
51   template<class T>
52   T read(uint64_t address, int process_index = ProcessIndexMissing)
53   {
54     static_assert(std::is_trivial<T>::value, "Cannot read a non-trivial type");
55     T res;
56     return *(T*)this->read_bytes(&res, sizeof(T), address, process_index);
57   }
58 };
59
60 }
61 }
62
63 #endif