ich hab eine klasse entwickelt, die eine BOOLEAN simuliert!



  • #define IS_TRUE_TRUE 1
    #define IS_FALSE_FALSE 0

    enum BOOLEAN
    {
    FALSE, TRUE
    }

    class CBOOLEANCLASS
    {
    private:
    int IS_TRUE;
    int IS_FALSE;

    public:
    CBOOLEANCLASS()
    {
    IS_TRUE = IS_TRUE_FALSE;
    IS_FALSE = IS_FALSE_FALSE;
    }

    CBOOLEANCLASS(BOOLEAN INITIALVALUE)
    {
    if(INITIALVALUE == BOOLEAN::FALSE)
    {
    IS_TRUE = IS_TRUE_TRUE;
    IS_FALSE = IS_FALSE_FALSE;
    }
    else
    {
    IS_TRUE = IS_TRUE_FALSE;
    IS_FALSE = IS_FALSE_TRUE;
    }
    }

    BOOLEAN IS_TRUE()
    {
    if(IS_TRUE == BOOLEAN::TRUE && IS_FALSE == BOOLEAN::FALSE)
    return BOOLEAN::TRUE;
    else
    return BOOLEAN::FALSE;
    }

    BOOLEAN IS_FALSE()
    {
    if(IS_TRUE() == BOOLEAN::TRUE)
    return BOOLEAN::FALSE;
    else
    return BOOLEAN::TRUE;
    }

    }

    geht es eigentlich noch besser?? ich würde sagen, da habe ich sehr
    gute arbeit geleistet. vielleicht kann sich ja mal jemand von euch
    gebrachen. bitteschön!



  • -.-

    wow das sieht echt toll aus ich suche genau sowas für mein projekt !!!

    ich hab auch schonmal eine boolean klasse-geschrieben :

    typedef char BOOLEAN;
    #define false 0
    #define true 1
    
    unglaublich  :D  und dabei um über 30 zeilen kürzer
    


  • #define IS_TRUE_TRUE 1
    #define IS_FALSE_FALSE 0
    
    enum BOOLEAN
    {
    FALSE, TRUE
    }
    
    class CBOOLEANCLASS
    {
    private:
    int IS_TRUE;
    int IS_FALSE;
    
    public:
    CBOOLEANCLASS()
    {
    IS_TRUE = IS_TRUE_FALSE;
    IS_FALSE = IS_FALSE_FALSE;
    }
    
    CBOOLEANCLASS(BOOLEAN INITIALVALUE)
    {
    if(INITIALVALUE == BOOLEAN::FALSE)
    {
    IS_TRUE = IS_TRUE_TRUE;
    IS_FALSE = IS_FALSE_FALSE;
    }
    else
    {
    IS_TRUE = IS_TRUE_FALSE;
    IS_FALSE = IS_FALSE_TRUE;
    }
    }
    
    BOOLEAN IS_TRUE()
    {
    if(IS_TRUE == BOOLEAN::TRUE && IS_FALSE == BOOLEAN::FALSE)
    return BOOLEAN::TRUE;
    else
    return BOOLEAN::FALSE;
    }
    
    BOOLEAN IS_FALSE()
    {
    if(IS_TRUE() == BOOLEAN::TRUE)
    return BOOLEAN::FALSE;
    else
    return BOOLEAN::TRUE;
    }
    
    }
    

    Ich habs mal farbig gemacht, jetzt sollte es besser funktionieren



  • Das geht auch noch dreimal kürzer:
    typedef bool BOOLEAN;



  • so geht das:

    enum BOOLEAN { TRUE, FALSE, FILE_NOT_FOUND }
    


  • enum BOOLEAN { YES, NO, MAYBE };
    


  • #define FALSE (0)
    #define TRUE (1)
    #define MAYBE (rand()&1)



  • weltmarktführer schrieb:

    #define MAYBE (rand()&1)

    rofl



  • Gab es in diesem Forum nicht bereits einmal eine recht ähnliche Bool-Klasse? 😉



  • #ifndef CHUCK_NORRIS
    get_ass_kicked();
    #ifndef
    
    #define FALSE CHUCK_NORRIS_FALSE
    #define TRUE CHUCK_NORRIS_TRUE
    


  • Nexus schrieb:

    Gab es in diesem Forum nicht bereits einmal eine recht ähnliche Bool-Klasse? 😉

    Doch gab es. Die wurde aber (leider) wegeditiert. Konnte mich damals kaum auf dem Sitz halten. 🙂



  • billigekopie schrieb:

    so geht das:

    enum BOOLEAN { TRUE, FALSE, FILE_NOT_FOUND }
    

    DailyWTF?



  • Hier nochmal die Klasse aus dem damaligen Thread. Da ich dran mitgearbeitet hatte, hab ich die noch 🙂

    namespace useless_datatypes 
    { 
    	class CBoolean 
    	{ 
    	private: 
    		bool m_value; 
    
    	public: 
    		CBoolean( bool value = false ) : m_value( value ) {} 
    		virtual ~CBoolean();
    
    		operator unspecified-bool-type() const { return m_value; } 
    
    		CBoolean operator!() { return Boolean( !m_value ); } 
    		CBoolean& operator=( bool rhs ) { m_value = rhs; return *this; } 
    
    		bool IsTrue() const { return m_value == true; } 
    
    		bool IsNotTrue() const { return m_value != true; } 
    
    		bool IsFalse() const { return m_value == false; } 
    
    		bool IsNotFalse() const { return m_value != false; } 
    
    		void ToggleBool() { m_bool = !m_bool; }
    	}; 
    };
    


  • Fellhuhn schrieb:

    billigekopie schrieb:

    so geht das:

    enum BOOLEAN { TRUE, FALSE, FILE_NOT_FOUND }
    

    DailyWTF?

    Wohl noch nie mit Windows gearbeitet? Die definieren eine Funktion mit Rückgabetyp BOOL und schreiben in die Doku: Wenn der Rückgabewert positiv ist, ..., wenn er null ist, ..., wenn er negativ ist, ... (Das ist _kein_ Scherz).

    Achja zu der maybe Sache: http://www.boost.org/doc/libs/1_36_0/doc/html/tribool.html Bevor man da was händisches macht 😉

    Gruß
    Don06


Anmelden zum Antworten