libptpmgmt  1.4
libptpmgmt library that provides the functionality of linuxptp pmc
buf.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: LGPL-3.0-or-later
2  SPDX-FileCopyrightText: Copyright © 2021 Erez Geva <ErezGeva2@gmail.com> */
3 
12 #ifndef __PTPMGMT_BUF_H
13 #define __PTPMGMT_BUF_H
14 
15 #ifdef __cplusplus
16 #include "name.h"
17 
18 __PTPMGMT_NAMESPACE_BEGIN
19 
25 class Buf
26 {
27  private:
28  void *m_buf = nullptr;
29  size_t m_size = 0;
30  public:
31  Buf() = default;
36  Buf(size_t size) {alloc(size);}
37  ~Buf();
43  bool alloc(size_t size);
48  void *get() const {return m_buf;}
53  void *operator()() const {return m_buf;}
58  size_t size() const {return m_size;}
63  bool isAlloc() const {return m_size > 0;}
64 };
65 
66 __PTPMGMT_NAMESPACE_END
67 #else /* __cplusplus */
68 #error "this header is for C++ and scripts use only, NOT for C"
69 #endif /* __cplusplus */
70 
71 #endif /* __PTPMGMT_BUF_H */
Definition: buf.h:26
Buf(size_t size)
Definition: buf.h:36
bool alloc(size_t size)
size_t size() const
Definition: buf.h:58
bool isAlloc() const
Definition: buf.h:63
void * get() const
Definition: buf.h:48
void * operator()() const
Definition: buf.h:53
Define name space.