Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / third_party / nlio / repo / include / nlio-base.hpp
1 /**
2  *    Copyright 2013-2016 Nest Labs Inc. All Rights Reserved.
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16
17 /**
18  *    @file
19  *      This file defines C++ functions for safely performing simple,
20  *      memory-mapped accesses, potentially to unaligned memory
21  *      locations.
22  */
23
24 #ifndef NLIO_BASE_HPP
25 #define NLIO_BASE_HPP
26
27 #include <nlio-base.h>
28
29 namespace nl
30 {
31
32 namespace IO
33 {
34
35 /**
36  * This determines whether the specified pointer is aligned on the
37  * indicated size boundary.
38  *
39  * @note The size should be a power of 2 (e.g. 1, 2, 4, 8, 16, etc.).
40  *
41  * @param[in]  p     The pointer to check the alignment of.
42  * @param[in]  size  The size, in bytes, boundary to check
43  *                   the alignment against.
44  *
45  * @return True if the pointer is aligned to the specified size;
46  *         otherwise, false.
47  */
48 static inline bool IsAligned(const void *p, size_t size)
49 {
50     return nlIOIsAligned(p, size);
51 }
52
53 /**
54  * This determines whether the specified pointer is aligned on the
55  * size boundary for the template type, T.
56  *
57  * @tparam     T     The type of pointer to check the alignment of.
58  *
59  * @param[in]  p     The pointer to check the alignment of.
60  *
61  * @return True if the pointer is aligned to size of the type;
62  *         otherwise, false.
63  */
64 template <typename T>
65 static inline bool IsAligned(const T *p)
66 {
67     return nlIOIsAligned(p, sizeof(T));
68 }
69
70 /**
71  * Perform an aligned memory read of the 8-bit value at the specified
72  * pointer address.
73  *
74  * @param[in]  p      A pointer address to read the 8-bit value from.
75  *
76  * @return The 8-bit value at the specified pointer address.
77  */
78 static inline uint8_t  GetAligned8(const void *p)
79 {
80     return nlIOGetAligned8(p);
81 }
82
83 /**
84  * Perform an aligned memory read of the 16-bit value at the specified
85  * pointer address.
86  *
87  * @param[in]  p      A pointer address to read the 16-bit value from.
88  *
89  * @return The 16-bit value at the specified pointer address.
90  */
91 static inline uint16_t GetAligned16(const void *p)
92 {
93     return nlIOGetAligned16(p);
94 }
95
96 /**
97  * Perform an aligned memory read of the 32-bit value at the specified
98  * pointer address.
99  *
100  * @param[in]  p      A pointer address to read the 32-bit value from.
101  *
102  * @return The 32-bit value at the specified pointer address.
103  */
104 static inline uint32_t GetAligned32(const void *p)
105 {
106     return nlIOGetAligned32(p);
107 }
108
109 /**
110  * Perform an aligned memory read of the 64-bit value at the specified
111  * pointer address.
112  *
113  * @param[in]  p      A pointer address to read the 64-bit value from.
114  *
115  * @return The 64-bit value at the specified pointer address.
116  */
117 static inline uint64_t GetAligned64(const void *p)
118 {
119     return nlIOGetAligned64(p);
120 }
121
122 /**
123  * Perform an unaligned memory read of the 8-bit value at the specified
124  * pointer address.
125  *
126  * @param[in]  p      A pointer address to read the 8-bit value from.
127  *
128  * @return The 8-bit value at the specified pointer address.
129  */
130 static inline uint8_t  GetUnaligned8(const void *p)
131 {
132     return nlIOGetUnaligned8(p);
133 }
134
135 /**
136  * Perform an unaligned memory read of the 16-bit value at the specified
137  * pointer address.
138  *
139  * @param[in]  p      A pointer address to read the 16-bit value from.
140  *
141  * @return The 16-bit value at the specified pointer address.
142  */
143 static inline uint16_t GetUnaligned16(const void *p)
144 {
145     return nlIOGetUnaligned16(p);
146 }
147
148 /**
149  * Perform an unaligned memory read of the 32-bit value at the specified
150  * pointer address.
151  *
152  * @param[in]  p      A pointer address to read the 32-bit value from.
153  *
154  * @return The 32-bit value at the specified pointer address.
155  */
156 static inline uint32_t GetUnaligned32(const void *p)
157 {
158     return nlIOGetUnaligned32(p);
159 }
160
161 /**
162  * Perform an unaligned memory read of the 64-bit value at the specified
163  * pointer address.
164  *
165  * @param[in]  p      A pointer address to read the 64-bit value from.
166  *
167  * @return The 64-bit value at the specified pointer address.
168  */
169 static inline uint64_t GetUnaligned64(const void *p)
170 {
171     return nlIOGetUnaligned64(p);
172 }
173
174 /**
175  * Perform a, potentially unaligned, memory read of the 8-bit value
176  * from the specified pointer address.
177  *
178  * @param[in]  p      A pointer address, potentially unaligned, to read
179  *                    the 8-bit value from.
180  *
181  * @return The 8-bit value at the specified pointer address.
182  */
183 static inline uint8_t  GetMaybeAligned8(const void *p)
184 {
185     return nlIOGetMaybeAligned8(p);
186 }
187
188 /**
189  * Perform a, potentially unaligned, memory read of the 16-bit value
190  * from the specified pointer address.
191  *
192  * @param[in]  p      A pointer address, potentially unaligned, to read
193  *                    the 16-bit value from.
194  *
195  * @return The 16-bit value at the specified pointer address.
196  */
197 static inline uint16_t GetMaybeAligned16(const void *p)
198 {
199     return nlIOGetMaybeAligned16(p);
200 }
201
202 /**
203  * Perform a, potentially unaligned, memory read of the 32-bit value
204  * from the specified pointer address.
205  *
206  * @param[in]  p      A pointer address, potentially unaligned, to read
207  *                    the 32-bit value from.
208  *
209  * @return The 32-bit value at the specified pointer address.
210  */
211 static inline uint32_t GetMaybeAligned32(const void *p)
212 {
213     return nlIOGetMaybeAligned32(p);
214 }
215
216 /**
217  * Perform a, potentially unaligned, memory read of the 64-bit value
218  * from the specified pointer address.
219  *
220  * @param[in]  p      A pointer address, potentially unaligned, to read
221  *                    the 64-bit value from.
222  *
223  * @return The 64-bit value at the specified pointer address.
224  */
225 static inline uint64_t GetMaybeAligned64(const void *p)
226 {
227     return nlIOGetMaybeAligned64(p);
228 }
229
230 /**
231  * Perform an aligned memory write of the 8-bit value to the specified
232  * pointer address.
233  *
234  * @param[in]  p      A pointer address to write the 8-bit value to.
235  *
236  * @param[in]  v      The 8-bit value to write.
237  *
238  */
239 static inline void     PutAligned8(void *p, const uint8_t v)
240 {
241     nlIOPutAligned8(p, v);
242 }
243
244 /**
245  * Perform an aligned memory write of the 16-bit value to the specified
246  * pointer address.
247  *
248  * @param[in]  p      A pointer address to write the 16-bit value to.
249  *
250  * @param[in]  v      The 16-bit value to write.
251  *
252  */
253 static inline void     PutAligned16(void *p, const uint16_t v)
254 {
255     nlIOPutAligned16(p, v);
256 }
257
258 /**
259  * Perform an aligned memory write of the 32-bit value to the specified
260  * pointer address.
261  *
262  * @param[in]  p      A pointer address to write the 32-bit value to.
263  *
264  * @param[in]  v      The 32-bit value to write.
265  *
266  */
267 static inline void     PutAligned32(void *p, const uint32_t v)
268 {
269     nlIOPutAligned32(p, v);
270 }
271
272 /**
273  * Perform an aligned memory write of the 64-bit value to the specified
274  * pointer address.
275  *
276  * @param[in]  p      A pointer address to write the 64-bit value to.
277  *
278  * @param[in]  v      The 64-bit value to write.
279  *
280  */
281 static inline void     PutAligned64(void *p, const uint64_t v)
282 {
283     nlIOPutAligned64(p, v);
284 }
285
286 /**
287  * Perform an unaligned memory write of the 8-bit value to the specified
288  * pointer address.
289  *
290  * @param[in]  p      A pointer address to write the 8-bit value to.
291  *
292  * @param[in]  v      The 8-bit value to write.
293  *
294  */
295 static inline void     PutUnaligned8(void *p, const uint8_t v)
296 {
297     nlIOPutUnaligned8(p, v);
298 }
299
300 /**
301  * Perform an unaligned memory write of the 16-bit value to the specified
302  * pointer address.
303  *
304  * @param[in]  p      A pointer address to write the 16-bit value to.
305  *
306  * @param[in]  v      The 16-bit value to write.
307  *
308  */
309 static inline void     PutUnaligned16(void *p, const uint16_t v)
310 {
311     nlIOPutUnaligned16(p, v);
312 }
313
314 /**
315  * Perform an unaligned memory write of the 32-bit value to the specified
316  * pointer address.
317  *
318  * @param[in]  p      A pointer address to write the 32-bit value to.
319  *
320  * @param[in]  v      The 32-bit value to write.
321  *
322  */
323 static inline void     PutUnaligned32(void *p, const uint32_t v)
324 {
325     nlIOPutUnaligned32(p, v);
326 }
327
328 /**
329  * Perform an unaligned memory write of the 64-bit value to the specified
330  * pointer address.
331  *
332  * @param[in]  p      A pointer address to write the 64-bit value to.
333  *
334  * @param[in]  v      The 64-bit value to write.
335  *
336  */
337 static inline void     PutUnaligned64(void *p, const uint64_t v)
338 {
339     nlIOPutUnaligned64(p, v);
340 }
341
342 /**
343  * Perform a, potentially unaligned, memory write of the 8-bit value
344  * to the specified pointer address.
345  *
346  * @param[in]  p      A pointer address, potentially unaligned, to write
347  *                    the 8-bit value to.
348  *
349  * @param[in]  v      The 8-bit value to write.
350  *
351  */
352 static inline void     PutMaybeAligned8(void *p, const uint8_t v)
353 {
354     nlIOPutMaybeAligned8(p, v);
355 }
356
357 /**
358  * Perform a, potentially unaligned, memory write of the 16-bit value
359  * to the specified pointer address.
360  *
361  * @param[in]  p      A pointer address, potentially unaligned, to write
362  *                    the 16-bit value to.
363  *
364  * @param[in]  v      The 16-bit value to write.
365  *
366  */
367 static inline void     PutMaybeAligned16(void *p, const uint16_t v)
368 {
369     nlIOPutMaybeAligned16(p, v);
370 }
371
372 /**
373  * Perform a, potentially unaligned, memory write of the 32-bit value
374  * to the specified pointer address.
375  *
376  * @param[in]  p      A pointer address, potentially unaligned, to write
377  *                    the 32-bit value to.
378  *
379  * @param[in]  v      The 32-bit value to write.
380  *
381  */
382 static inline void     PutMaybeAligned32(void *p, const uint32_t v)
383 {
384     nlIOPutMaybeAligned32(p, v);
385 }
386
387 /**
388  * Perform a, potentially unaligned, memory write of the 64-bit value
389  * to the specified pointer address.
390  *
391  * @param[in]  p      A pointer address, potentially unaligned, to write
392  *                    the 64-bit value to.
393  *
394  * @param[in]  v      The 64-bit value to write.
395  *
396  */
397 static inline void     PutMaybeAligned64(void *p, const uint64_t v)
398 {
399     nlIOPutMaybeAligned64(p, v);
400 }
401
402 /**
403  * Perform an aligned memory read of the 8-bit value at the specified
404  * pointer address and increment the pointer by 8-bits (1 byte).
405  *
406  * @param[inout]  p   A reference to a pointer address to read the
407  *                    8-bit value from and to then increment by
408  *                    8-bits (1 byte).
409  *
410  * @return The 8-bit value at the specified pointer address.
411  */
412 static inline uint8_t  ReadAligned8(const void *&p)
413 {
414     return nlIOReadAligned8(&p);
415 }
416
417 /**
418  * Perform an aligned memory read of the 16-bit value at the specified
419  * pointer address and increment the pointer by 16-bits (2 bytes).
420  *
421  * @param[inout]  p   A reference to a pointer address to read the
422  *                    16-bit value from and to then increment by
423  *                    16-bits (2 bytes).
424  *
425  * @return The 16-bit value at the specified pointer address.
426  */
427 static inline uint16_t ReadAligned16(const void *&p)
428 {
429     return nlIOReadAligned16(&p);
430 }
431
432 /**
433  * Perform an aligned memory read of the 32-bit value at the specified
434  * pointer address and increment the pointer by 32-bits (4 bytes).
435  *
436  * @param[inout]  p   A reference to a pointer address to read the
437  *                    32-bit value from and to then increment by
438  *                    32-bits (4 bytes).
439  *
440  * @return The 32-bit value at the specified pointer address.
441  */
442 static inline uint32_t ReadAligned32(const void *&p)
443 {
444     return nlIOReadAligned32(&p);
445 }
446
447 /**
448  * Perform an aligned memory read of the 64-bit value at the specified
449  * pointer address and increment the pointer by 64-bits (8 bytes).
450  *
451  * @param[inout]  p   A reference to a pointer address to read the
452  *                    64-bit value from and to then increment by
453  *                    64-bits (8 bytes).
454  *
455  * @return The 64-bit value at the specified pointer address.
456  */
457 static inline uint64_t ReadAligned64(const void *&p)
458 {
459     return nlIOReadAligned64(&p);
460 }
461
462 /**
463  * Perform an unaligned memory read of the 8-bit value at the specified
464  * pointer address and increment the pointer by 8-bits (1 byte).
465  *
466  * @param[inout]  p   A reference to a pointer address to read the
467  *                    8-bit value from and to then increment by
468  *                    8-bits (1 byte).
469  *
470  * @return The 8-bit value at the specified pointer address.
471  */
472 static inline uint8_t ReadUnaligned8(const void *&p)
473 {
474     return nlIOReadUnaligned8(&p);
475 }
476
477 /**
478  * Perform an unaligned memory read of the 16-bit value at the specified
479  * pointer address and increment the pointer by 16-bits (2 bytes).
480  *
481  * @param[inout]  p   A reference to a pointer address to read the
482  *                    16-bit value from and to then increment by
483  *                    16-bits (2 bytes).
484  *
485  * @return The 16-bit value at the specified pointer address.
486  */
487 static inline uint16_t ReadUnaligned16(const void *&p)
488 {
489     return nlIOReadUnaligned16(&p);
490 }
491
492 /**
493  * Perform an aligned memory read of the 32-bit value at the specified
494  * pointer address and increment the pointer by 32-bits (4 bytes).
495  *
496  * @param[inout]  p   A reference to a pointer address to read the
497  *                    32-bit value from and to then increment by
498  *                    32-bits (4 bytes).
499  *
500  * @return The 32-bit value at the specified pointer address.
501  */
502 static inline uint32_t ReadUnaligned32(const void *&p)
503 {
504     return nlIOReadUnaligned32(&p);
505 }
506
507 /**
508  * Perform an unaligned memory read of the 64-bit value at the specified
509  * pointer address and increment the pointer by 64-bits (8 bytes).
510  *
511  * @param[inout]  p   A reference to a pointer address to read the
512  *                    64-bit value from and to then increment by
513  *                    64-bits (8 bytes).
514  *
515  * @return The 64-bit value at the specified pointer address.
516  */
517 static inline uint64_t ReadUnaligned64(const void *&p)
518 {
519     return nlIOReadUnaligned64(&p);
520 }
521
522 /**
523  * Perform a, potentially unaligned, memory read of the 8-bit value
524  * from the specified pointer address and increment the pointer by
525  * 8-bits (1 bytes).
526  *
527  * @param[inout]  p   A reference to a pointer address, potentially
528  *                    unaligned, to read the 8-bit value from and to
529  *                    then increment by 8-bits (1 byte).
530  *
531  * @return The 8-bit value at the specified pointer address.
532  */
533 static inline uint8_t  ReadMaybeAligned8(const void *&p)
534 {
535     return nlIOReadMaybeAligned8(&p);
536 }
537
538 /**
539  * Perform a, potentially unaligned, memory read of the 16-bit value
540  * from the specified pointer address and increment the pointer by
541  * 16-bits (2 bytes).
542  *
543  * @param[inout]  p   A reference to a pointer address, potentially
544  *                    unaligned, to read the 16-bit value from and to
545  *                    then increment by 16-bits (2 bytes).
546  *
547  * @return The 16-bit value at the specified pointer address.
548  */
549 static inline uint16_t ReadMaybeAligned16(const void *&p)
550 {
551     return nlIOReadMaybeAligned16(&p);
552 }
553
554 /**
555  * Perform a, potentially unaligned, memory read of the 32-bit value
556  * from the specified pointer address and increment the pointer by
557  * 32-bits (4 bytes).
558  *
559  * @param[inout]  p   A reference to a pointer address, potentially
560  *                    unaligned, to read the 32-bit value from and to
561  *                    then increment by 32-bits (4 bytes).
562  *
563  * @return The 32-bit value at the specified pointer address.
564  */
565 static inline uint32_t ReadMaybeAligned32(const void *&p)
566 {
567     return nlIOReadMaybeAligned32(&p);
568 }
569
570 /**
571  * Perform a, potentially unaligned, memory read of the 64-bit value
572  * from the specified pointer address and increment the pointer by
573  * 64-bits (8 bytes).
574  *
575  * @param[inout]  p   A reference to a pointer address, potentially
576  *                    unaligned, to read the 64-bit value from and to
577  *                    then increment by 64-bits (8 bytes).
578  *
579  * @return The 64-bit value at the specified pointer address.
580  */
581 static inline uint64_t ReadMaybeAligned64(const void *&p)
582 {
583     return nlIOReadMaybeAligned64(&p);
584 }
585
586 /**
587  * Perform an aligned memory write of the 8-bit value to the specified
588  * pointer address and increment the pointer by 8-bits (1 byte).
589  *
590  * @param[inout]  p   A reference to a pointer address to read the 8-bit
591  *                    value from and to then increment by 8-bits (1 byte).
592  *
593  * @param[in]     v   The 8-bit value to write.
594  *
595  */
596 static inline void     WriteAligned8(void *&p, const uint8_t v)
597 {
598     nlIOWriteAligned8(&p, v);
599 }
600
601 /**
602  * Perform an aligned memory write of the 16-bit value to the specified
603  * pointer address and increment the pointer by 16-bits (2 bytes).
604  *
605  * @param[inout]  p   A reference to a pointer address to read the 16-bit
606  *                    value from and to then increment by 16-bits (2 bytes).
607  *
608  * @param[in]     v   The 16-bit value to write.
609  *
610  */
611 static inline void     WriteAligned16(void *&p, const uint16_t v)
612 {
613     nlIOWriteAligned16(&p, v);
614 }
615
616 /**
617  * Perform an aligned memory write of the 32-bit value to the specified
618  * pointer address and increment the pointer by 32-bits (4 bytes).
619  *
620  * @param[inout]  p   A reference to a pointer address to read the 32-bit
621  *                    value from and to then increment by 32-bits (4 bytes).
622  *
623  * @param[in]     v   The 32-bit value to write.
624  *
625  */
626 static inline void     WriteAligned32(void *&p, const uint32_t v)
627 {
628     nlIOWriteAligned32(&p, v);
629 }
630
631 /**
632  * Perform an aligned memory write of the 64-bit value to the specified
633  * pointer address and increment the pointer by 64-bits (8 bytes).
634  *
635  * @param[inout]  p   A reference to a pointer address to read the 64-bit
636  *                    value from and to then increment by 64-bits (8 bytes).
637  *
638  * @param[in]     v   The 64-bit value to write.
639  *
640  */
641 static inline void     WriteAligned64(void *&p, const uint64_t v)
642 {
643     nlIOWriteAligned64(&p, v);
644 }
645
646 /**
647  * Perform an unaligned memory write of the 8-bit value to the specified
648  * pointer address and increment the pointer by 8-bits (1 byte).
649  *
650  * @param[inout]  p   A reference to a pointer address to read the 8-bit
651  *                    value from and to then increment by 8-bits (1 byte).
652  *
653  * @param[in]     v   The 8-bit value to write.
654  *
655  */
656 static inline void     WriteUnaligned8(void *&p, const uint8_t v)
657 {
658     nlIOWriteUnaligned8(&p, v);
659 }
660
661 /**
662  * Perform an unaligned memory write of the 16-bit value to the specified
663  * pointer address and increment the pointer by 16-bits (2 bytes).
664  *
665  * @param[inout]  p   A reference to a pointer address to read the 16-bit
666  *                    value from and to then increment by 16-bits (2 bytes).
667  *
668  * @param[in]     v   The 16-bit value to write.
669  *
670  */
671 static inline void     WriteUnaligned16(void *&p, const uint16_t v)
672 {
673     nlIOWriteUnaligned16(&p, v);
674 }
675
676 /**
677  * Perform an unaligned memory write of the 32-bit value to the specified
678  * pointer address and increment the pointer by 32-bits (4 bytes).
679  *
680  * @param[inout]  p   A reference to a pointer address to read the 32-bit
681  *                    value from and to then increment by 32-bits (4 bytes).
682  *
683  * @param[in]     v   The 32-bit value to write.
684  *
685  */
686 static inline void     WriteUnaligned32(void *&p, const uint32_t v)
687 {
688     nlIOWriteUnaligned32(&p, v);
689 }
690
691 /**
692  * Perform an unaligned memory write of the 64-bit value to the specified
693  * pointer address and increment the pointer by 64-bits (8 bytes).
694  *
695  * @param[inout]  p   A reference to a pointer address to read the 64-bit
696  *                    value from and to then increment by 64-bits (8 bytes).
697  *
698  * @param[in]     v   The 64-bit value to write.
699  *
700  */
701 static inline void     WriteUnaligned64(void *&p, const uint64_t v)
702 {
703     nlIOWriteUnaligned64(&p, v);
704 }
705
706 /**
707  * Perform a, potentially unaligned, memory write of the 8-bit value
708  * to the specified pointer address and increment the pointer by
709  * 8-bits (1 byte).
710  *
711  * @param[inout]  p   A reference to a pointer address, potentially
712  *                    unaligned, to read the 8-bit value from and to
713  *                    then increment by 8-bits (1 byte).
714  *
715  * @param[in]     v   The 8-bit value to write.
716  *
717  */
718 static inline void     WriteMaybeAligned8(void *&p, const uint8_t v)
719 {
720     nlIOWriteMaybeAligned8(&p, v);
721 }
722
723 /**
724  * Perform a, potentially unaligned, memory write of the 16-bit value
725  * to the specified pointer address and increment the pointer by
726  * 16-bits (2 bytes).
727  *
728  * @param[inout]  p   A reference to a pointer address, potentially
729  *                    unaligned, to read the 16-bit value from and to
730  *                    then increment by 16-bits (2 bytes).
731  *
732  * @param[in]     v   The 16-bit value to write.
733  *
734  */
735 static inline void     WriteMaybeAligned16(void *&p, const uint16_t v)
736 {
737     nlIOWriteMaybeAligned16(&p, v);
738 }
739
740 /**
741  * Perform a, potentially unaligned, memory write of the 32-bit value
742  * to the specified pointer address and increment the pointer by
743  * 32-bits (4 bytes).
744  *
745  * @param[inout]  p   A reference to a pointer address, potentially
746  *                    unaligned, to read the 32-bit value from and to
747  *                    then increment by 32-bits (4 bytes).
748  *
749  * @param[in]     v   The 32-bit value to write.
750  *
751  */
752 static inline void     WriteMaybeAligned32(void *&p, const uint32_t v)
753 {
754     nlIOWriteMaybeAligned32(&p, v);
755 }
756
757 /**
758  * Perform a, potentially unaligned, memory write of the 64-bit value
759  * to the specified pointer address and increment the pointer by
760  * 64-bits (8 bytes).
761  *
762  * @param[inout]  p   A reference to a pointer address, potentially
763  *                    unaligned, to read the 64-bit value from and to
764  *                    then increment by 64-bits (8 bytes).
765  *
766  * @param[in]     v   The 64-bit value to write.
767  *
768  */
769 static inline void     WriteMaybeAligned64(void *&p, const uint64_t v)
770 {
771     nlIOWriteMaybeAligned64(&p, v);
772 }
773
774 /**
775  * Perform a memory read of the 8-bit value at the specified pointer
776  * address.
777  *
778  * @param[in]  p      A pointer address to read the 8-bit value from.
779  *
780  * @return The 8-bit value at the specified pointer address.
781  */
782 static inline uint8_t  Get8(const void *p)
783 {
784     return nlIOGet8(p);
785 }
786
787 /**
788  * Perform a, potentially unaligned, memory read of the 16-bit value
789  * from the specified pointer address.
790  *
791  * @param[in]  p      A pointer address, potentially unaligned, to read
792  *                    the 16-bit value from.
793  *
794  * @return The 16-bit value at the specified pointer address.
795  */
796 static inline uint16_t Get16(const void *p)
797 {
798     return nlIOGet16(p);
799 }
800
801 /**
802  * Perform a, potentially unaligned, memory read of the 32-bit value
803  * from the specified pointer address.
804  *
805  * @param[in]  p      A pointer address, potentially unaligned, to read
806  *                    the 32-bit value from.
807  *
808  * @return The 32-bit value at the specified pointer address.
809  */
810 static inline uint32_t Get32(const void *p)
811 {
812     return nlIOGet32(p);
813 }
814
815 /**
816  * Perform a, potentially unaligned, memory read of the 64-bit value
817  * from the specified pointer address.
818  *
819  * @param[in]  p      A pointer address, potentially unaligned, to read
820  *                    the 64-bit value from.
821  *
822  * @return The 64-bit value at the specified pointer address.
823  */
824 static inline uint64_t Get64(const void *p)
825 {
826     return nlIOGet64(p);
827 }
828
829 /**
830  * Perform a, potentially unaligned, memory write of the 8-bit value
831  * to the specified pointer address.
832  *
833  * @param[in]  p      A pointer address, potentially unaligned, to write
834  *                    the 8-bit value to.
835  *
836  * @param[in]  v      The 8-bit value to write.
837  *
838  */
839 static inline void Put8(void *p, const uint8_t v)
840 {
841     nlIOPut8(p, v);
842 }
843
844 /**
845  * Perform a, potentially unaligned, memory write of the 16-bit value
846  * to the specified pointer address.
847  *
848  * @param[in]  p      A pointer address, potentially unaligned, to write
849  *                    the 16-bit value to.
850  *
851  * @param[in]  v      The 16-bit value to write.
852  *
853  */
854 static inline void Put16(void *p, const uint16_t v)
855 {
856     nlIOPut16(p, v);
857 }
858
859 /**
860  * Perform a, potentially unaligned, memory write of the 32-bit value
861  * to the specified pointer address.
862  *
863  * @param[in]  p      A pointer address, potentially unaligned, to write
864  *                    the 32-bit value to.
865  *
866  * @param[in]  v      The 32-bit value to write.
867  *
868  */
869 static inline void Put32(void *p, const uint32_t v)
870 {
871     nlIOPut32(p, v);
872 }
873
874 /**
875  * Perform a, potentially unaligned, memory write of the 64-bit value
876  * to the specified pointer address.
877  *
878  * @param[in]  p      A pointer address, potentially unaligned, to write
879  *                    the 64-bit value to.
880  *
881  * @param[in]  v      The 64-bit value to write.
882  *
883  */
884 static inline void Put64(void *p, const uint64_t v)
885 {
886     nlIOPut64(p, v);
887 }
888
889 /**
890  * Perform a, potentially unaligned, memory read of the 16-bit value
891  * from the specified pointer address and increment the pointer by
892  * 8-bits (1 byte).
893  *
894  * @param[inout]  p   A reference to a pointer address, potentially
895  *                    unaligned, to read the 8-bit value from and to
896  *                    then increment by 8-bits (1 byte).
897  *
898  * @return The 8-bit value at the specified pointer address.
899  */
900 static inline uint8_t  Read8(const void *&p)
901 {
902     return nlIORead8(&p);
903 }
904
905 /**
906  * Perform a, potentially unaligned, memory read of the 16-bit value
907  * from the specified pointer address and increment the pointer by
908  * 16-bits (2 bytes).
909  *
910  * @param[inout]  p   A reference to a pointer address, potentially
911  *                    unaligned, to read the 16-bit value from and to
912  *                    then increment by 16-bits (2 bytes).
913  *
914  * @return The 16-bit value at the specified pointer address.
915  */
916 static inline uint16_t Read16(const void *&p)
917 {
918     return nlIORead16(&p);
919 }
920
921 /**
922  * Perform a, potentially unaligned, memory read of the 32-bit value
923  * from the specified pointer address and increment the pointer by
924  * 32-bits (4 bytes).
925  *
926  * @param[inout]  p   A reference to a pointer address, potentially
927  *                    unaligned, to read the 32-bit value from and to
928  *                    then increment by 32-bits (4 bytes).
929  *
930  * @return The 32-bit value at the specified pointer address.
931  */
932 static inline uint32_t Read32(const void *&p)
933 {
934     return nlIORead32(&p);
935 }
936
937 /**
938  * Perform a, potentially unaligned, memory read of the 64-bit value
939  * from the specified pointer address and increment the pointer by
940  * 64-bits (8 bytes).
941  *
942  * @param[inout]  p   A reference to a pointer address, potentially
943  *                    unaligned, to read the 64-bit value from and to
944  *                    then increment by 64-bits (8 bytes).
945  *
946  * @return The 64-bit value at the specified pointer address.
947  */
948 static inline uint64_t Read64(const void *&p)
949 {
950     return nlIORead64(&p);
951 }
952
953 /**
954  * Perform a, potentially unaligned, memory write of the 8-bit value
955  * to the specified pointer address and increment the pointer by
956  * 8-bits (1 byte).
957  *
958  * @param[inout]  p   A reference to a pointer address, potentially
959  *                    unaligned, to read the 8-bit value from and to
960  *                    then increment by 8-bits (1 byte).
961  *
962  * @param[in]     v   The 8-bit value to write.
963  *
964  */
965 static inline void Write8(void *&p, const uint8_t v)
966 {
967     nlIOWrite8(&p, v);
968 }
969
970 /**
971  * Perform a, potentially unaligned, memory write of the 16-bit value
972  * to the specified pointer address and increment the pointer by
973  * 16-bits (2 bytes).
974  *
975  * @param[inout]  p   A reference to a pointer address, potentially
976  *                    unaligned, to read the 16-bit value from and to
977  *                    then increment by 16-bits (2 bytes).
978  *
979  * @param[in]     v   The 16-bit value to write.
980  *
981  */
982 static inline void Write16(void *&p, const uint16_t v)
983 {
984     nlIOWrite16(&p, v);
985 }
986
987 /**
988  * Perform a, potentially unaligned, memory write of the 32-bit value
989  * to the specified pointer address and increment the pointer by
990  * 32-bits (4 bytes).
991  *
992  * @param[inout]  p   A reference to a pointer address, potentially
993  *                    unaligned, to read the 32-bit value from and to
994  *                    then increment by 32-bits (4 bytes).
995  *
996  * @param[in]     v   The 32-bit value to write.
997  *
998  */
999 static inline void Write32(void *&p, const uint32_t v)
1000 {
1001     nlIOWrite32(&p, v);
1002 }
1003
1004 /**
1005  * Perform a, potentially unaligned, memory write of the 64-bit value
1006  * to the specified pointer address and increment the pointer by
1007  * 64-bits (8 bytes).
1008  *
1009  * @param[inout]  p   A reference to a pointer address, potentially
1010  *                    unaligned, to read the 64-bit value from and to
1011  *                    then increment by 64-bits (8 bytes).
1012  *
1013  * @param[in]     v   The 64-bit value to write.
1014  *
1015  */
1016 static inline void Write64(void *&p, const uint64_t v)
1017 {
1018     nlIOWrite64(&p, v);
1019 }
1020
1021 } // namespace IO
1022
1023 } // namespace nl
1024
1025 #endif // NLIO_BASE_HPP