Message.C 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  6. * These libraries and programs are free software; you can
  7. * redistribute them and/or modify them under the terms of the GNU
  8. * Lesser General Public License as published by the Free Software
  9. * Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. *
  12. * These libraries and programs are distributed in the hope that
  13. * they will be useful, but WITHOUT ANY WARRANTY; without even the
  14. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  15. * PURPOSE. See the GNU Lesser General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $XConsortium: Message.C /main/1 1996/07/29 16:56:53 cde-hp $ */
  24. // Copyright (c) 1994 James Clark
  25. // See the file COPYING for copying permission.
  26. #ifdef __GNUG__
  27. #pragma implementation
  28. #endif
  29. #include "splib.h"
  30. #include "Message.h"
  31. #include "MessageArg.h"
  32. #ifdef SP_NAMESPACE
  33. namespace SP_NAMESPACE {
  34. #endif
  35. MessageFragment::MessageFragment(unsigned module, unsigned number, const char *
  36. #ifndef SP_NO_MESSAGE_TEXT
  37. text
  38. #endif
  39. )
  40. : module_(module),
  41. #ifndef SP_NO_MESSAGE_TEXT
  42. text_(text),
  43. #endif
  44. number_(number),
  45. spare_(0)
  46. {
  47. }
  48. MessageType::MessageType(Severity severity, unsigned module, unsigned number,
  49. const char *text, const char *
  50. #ifndef SP_NO_MESSAGE_TEXT
  51. auxText
  52. #endif
  53. )
  54. :
  55. #ifndef SP_NO_MESSAGE_TEXT
  56. auxText_(auxText),
  57. #endif
  58. MessageFragment(module, number, text)
  59. {
  60. spare_ = severity;
  61. }
  62. MessageType0::MessageType0(Severity severity, unsigned module, unsigned number,
  63. const char *text)
  64. : MessageType(severity, module, number, text)
  65. {
  66. }
  67. MessageType1::MessageType1(Severity severity, unsigned module, unsigned number,
  68. const char *text)
  69. : MessageType(severity, module, number, text)
  70. {
  71. }
  72. MessageType2::MessageType2(Severity severity, unsigned module, unsigned number,
  73. const char *text)
  74. : MessageType(severity, module, number, text)
  75. {
  76. }
  77. MessageType3::MessageType3(Severity severity, unsigned module, unsigned number,
  78. const char *text)
  79. : MessageType(severity, module, number, text)
  80. {
  81. }
  82. MessageType4::MessageType4(Severity severity, unsigned module, unsigned number,
  83. const char *text)
  84. : MessageType(severity, module, number, text)
  85. {
  86. }
  87. MessageType5::MessageType5(Severity severity, unsigned module, unsigned number,
  88. const char *text)
  89. : MessageType(severity, module, number, text)
  90. {
  91. }
  92. MessageType6::MessageType6(Severity severity, unsigned module, unsigned number,
  93. const char *text)
  94. : MessageType(severity, module, number, text)
  95. {
  96. }
  97. MessageType0L::MessageType0L(Severity severity, unsigned module, unsigned number,
  98. const char *text, const char *auxText)
  99. : MessageType(severity, module, number, text, auxText)
  100. {
  101. }
  102. MessageType1L::MessageType1L(Severity severity, unsigned module, unsigned number,
  103. const char *text, const char *auxText)
  104. : MessageType(severity, module, number, text, auxText)
  105. {
  106. }
  107. OpenElementInfo::OpenElementInfo()
  108. : included(0), matchIndex(0)
  109. {
  110. }
  111. Message::Message()
  112. : type(NULL)
  113. {
  114. }
  115. Message::Message(int nArgs)
  116. : args(nArgs), type(NULL)
  117. {
  118. }
  119. void Message::swap(Message &to)
  120. {
  121. const MessageType *tem = type;
  122. type = to.type;
  123. to.type = tem;
  124. to.loc.swap(loc);
  125. to.auxLoc.swap(auxLoc);
  126. args.swap(to.args);
  127. openElementInfo.swap(to.openElementInfo);
  128. }
  129. Messenger::Messenger()
  130. : haveNextLocation_(0)
  131. {
  132. }
  133. Messenger::~Messenger()
  134. {
  135. }
  136. void Messenger::dispatchMessage(Message &msg)
  137. {
  138. const Message &tem = msg;
  139. dispatchMessage(tem);
  140. }
  141. void Messenger::message(const MessageType0 &type)
  142. {
  143. Message msg(0);
  144. doInitMessage(msg);
  145. msg.type = &type;
  146. dispatchMessage(msg);
  147. }
  148. void Messenger::message(const MessageType1 &type, const MessageArg &arg0)
  149. {
  150. Message msg(1);
  151. doInitMessage(msg);
  152. msg.args[0] = arg0.copy();
  153. msg.type = &type;
  154. dispatchMessage(msg);
  155. }
  156. void Messenger::message(const MessageType2 &type,
  157. const MessageArg &arg0,
  158. const MessageArg &arg1)
  159. {
  160. Message msg(2);
  161. doInitMessage(msg);
  162. msg.args[0] = arg0.copy();
  163. msg.args[1] = arg1.copy();
  164. msg.type = &type;
  165. dispatchMessage(msg);
  166. }
  167. void Messenger::message(const MessageType3 &type,
  168. const MessageArg &arg0,
  169. const MessageArg &arg1,
  170. const MessageArg &arg2)
  171. {
  172. Message msg(3);
  173. doInitMessage(msg);
  174. msg.args[0] = arg0.copy();
  175. msg.args[1] = arg1.copy();
  176. msg.args[2] = arg2.copy();
  177. msg.type = &type;
  178. dispatchMessage(msg);
  179. }
  180. void Messenger::message(const MessageType4 &type,
  181. const MessageArg &arg0,
  182. const MessageArg &arg1,
  183. const MessageArg &arg2,
  184. const MessageArg &arg3)
  185. {
  186. Message msg(4);
  187. doInitMessage(msg);
  188. msg.args[0] = arg0.copy();
  189. msg.args[1] = arg1.copy();
  190. msg.args[2] = arg2.copy();
  191. msg.args[3] = arg3.copy();
  192. msg.type = &type;
  193. dispatchMessage(msg);
  194. }
  195. void Messenger::message(const MessageType5 &type,
  196. const MessageArg &arg0,
  197. const MessageArg &arg1,
  198. const MessageArg &arg2,
  199. const MessageArg &arg3,
  200. const MessageArg &arg4)
  201. {
  202. Message msg(5);
  203. doInitMessage(msg);
  204. msg.args[0] = arg0.copy();
  205. msg.args[1] = arg1.copy();
  206. msg.args[2] = arg2.copy();
  207. msg.args[3] = arg3.copy();
  208. msg.args[4] = arg4.copy();
  209. msg.type = &type;
  210. dispatchMessage(msg);
  211. }
  212. void Messenger::message(const MessageType6 &type,
  213. const MessageArg &arg0,
  214. const MessageArg &arg1,
  215. const MessageArg &arg2,
  216. const MessageArg &arg3,
  217. const MessageArg &arg4,
  218. const MessageArg &arg5)
  219. {
  220. Message msg(6);
  221. doInitMessage(msg);
  222. msg.args[0] = arg0.copy();
  223. msg.args[1] = arg1.copy();
  224. msg.args[2] = arg2.copy();
  225. msg.args[3] = arg3.copy();
  226. msg.args[4] = arg4.copy();
  227. msg.args[5] = arg5.copy();
  228. msg.type = &type;
  229. dispatchMessage(msg);
  230. }
  231. void Messenger::message(const MessageType0L &type, const Location &loc)
  232. {
  233. Message msg(0);
  234. doInitMessage(msg);
  235. msg.type = &type;
  236. msg.auxLoc = loc;
  237. dispatchMessage(msg);
  238. }
  239. void Messenger::message(const MessageType1L &type, const MessageArg &arg0,
  240. const Location &loc)
  241. {
  242. Message msg(1);
  243. doInitMessage(msg);
  244. msg.args[0] = arg0.copy();
  245. msg.type = &type;
  246. msg.auxLoc = loc;
  247. dispatchMessage(msg);
  248. }
  249. void Messenger::setNextLocation(const Location &loc)
  250. {
  251. haveNextLocation_ = 1;
  252. nextLocation_ = loc;
  253. }
  254. void Messenger::initMessage(Message &)
  255. {
  256. }
  257. void Messenger::doInitMessage(Message &msg)
  258. {
  259. initMessage(msg);
  260. if (haveNextLocation_) {
  261. msg.loc = nextLocation_;
  262. haveNextLocation_ = 0;
  263. }
  264. }
  265. ForwardingMessenger::ForwardingMessenger(Messenger &to)
  266. : to_(&to)
  267. {
  268. }
  269. void ForwardingMessenger::dispatchMessage(Message &msg)
  270. {
  271. to_->dispatchMessage(msg);
  272. }
  273. void ForwardingMessenger::dispatchMessage(const Message &msg)
  274. {
  275. to_->dispatchMessage(msg);
  276. }
  277. void ForwardingMessenger::initMessage(Message &msg)
  278. {
  279. to_->initMessage(msg);
  280. }
  281. ParentLocationMessenger::ParentLocationMessenger(Messenger &mgr)
  282. : ForwardingMessenger(mgr)
  283. {
  284. }
  285. void ParentLocationMessenger::initMessage(Message &msg)
  286. {
  287. ForwardingMessenger::initMessage(msg);
  288. if (!msg.loc.origin().isNull())
  289. msg.loc = msg.loc.origin()->parent();
  290. }
  291. NullMessenger::NullMessenger()
  292. {
  293. }
  294. void NullMessenger::dispatchMessage(Message &)
  295. {
  296. }
  297. void NullMessenger::dispatchMessage(const Message &)
  298. {
  299. }
  300. #ifdef SP_NAMESPACE
  301. }
  302. #endif