My favorites | Sign in
Project Logo
                
Changes to /trunk/Library/Storage.h
r2 vs. r6   Edit
  Compare: vs.   Format:
Revision r6
Go to: 
Project members, sign in to write a code review
/trunk/Library/Storage.h   r2 /trunk/Library/Storage.h   r6
1 #pragma once 1 #pragma once
2 2
3 #include "TypeTraits.h" 3 #include "TypeTraits.h"
4 #include "Assert.h" 4 #include "Assert.h"
5 5
6 namespace MockItNow 6 namespace MockItNow
7 { 7 {
8 template<typename T> 8 template<typename T>
9 struct Storage 9 struct Storage
10 { 10 {
11 Storage(const T& value_) 11 Storage(const T& value_)
12 : value(value_), 12 : value(value_),
13 address(&value_) 13 address(&value_)
14 { 14 {
15 MOCKITNOW_STATIC_ASSERT(IsReference<T>::Value == false, ArgumentTypeIsAReference); 15 MOCKITNOW_STATIC_ASSERT(IsReference<T>::Value == false, ArgumentTypeIsAReference);
16 MOCKITNOW_STATIC_ASSERT(IsConst<T>::Value == false, ArgumentTypeIsConst); 16 MOCKITNOW_STATIC_ASSERT(IsConst<T>::Value == false, ArgumentTypeIsConst);
17 } 17 }
18 18
19 Storage(const T* address_) 19 Storage(const T* address_)
20 : value(*address_), 20 : value(*address_),
21 address(address_) 21 address(address_)
22 { 22 {
23 MOCKITNOW_STATIC_ASSERT(IsReference<T>::Value == false, ArgumentTypeIsAReference); 23 MOCKITNOW_STATIC_ASSERT(IsReference<T>::Value == false, ArgumentTypeIsAReference);
24 MOCKITNOW_STATIC_ASSERT(IsConst<T>::Value == false, ArgumentTypeIsConst); 24 MOCKITNOW_STATIC_ASSERT(IsConst<T>::Value == false, ArgumentTypeIsConst);
25 } 25 }
26 26
27 T value; 27 T value;
28 const T* address; 28 const T* address;
29 29
30 private: 30 private:
31 31
32 Storage(const Storage&); 32 Storage(const Storage&);
33 Storage& operator=(const Storage&); 33 Storage& operator=(const Storage&);
34 }; 34 };
35 35
36 template<> 36 template<>
37 struct Storage<char *> 37 struct Storage<char *>
38 { 38 {
39 Storage(const char* value_) 39 Storage(const char* value_)
40 { 40 {
41 value = new char[strlen(value_) + 1]; 41 value = new char[strlen(value_) + 1];
42 strcpy(value, value_); 42 strcpy(value, value_);
43 } 43 }
44 44
45 ~Storage() 45 ~Storage()
46 { 46 {
47 delete[] value; 47 delete[] value;
48 } 48 }
49 49
50 char* value; 50 char* value;
51 51
52 private: 52 private:
53 53
54 Storage(const Storage&); 54 Storage(const Storage&);
55 Storage& operator=(const Storage&); 55 Storage& operator=(const Storage&);
56 }; 56 };
57 } 57
58 #define DECLARE_STORAGE_TYPE(ClassToStore, StorageType) \
59 namespace MockItNow \
60 { \
61 template<> \
62 struct Storage<ClassToStore> \
63 { \
64 Storage(const ClassToStore& value_) \
65 : value(value_) \
66 { \
67 } \
68 \
69 StorageType value; \
70 \
71 private: \
72 \
73 Storage(const Storage&); \
74 Storage& operator=(const Storage&); \
75 }; \
76 }
77 }
Hosted by Google Code