7 * Written by Keith Marshall <keithmarshall@users.sourceforge.net>
8 * Copyright (C) 2009, 2010, 2011, MinGW Project
11 * Public interface for the package version comparator module, as
12 * implemented in the "C++" language file "vercmp.cpp".
15 * This is free software. Permission is granted to copy, modify and
16 * redistribute this software, under the provisions of the GNU General
17 * Public License, Version 3, (or, at your option, any later version),
18 * as published by the Free Software Foundation; see the file COPYING
19 * for licensing details.
21 * Note, in particular, that this software is provided "as is", in the
22 * hope that it may prove useful, but WITHOUT WARRANTY OF ANY KIND; not
23 * even an implied WARRANTY OF MERCHANTABILITY, nor of FITNESS FOR ANY
24 * PARTICULAR PURPOSE. Under no circumstances will the author, or the
25 * MinGW Project, accept liability for any damages, however caused,
26 * arising from the use of this software.
34 { /* The constituent elements of a package version number,
35 * and build serial number, in sequential order as they appear
36 * within a correctly formed package tarball name.
44 /* Not a real element of the version/serial number sequence,
45 * but this final entry in the enumeration provides a convenient
46 * counter for the number of real elements listed above.
53 /* Internal structure, used to capture an individual element
54 * of a decomposed version number, or build serial number.
62 * Define the properties of the "C++" class API...
66 /* A class for capture and manipulation of package version numbers
67 * in decomposed "major.minor.patch-datetamp-sequence" form.
70 inline pkgVersionInfo( const char* version = "", const char* build = NULL )
73 * This expects either one or two "char *" arguments:
74 * the first is the package version number, in "major.minor.patch"
75 * format; the second is build serial number in "datestamp-sequence"
76 * format. If the second is omitted, the build serial number may
77 * be appended to the first, in the full format as above.
79 * Note that we inline the constructor itself, but we then delegate
80 * its entire implementation to the Parse() method, to facilitate...
82 Parse( version, build );
84 inline void Reset( const char* version = "", const char* build = NULL )
86 /* ...implementation of this "reconstructor" method, which permits
87 * us to reassign alternative content to an existing instance of the
88 * class, (after first clearing out all previous content).
90 FreeAll(); Parse( version, build );
94 * This must release all heap memory allocated for parsed class data.
96 inline ~pkgVersionInfo(){ FreeAll(); }
98 /* Package version comparison operators.
100 bool operator<( const pkgVersionInfo& );
101 bool operator<=( const pkgVersionInfo& );
102 bool operator==( const pkgVersionInfo& );
103 bool operator!=( const pkgVersionInfo& );
104 bool operator>=( const pkgVersionInfo& );
105 bool operator>( const pkgVersionInfo& );
108 /* The decomposed version/serial number elements.
110 char *version_string, *build_string;
111 struct version_t version_elements[VERSION_ELEMENT_COUNT];
113 /* The separated implementation for the constructor,
114 * shared by the Reset() "reconstructor" method.
116 void Parse( const char*, const char* );
118 /* An internal comparison helper function.
120 long Compare( const pkgVersionInfo&, int );
122 inline void FreeEntry( void *mem )
124 /* Helper method to release each of the two blocks of heap
125 * memory, which are allocated to store the class data...
127 if( mem != NULL ) free( mem );
129 inline void FreeAll()
131 /* ...used by this composite helper, which releases both of
132 * these allocated memory blocks with a single call.
134 FreeEntry( version_string ); FreeEntry( build_string );
138 #endif /* __cplusplus */
139 #endif /* VERCMP_H: $RCSfile$: end of file */