/* Copyright (C) 2013-2020, Dirk Krause SPDX-License-Identifier: BSD-3-Clause */ /* WARNING: This file was generated by the dkct program (see http://dktools.sourceforge.net/ for details). Changes you make here will be lost if dkct is run again! You should modify the original source and run dkct on it. Original source: Dk4Comparable.cpt */ /** @file Dk4Comparable.h Header file for the Dk4Comparable module. */ #ifndef DK4COMPARABLE_H_INCLUDED /** Avoid multiple inclusions. */ #define DK4COMPARABLE_H_INCLUDED 1 #line 8 "Dk4Comparable.cpt" #ifndef DK4CONF_H_INCLUDED #if DK4_BUILDING_DKTOOLS4 #include "dk4conf.h" #else #include #endif #endif #if DK4_HAVE_STDLIB_H #include #endif #if DK4_HAVE_UNISTD_H #include #endif /** Namespace to protect Container and Iterator from name collisions. */ namespace DkTools4 { /** Comparable is a general base class for objects we want to compare, for example for sorted storage. Derived classes must implement the compareAgainst() method. */ class Comparable { public: /** Compare object against another object or some data. Derived classes must implement this method. The comparison is used by sorted containers. Example: When storing persons (name and age) we can use crit=0 as comparison criteria in the container to compare person object against person object. When searching the container for an object with a specific name we can use crit=1 for comparisons of the object against a string. @param pt Address of other object or data. @param crit Comparison criteria, see documentation of derived classes for class-specific numbers. @return Positive number if larger than ptr, 0 if evaluates equal to ptr, negative number if smaller than ptr. */ virtual int compareAgainst(void const *ptr, int crit) const = 0; /** Compare two pointers @param l Left pointer. @param r Right pointer. @param cr Comparison criteria. @return 1 for left object is large, 0 for right object is large, 0 for objects evaluating equally. */ static int compareTwoPointers(void const *l, void const *r, int cr); /** Virtual destructor required by compiler. */ virtual ~Comparable(); }; /* End of class Comparable. */ } /* End of namespace DkTools4 */ #endif