Création d'un compte pour un collaborateur extérieur au laboratoire depuis l'intranet ICube : https://intranet.icube.unistra.fr/fr/labs/member/profile

mark.h 4.56 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*******************************************************************************
* CGoGN: Combinatorial and Geometric modeling with Generic N-dimensional Maps  *
* version 0.1                                                                  *
* Copyright (C) 2009, IGG Team, LSIIT, University of Strasbourg                *
*                                                                              *
* This library is free software; you can redistribute it and/or modify it      *
* under the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation; either version 2.1 of the License, or (at your     *
* option) any later version.                                                   *
*                                                                              *
* This library is distributed in the hope that it will be useful, but WITHOUT  *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or        *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License  *
* for more details.                                                            *
*                                                                              *
* You should have received a copy of the GNU Lesser General Public License     *
* along with this library; if not, write to the Free Software Foundation,      *
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.           *
*                                                                              *
* Web site: https://iggservis.u-strasbg.fr/CGoGN/                              *
* Contact information: cgogn@unistra.fr                                        *
*                                                                              *
*******************************************************************************/

#ifndef _MARK_H_
#define _MARK_H_

#include <cassert>
#include <string>
#include <iostream>
#include <sstream>

namespace CGoGN
{

//! A Mark object is a set of boolean flags.
/*! The values are stored as bits in a integral value.
 *  Each single bit means: 1 = YES / 0 = NO.
 *  Operation on bits are performed through classical AND / OR / XOR
 *  operators on the integral value. 
 */
class Mark
{
	friend class MarkerSet;

	typedef unsigned int value_type;
	value_type m_bits;

public:
	//! Return the number of single marks (or bits) in a Mark
	static unsigned getNbMarks()
	{
		return 8 * sizeof(Mark);
	};

	//! Constructor
	Mark() : m_bits(0) {};

59
	Mark(unsigned int a) : m_bits(a) {};
Pierre Kraemer's avatar
Pierre Kraemer committed
60
61
62
63
64
65
66
67
68
69
70
71
72
73

	//! Copy constructor
	Mark(const Mark& m) : m_bits(m.m_bits) {};

	static std::string CGoGNnameOfType() { return "Mark"; }

	//! Logical OR on two marks
	Mark operator+(const Mark m) const
	{
		Mark n(*this);
		n.setMark(m);
		return n;
	}

74
75
76
77
78
	inline void clear()
	{
		m_bits = 0;
	}

Pierre Kraemer's avatar
Pierre Kraemer committed
79
80
81
82
	//! Test if all marks are set to NO (0)
	inline bool isClear()
	{
		return (m_bits == 0);
83
	}
Pierre Kraemer's avatar
Pierre Kraemer committed
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173

	//! Set given marks to YES
	/*! @param m the marks to set
	 */
	inline void setMark(const Mark m)
	{
		m_bits |= m.m_bits;
	}

	//! Unset given marks or set them to NO
	/*! @param m the marks to unset
	 */
	inline void unsetMark(const Mark m)
	{
		m_bits &= ~m.m_bits;
	}

	//! Test if the given marks are set to YES
	/*! @param m the marks to test
	 */
	inline bool testMark(const Mark m) const
	{
		return (m_bits & m.m_bits) != 0;
	}

	//! Return the state of the mark as value_type
	inline value_type getMarkVal() const
	{
        return m_bits;
	}

	//! Save the binary state of mark in a string
	std::string getMarkAsBinaryString() const
	{
		std::ostringstream oss;
		// transforme la chaine en binaire (plus lisible)
		value_type v = m_bits;
		for (unsigned int i = 0; i < 8*sizeof(value_type); ++i)
		{
			oss << (v%2);
			v = v >> 1;
		}
		return oss.str();
	}

	//! Save the state of mark in a string
	std::string getMarkAsString() const
	{
		std::ostringstream oss;
		oss << m_bits;
		return oss.str();
	}

	//! Set marks from a saved state
	void setMarkVal(const value_type bits)
	{
        m_bits = bits;
	}

	//! Set marks from a saved state
	void setMarkVal(const std::string& state)
	{
		std::istringstream iss(state);
		iss >> m_bits;
	}

	//! Stream output operator
	friend std::ostream& operator<<(std::ostream& s, const Mark m)
	{
		s << m.m_bits;
		return s;
	}

	//! Stream output operator
	friend std::istream& operator>>(std::istream& s, Mark& m)
	{
		s >> m.m_bits;
		return s;
	}

	// math operator (fake, juste here to enable compilation)
	void operator +=(const Mark& m) {}
	void operator -=(const Mark& m) {}
	void operator *=(double a) {}
	void operator /=(double a) {}
};

} // namespace CGoGN

#endif