Valkka  0.17.0
OpenSource Video Management
macro.h
Go to the documentation of this file.
1 #ifndef macro_HEADER_GUARD
2 #define macro_HEADER_GUARD
3 /*
4  * macro.h :
5  *
6  * Copyright 2017, 2018 Valkka Security Ltd. and Sampsa Riikonen.
7  *
8  * Authors: Sampsa Riikonen <sampsa.riikonen@iki.fi>
9  *
10  * This file is part of the Valkka library.
11  *
12  * Valkka is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU Affero General Public License as
14  * published by the Free Software Foundation, either version 3 of the
15  * License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU Affero General Public License for more details.
21  *
22  * You should have received a copy of the GNU Affero General Public License
23  * along with this program. If not, see <https://www.gnu.org/licenses/>
24  *
25  */
26 
37 #define ban_copy_ctor(CLASS) \
38 CLASS(const CLASS &f) {\
39  std::cout << "FATAL: copy-construction prohibited for this class" << std::endl;\
40  perror("FATAL: copy-construction prohibited for this class");\
41  exit(2);\
42 };\
43 
44 #define ban_copy_asm(CLASS) \
45 CLASS &operator= (const CLASS &f) {\
46  std::cout << "FATAL: copy assignment prohibited for this class" << std::endl;\
47  perror("FATAL: copy assignment prohibited for this class");\
48  exit(2);\
49 };\
50 
51 #define notice_ban_copy_ctor() \
52 {\
53  std::cout << "FATAL: copy-construction prohibited for this class" << std::endl;\
54  perror("FATAL: copy-construction prohibited for this class");\
55  exit(2);\
56 };\
57 
58 
59 
60 // Macros for making getFrameClass and copyFrom
61 // use the implicit copy assignment through copyFrom
62 // prohibit copy-construction: frames are pre-reserved and copied, not copy-constructed
63 #define frame_essentials(CLASSNAME, CLASS) \
64 virtual FrameClass getFrameClass() {\
65  return CLASSNAME;\
66 };\
67 virtual void copyFrom(Frame *f) {\
68  CLASS *cf;\
69  cf=dynamic_cast<CLASS*>(f);\
70  if (!cf) {\
71  perror("FATAL : invalid cast at copyFrom");\
72  exit(5);\
73  }\
74  *this =*(cf);\
75 };\
76 CLASS(const CLASS &f) {\
77  std::cout << "FATAL: copy-construction prohibited for frame classes" << std::endl;\
78  perror("FATAL: copy-construction prohibited for frame classes");\
79  exit(2);\
80 };\
81 
82 #define frame_clone(CLASSNAME, CLASS) \
83 virtual CLASS *getClone() {\
84  CLASS *tmpframe = new CLASS();\
85  *tmpframe = *this;\
86  return tmpframe;\
87 };\
88 
89 
90 // macros for initializing and deallocating SignalFrame's custom_signal_ctx
91 
92 
93 #define init_signal_frames(FIFONAME, CONTEXTCLASS) \
94 Reservoir &res = FIFONAME.getReservoir(FrameClass::signal);\
95 for(auto it=res.begin(); it!=res.end(); ++it) {\
96  SignalFrame* f = static_cast<SignalFrame*>(*it);\
97  f->custom_signal_ctx = (void*)(new CONTEXTCLASS());\
98 };\
99 
100 #define clear_signal_frames(FIFONAME, CONTEXTCLASS) \
101 Reservoir &res = FIFONAME.getReservoir(FrameClass::signal);\
102 for(auto it=res.begin(); it!=res.end(); ++it) {\
103  SignalFrame* f = static_cast<SignalFrame*>(*it);\
104  delete (CONTEXTCLASS*)(f->custom_signal_ctx);\
105 };\
106 
107 
108 
109 // generic error handling
110 #define handle_error(msg) \
111  do { perror(msg); exit(EXIT_FAILURE); } while (0)
112 
113 
114 #endif