1 /*
2  * mp3plot - Bitrate analysis tool
3  *
4  * Copyright (C) 2007, 2009 Toni Corvera
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 
21 // $Id: plotter_features.cc 1090 2009-04-01 20:15:14Z  $
22 
23 #include "plotter_features.h"
24 
25 #include <iostream>
26 
27 namespace mp3plot {
28 
29 // Constants
30 // These are used in the bitset so their binary representation must not overlap
31 const plotter_features::constant_type
32                     plotter_features::TEXTUAL   = 0x01U,
33                     plotter_features::GRAPHICAL = 0x02U,
34                     plotter_features::MARKUP    = 0x04U,
35                     plotter_features::PRINTED   = 0x08U,
36                     plotter_features::FILE      = 0x10U;
37 
plotter_features(const bitset_type & b)38 plotter_features::plotter_features(const bitset_type & b)
39     : bits(b)
40 {}
41 
textual()42 const plotter_features plotter_features::textual() {
43     return plotter_features(TEXTUAL);
44 }
45 
graphical()46 const plotter_features plotter_features::graphical() {
47     return plotter_features(GRAPHICAL);
48 }
49 
printed()50 const plotter_features plotter_features::printed() {
51     return plotter_features(PRINTED);
52 }
53 
file()54 const plotter_features plotter_features::file() {
55     return plotter_features(FILE);
56 }
57 
operator ==(const plotter_features & to) const58 bool plotter_features::operator==(const plotter_features & to) const {
59     if (this == &to) {
60         return true;
61     }
62 
63     return to.bits == bits;
64 }
65 
operator >(const plotter_features & p) const66 bool plotter_features::operator>(const plotter_features & p) const {
67     return (p != *this) && (bits & p.bits).any();
68 }
69 
operator >=(const plotter_features & p) const70 bool plotter_features::operator>=(const plotter_features & p) const {
71     return (p == *this) || (bits & p.bits).any();
72 }
73 
74 
operator |(const plotter_features & p) const75 plotter_features plotter_features::operator|(const plotter_features & p) const {
76     return plotter_features(bits | p.bits);
77 }
78 
operator &(const plotter_features & p) const79 plotter_features plotter_features::operator&(const plotter_features & p) const {
80     return plotter_features(bits & p.bits);
81 }
82 
operator ^(const plotter_features & p) const83 plotter_features plotter_features::operator^(const plotter_features & p) const {
84     return plotter_features(bits ^ p.bits);
85 }
86 
operator !() const87 plotter_features plotter_features::operator!() const {
88     return plotter_features( (bitset_type(bits)).flip() );
89 }
90 
91 // [C++] local visibility
92 namespace {
YESNO(bool v)93     inline const char * YESNO(bool v) {
94         return ( v ? "yes" : "no" );
95     }
96 }
97 
98 // output operator
operator <<(std::ostream & os,const plotter_features & pf)99 std::ostream & operator<<(std::ostream & os, const plotter_features & pf) {
100     typedef plotter_features::bitset_type bst;
101 
102     const bst t = bst(plotter_features::TEXTUAL),
103               g = bst(plotter_features::GRAPHICAL),
104               m = bst(plotter_features::MARKUP),
105               p = bst(plotter_features::PRINTED),
106               f = bst(plotter_features::FILE);
107 
108     return os <<
109     "is_textual = "     << YESNO( (pf.bits & t).any() ) <<
110     "\nis_graphical = " << YESNO( (pf.bits & g).any() ) <<
111     "\nis_markup = "    << YESNO( (pf.bits & m).any() ) <<
112     "\nis_printed = "   << YESNO( (pf.bits & p).any() ) <<
113     "\nis_file = "      << YESNO( (pf.bits & f).any() ) <<
114     "\n";
115 }
116 
operator <<(std::ostream & os,const plotter_description & pd)117 std::ostream & operator<<(std::ostream & os, const plotter_description & pd) {
118     os << pd.name() << ": ";
119 
120     bool ws = false, pws = false;
121     if ((ws = (pd.feats_ > plotter_features::textual()) )) {
122         os << "textual";
123         pws = ws;
124     }
125     if ((ws = (pd.feats_ > plotter_features::graphical()) )) {
126         os << (pws ? ", " : "") << "graphical";
127         pws = ws;
128     }
129 
130     if ((ws = (pd.feats_ > plotter_features::printed()) )) {
131         os << (pws ? ", " : "") << "printed";
132         pws = ws;
133     }
134     if ((ws = (pd.feats_ > plotter_features::file()) )) {
135         os << (pws ? ", " : "") << "file output";
136         pws = ws;
137     }
138 
139     return os;
140 }
141 
142 } // namespace mp3plot
143 
144 // vim:set ts=4 et ai:
145 
146