Free Electron
src/core/stream.h
Go to the documentation of this file.
1 /* Copyright (C) 2003-2021 Free Electron Organization
2  Any use of this software requires a license. If a valid license
3  was not distributed with this file, visit freeelectron.org. */
4 
5 /** @file */
6 
7 #ifndef __core_stream_h__
8 #define __core_stream_h__
9 
10 namespace fe
11 {
12 
13 #if 0
14 void FE_DL_PUBLIC FE_CORE_PORT skip(std::istream &istrm, FE_UWORD cnt);
15 
16 void FE_DL_PUBLIC FE_CORE_PORT output(std::ostream &ostrm, const String &s);
17 void FE_DL_PUBLIC FE_CORE_PORT output(std::ostream &ostrm, U8 u8);
18 void FE_DL_PUBLIC FE_CORE_PORT output(std::ostream &ostrm, U32 u32);
19 void FE_DL_PUBLIC FE_CORE_PORT output(std::ostream &ostrm, I32 i32);
20 
21 void FE_DL_PUBLIC FE_CORE_PORT input(std::istream &istrm, String &s);
22 void FE_DL_PUBLIC FE_CORE_PORT input(std::istream &istrm, U8 &u8);
23 void FE_DL_PUBLIC FE_CORE_PORT input(std::istream &istrm, U32 &u32);
24 void FE_DL_PUBLIC FE_CORE_PORT input(std::istream &istrm, I32 &i32);
25 #endif
26 
27 inline
28 void skip(std::istream &istrm, FE_UWORD cnt)
29 {
30  char c;
31  while(cnt--)
32  {
33  istrm.get(c);
34  }
35 }
36 
37 inline
38 void output(std::ostream &ostrm, const String &s)
39 {
40  s.output(ostrm);
41 }
42 
43 inline
44 void output(std::ostream &ostrm, U8 u8)
45 {
46  ostrm.write((char *)&u8, sizeof(U8));
47 }
48 
49 inline
50 void output(std::ostream &ostrm, U32 u32)
51 {
52  U32 n_ul = htonl(u32);
53  ostrm.write((char *)&n_ul, sizeof(U32));
54 }
55 
56 inline
57 void output(std::ostream &ostrm, I32 i32)
58 {
59  U32 n_ul = htonl(*(U32 *)&i32);
60  ostrm.write((char *)&n_ul, sizeof(U32));
61 }
62 
63 inline
64 void input(std::istream &istrm, String &s)
65 {
66  s.input(istrm);
67 }
68 
69 inline
70 void input(std::istream &istrm, U8 &u8)
71 {
72  istrm.read((char *)&u8, sizeof(U8));
73 }
74 
75 inline
76 void input(std::istream &istrm, U32 &u32)
77 {
78  U32 n_ul;
79  istrm.read((char *)&n_ul, sizeof(U32));
80  u32 = ntohl(n_ul);
81 }
82 
83 inline
84 void input(std::istream &istrm, I32 &i32)
85 {
86  U32 n_ul;
87  istrm.read((char *)&n_ul, sizeof(U32));
88  n_ul = ntohl(n_ul);
89  i32 = *(I32 *)&n_ul;
90 }
91 
92 } /* namespace */
93 
94 
95 #endif /* __core_stream_h__ */
96 
kernel
Definition: namespace.dox:3