flags.hh revision 5764
15734Snate@binkert.org/* 25734Snate@binkert.org * Copyright (c) 2008 The Hewlett-Packard Development Company 35734Snate@binkert.org * All rights reserved. 45734Snate@binkert.org * 55734Snate@binkert.org * Redistribution and use in source and binary forms, with or without 65734Snate@binkert.org * modification, are permitted provided that the following conditions are 75734Snate@binkert.org * met: redistributions of source code must retain the above copyright 85734Snate@binkert.org * notice, this list of conditions and the following disclaimer; 95734Snate@binkert.org * redistributions in binary form must reproduce the above copyright 105734Snate@binkert.org * notice, this list of conditions and the following disclaimer in the 115734Snate@binkert.org * documentation and/or other materials provided with the distribution; 125734Snate@binkert.org * neither the name of the copyright holders nor the names of its 135734Snate@binkert.org * contributors may be used to endorse or promote products derived from 145734Snate@binkert.org * this software without specific prior written permission. 155734Snate@binkert.org * 165734Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 175734Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 185734Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 195734Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 205734Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 215734Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 225734Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 235734Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 245734Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 255734Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 265734Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 275734Snate@binkert.org * 285734Snate@binkert.org * Authors: Nathan Binkert 295734Snate@binkert.org */ 305734Snate@binkert.org 315734Snate@binkert.org#ifndef __BASE_FLAGS_HH__ 325734Snate@binkert.org#define __BASE_FLAGS_HH__ 335734Snate@binkert.org 345734Snate@binkert.orgtemplate <typename T> 355734Snate@binkert.orgclass Flags 365734Snate@binkert.org{ 375734Snate@binkert.org private: 385734Snate@binkert.org T _flags; 395734Snate@binkert.org 405734Snate@binkert.org public: 415734Snate@binkert.org typedef T Type; 425734Snate@binkert.org Flags() : _flags(0) {} 435734Snate@binkert.org Flags(Type flags) : _flags(flags) {} 445734Snate@binkert.org 455734Snate@binkert.org operator const Type() const { return _flags; } 465734Snate@binkert.org 475734Snate@binkert.org template <typename U> 485734Snate@binkert.org const Flags<T> & 495734Snate@binkert.org operator=(const Flags<U> &flags) 505734Snate@binkert.org { 515734Snate@binkert.org _flags = flags._flags; 525734Snate@binkert.org return *this; 535734Snate@binkert.org } 545734Snate@binkert.org 555734Snate@binkert.org const Flags<T> & 565734Snate@binkert.org operator=(T flags) 575734Snate@binkert.org { 585734Snate@binkert.org _flags = flags; 595734Snate@binkert.org return *this; 605734Snate@binkert.org } 615734Snate@binkert.org 625764Snate@binkert.org bool isSet() const { return _flags; } 635764Snate@binkert.org bool isSet(Type flags) const { return (_flags & flags); } 645764Snate@binkert.org bool allSet() const { return !(~_flags); } 655764Snate@binkert.org bool allSet(Type flags) const { return (_flags & flags) == flags; } 665764Snate@binkert.org bool noneSet() const { return _flags == 0; } 675764Snate@binkert.org bool noneSet(Type flags) const { return (_flags & flags) == 0; } 685734Snate@binkert.org void clear() { _flags = 0; } 695734Snate@binkert.org void clear(Type flags) { _flags &= ~flags; } 705734Snate@binkert.org void set(Type flags) { _flags |= flags; } 715745Snate@binkert.org void set(Type f, bool val) { _flags = (_flags & ~f) | (val ? f : 0); } 725734Snate@binkert.org void 735734Snate@binkert.org update(Type flags, Type mask) 745734Snate@binkert.org { 755734Snate@binkert.org _flags = (_flags & ~mask) | (flags & mask); 765734Snate@binkert.org } 775734Snate@binkert.org}; 785734Snate@binkert.org 795734Snate@binkert.org#endif // __BASE_FLAGS_HH__ 80