Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
multipass
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
derf
multipass
Commits
4853a559
Commit
4853a559
authored
6 years ago
by
Birte Kristina Friesel
Browse files
Options
Downloads
Patches
Plain Diff
Your Templates are Bad and You Should Feel Bad
parent
b682dc0c
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/object/xdrstream.h
+9
-1
9 additions, 1 deletion
include/object/xdrstream.h
src/app/prototest/main.cc
+8
-2
8 additions, 2 deletions
src/app/prototest/main.cc
src/os/object/xdrstream.cc
+32
-1
32 additions, 1 deletion
src/os/object/xdrstream.cc
with
49 additions
and
4 deletions
include/object/xdrstream.h
+
9
−
1
View file @
4853a559
...
...
@@ -7,10 +7,13 @@ class XDRStream {
private:
XDRStream
(
const
XDRStream
&
copy
);
uint32_t
next_array_len
;
bool
is_fixed_length
;
public:
XDRStream
()
:
next_array_len
(
0
)
{}
void
setNextArrayLen
(
uint32_t
len
)
{
next_array_len
=
len
;}
void
setFixedLength
()
{
is_fixed_length
=
true
;
}
void
setVariableLength
()
{
is_fixed_length
=
false
;
}
virtual
void
put
(
char
c
)
=
0
;
...
...
@@ -26,7 +29,8 @@ class XDRStream {
XDRStream
&
operator
<<
(
long
number
);
XDRStream
&
operator
<<
(
unsigned
long
long
number
);
XDRStream
&
operator
<<
(
long
long
number
);
XDRStream
&
operator
<<
(
const
char
*
text
);
XDRStream
&
operator
<<
(
char
const
*
text
);
template
<
int
N
>
XDRStream
&
operator
<<
(
char
const
(
&
text
)[
N
]);
XDRStream
&
operator
<<
(
XDRStream
&
(
*
fun
)
(
XDRStream
&
));
};
...
...
@@ -37,6 +41,10 @@ XDRStream & flush(XDRStream & os);
// TERM: zero-termination
XDRStream
&
term
(
XDRStream
&
os
);
template
<
int
N
>
XDRStream
&
opaque
(
XDRStream
&
os
);
XDRStream
&
fixed
(
XDRStream
&
os
);
XDRStream
&
variable
(
XDRStream
&
os
);
#endif //OUTPUTSTREAM_H
This diff is collapsed.
Click to expand it.
src/app/prototest/main.cc
+
8
−
2
View file @
4853a559
...
...
@@ -6,7 +6,7 @@
#include
"object/stdbuf.h"
#include
"object/xdrstream.h"
char
buf
[
128
];
char
buf
[
256
];
void
loop
(
void
)
{
...
...
@@ -30,10 +30,16 @@ void loop(void)
BufferOutput
<
XDRStream
>
foostream
(
buf
);
char
test
[]
=
"Obai World!"
;
foostream
<<
123
<<
0
<<
12345678
;
foostream
.
setNextArrayLen
(
3
);
foostream
<<
fixed
<<
"Hai"
;
foostream
.
setNextArrayLen
(
sizeof
(
test
));
foostream
<<
variable
<<
(
char
const
*
)
test
;
kout
<<
"foostream is "
<<
hex
;
for
(
unsigned
int
i
=
0
;
i
<
32
;
i
+=
4
)
{
for
(
unsigned
int
i
=
0
;
i
<
64
;
i
+=
4
)
{
kout
<<
(
unsigned
char
)
buf
[
i
]
<<
(
unsigned
char
)
buf
[
i
+
1
];
kout
<<
(
unsigned
char
)
buf
[
i
+
2
]
<<
(
unsigned
char
)
buf
[
i
+
3
]
<<
" "
;
}
...
...
This diff is collapsed.
Click to expand it.
src/os/object/xdrstream.cc
+
32
−
1
View file @
4853a559
...
...
@@ -69,6 +69,9 @@ XDRStream & XDRStream::operator<<(int64_t number)
}
XDRStream
&
XDRStream
::
operator
<<
(
char
const
*
data
){
if
(
!
is_fixed_length
)
{
*
this
<<
next_array_len
;
}
uint32_t
i
;
for
(
i
=
0
;
i
<
next_array_len
;
i
++
)
{
put
(
data
[
i
]);
...
...
@@ -79,6 +82,21 @@ XDRStream & XDRStream::operator<<(char const *data){
return
*
this
;
}
template
<
int
N
>
XDRStream
&
XDRStream
::
operator
<<
(
char
const
(
&
data
)[
N
]){
if
(
!
is_fixed_length
)
{
*
this
<<
N
;
}
uint32_t
i
;
for
(
i
=
0
;
i
<
N
;
i
++
)
{
put
(
data
[
i
]);
}
while
((
i
++
)
%
4
!=
0
){
put
(
'\0'
);
}
return
*
this
;
}
XDRStream
&
XDRStream
::
operator
<<
(
XDRStream
&
(
*
fkt
)
(
XDRStream
&
))
{
return
fkt
(
*
this
);
...
...
@@ -99,8 +117,21 @@ XDRStream & term(XDRStream & os)
return
os
;
}
template
<
int
N
>
XDRStream
&
opaque
(
XDRStream
&
os
)
{
os
.
setNextArrayLen
(
3
);
os
.
setNextArrayLen
(
N
);
return
os
;
}
XDRStream
&
fixed
(
XDRStream
&
os
)
{
os
.
setFixedLength
();
return
os
;
}
XDRStream
&
variable
(
XDRStream
&
os
)
{
os
.
setVariableLength
();
return
os
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment