ModuleVersion.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2018-2019, Dataspeed Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Dataspeed Inc. nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 #ifndef _DBW_FCA_CAN_MODULE_VERSION_H
36 #define _DBW_FCA_CAN_MODULE_VERSION_H
37 #include <stdint.h>
38 #include <endian.h>
39 
40 // Undefine GNU C system macros that we use for other purposes
41 #ifdef major
42 #undef major
43 #endif
44 #ifdef minor
45 #undef minor
46 #endif
47 
48 namespace dbw_fca_can
49 {
50 
52 public:
53  ModuleVersion() : full(0) {};
54  ModuleVersion(uint16_t major, uint16_t minor, uint16_t build) : major_(major), minor_(minor), build_(build), extra_(0) {};
55  bool operator< (const ModuleVersion& other) const { return this->full < other.full; }
56  bool operator> (const ModuleVersion& other) const { return this->full > other.full; }
57  bool operator<=(const ModuleVersion& other) const { return this->full <= other.full; }
58  bool operator>=(const ModuleVersion& other) const { return this->full >= other.full; }
59  bool operator==(const ModuleVersion& other) const { return this->full == other.full; }
60  bool operator!=(const ModuleVersion& other) const { return this->full != other.full; }
61  bool valid() const { return full != 0; }
62  uint16_t major() const { return major_; }
63  uint16_t minor() const { return minor_; }
64  uint16_t build() const { return build_; }
65 private:
66  union {
67  uint64_t full;
68  struct {
69 #if __BYTE_ORDER == __LITTLE_ENDIAN
70  uint16_t build_; uint16_t minor_; uint16_t major_; uint16_t extra_;
71 #elif __BYTE_ORDER == __BIG_ENDIAN
72  uint16_t extra_; uint16_t major_; uint16_t minor_; uint16_t build_;
73 #else
74 #error Failed to determine system endianness
75 #endif
76  };
77  };
78 };
79 
80 } //namespace dbw_fca_can
81 
82 #endif // _DBW_FCA_CAN_MODULE_VERSION_H
83 
bool operator!=(const ModuleVersion &other) const
Definition: ModuleVersion.h:60
bool operator>=(const ModuleVersion &other) const
Definition: ModuleVersion.h:58
uint16_t minor() const
Definition: ModuleVersion.h:63
bool operator<(const ModuleVersion &other) const
Definition: ModuleVersion.h:55
uint16_t build() const
Definition: ModuleVersion.h:64
ModuleVersion(uint16_t major, uint16_t minor, uint16_t build)
Definition: ModuleVersion.h:54
bool operator>(const ModuleVersion &other) const
Definition: ModuleVersion.h:56
bool operator<=(const ModuleVersion &other) const
Definition: ModuleVersion.h:57
bool operator==(const ModuleVersion &other) const
Definition: ModuleVersion.h:59
uint16_t major() const
Definition: ModuleVersion.h:62


dbw_fca_can
Author(s): Kevin Hallenbeck
autogenerated on Wed May 12 2021 02:14:05