/usr/include/sofa/helper/fixed_array.h is in libsofa1-dev 1.0~beta4-10ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 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 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 | /******************************************************************************
* SOFA, Simulation Open-Framework Architecture, version 1.0 beta 4 *
* (c) 2006-2009 MGH, INRIA, USTL, UJF, CNRS *
* *
* 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. *
*******************************************************************************
* SOFA :: Framework *
* *
* Authors: M. Adam, J. Allard, B. Andre, P-J. Bensoussan, S. Cotin, C. Duriez,*
* H. Delingette, F. Falipou, F. Faure, S. Fonteneau, L. Heigeas, C. Mendoza, *
* M. Nesme, P. Neumann, J-P. de la Plata Alcade, F. Poyer and F. Roy *
* *
* Contact information: contact@sofa-framework.org *
******************************************************************************/
/* The following code declares class array,
* an STL container (as wrapper) for arrays of constant size.
*
* See
* http://www.josuttis.com/cppcode
* for details and the latest version.
*
* (C) Copyright Nicolai M. Josuttis 2001.
* Permission to copy, use, modify, sell and distribute this software
* is granted provided this copyright notice appears in all copies.
* This software is provided "as is" without express or implied
* warranty, and with no claim as to its suitability for any purpose.
*
* 29 Jun 2005 - remove boost includes and reverse iterators. (Jeremie Allard)
* 23 Aug 2002 - fix for Non-MSVC compilers combined with MSVC libraries.
* 05 Aug 2001 - minor update (Nico Josuttis)
* 20 Jan 2001 - STLport fix (Beman Dawes)
* 29 Sep 2000 - Initial Revision (Nico Josuttis)
*/
// See http://www.boost.org/libs/array for Documentation.
// FF added operator <
// JA added constructors from tuples
#ifndef SOFA_HELPER_FIXED_ARRAY_H
#define SOFA_HELPER_FIXED_ARRAY_H
#if !defined(__GNUC__) || (__GNUC__ > 3 || (_GNUC__ == 3 && __GNUC_MINOR__ > 3))
#pragma once
#endif
#include <sofa/helper/system/config.h>
#include <sofa/helper/helper.h>
#include <boost/static_assert.hpp>
#include <cstddef>
#include <stdexcept>
#include <iterator>
#include <algorithm>
#include <math.h>
namespace sofa
{
namespace helper
{
template<class T, std::size_t N>
class fixed_array
{
public:
T elems[N]; // fixed-size array of elements of type T
public:
// type definitions
typedef T value_type;
typedef T* iterator;
typedef const T* const_iterator;
typedef T& reference;
typedef const T& const_reference;
typedef std::size_t size_type;
typedef std::ptrdiff_t difference_type;
fixed_array()
{
}
/// Specific constructor for 1-element vectors.
explicit fixed_array(value_type r1)
{
BOOST_STATIC_ASSERT(N==1);
this->elems[0]=r1;
}
/// Specific constructor for 2-elements vectors.
fixed_array(value_type r1, value_type r2)
{
BOOST_STATIC_ASSERT(N == 2);
this->elems[0]=r1;
this->elems[1]=r2;
}
/// Specific constructor for 3-elements vectors.
fixed_array(value_type r1, value_type r2, value_type r3)
{
BOOST_STATIC_ASSERT(N == 3);
this->elems[0]=r1;
this->elems[1]=r2;
this->elems[2]=r3;
}
/// Specific constructor for 4-elements vectors.
fixed_array(value_type r1, value_type r2, value_type r3, value_type r4)
{
BOOST_STATIC_ASSERT(N == 4);
this->elems[0]=r1;
this->elems[1]=r2;
this->elems[2]=r3;
this->elems[3]=r4;
}
/// Specific constructor for 5-elements vectors.
fixed_array(value_type r1, value_type r2, value_type r3, value_type r4, value_type r5)
{
BOOST_STATIC_ASSERT(N == 5);
this->elems[0]=r1;
this->elems[1]=r2;
this->elems[2]=r3;
this->elems[3]=r4;
this->elems[4]=r5;
}
/// Specific constructor for 6-elements vectors.
fixed_array(value_type r1, value_type r2, value_type r3, value_type r4, value_type r5, value_type r6)
{
BOOST_STATIC_ASSERT(N == 6);
this->elems[0]=r1;
this->elems[1]=r2;
this->elems[2]=r3;
this->elems[3]=r4;
this->elems[4]=r5;
this->elems[5]=r6;
}
/// Specific constructor for 7-elements vectors.
fixed_array(value_type r1, value_type r2, value_type r3, value_type r4, value_type r5, value_type r6, value_type r7)
{
BOOST_STATIC_ASSERT(N == 7);
this->elems[0]=r1;
this->elems[1]=r2;
this->elems[2]=r3;
this->elems[3]=r4;
this->elems[4]=r5;
this->elems[5]=r6;
this->elems[6]=r7;
}
/// Specific constructor for 8-elements vectors.
fixed_array(value_type r1, value_type r2, value_type r3, value_type r4, value_type r5, value_type r6, value_type r7, value_type r8)
{
BOOST_STATIC_ASSERT(N == 8);
this->elems[0]=r1;
this->elems[1]=r2;
this->elems[2]=r3;
this->elems[3]=r4;
this->elems[4]=r5;
this->elems[5]=r6;
this->elems[6]=r7;
this->elems[7]=r8;
}
/// Specific constructor for 9-elements vectors.
fixed_array(value_type r1, value_type r2, value_type r3, value_type r4, value_type r5, value_type r6, value_type r7, value_type r8, value_type r9)
{
BOOST_STATIC_ASSERT(N == 9);
this->elems[0]=r1;
this->elems[1]=r2;
this->elems[2]=r3;
this->elems[3]=r4;
this->elems[4]=r5;
this->elems[5]=r6;
this->elems[6]=r7;
this->elems[7]=r8;
this->elems[8]=r9;
}
/// Specific constructor for 10-elements vectors.
fixed_array(value_type r1, value_type r2, value_type r3, value_type r4, value_type r5, value_type r6, value_type r7, value_type r8, value_type r9, value_type r10)
{
BOOST_STATIC_ASSERT(N == 10);
this->elems[0]=r1;
this->elems[1]=r2;
this->elems[2]=r3;
this->elems[3]=r4;
this->elems[4]=r5;
this->elems[5]=r6;
this->elems[6]=r7;
this->elems[7]=r8;
this->elems[8]=r9;
this->elems[9]=r10;
}
// iterator support
iterator begin()
{
return elems;
}
const_iterator begin() const
{
return elems;
}
iterator end()
{
return elems+N;
}
const_iterator end() const
{
return elems+N;
}
// operator[]
reference operator[](size_type i)
{
return elems[i];
}
const_reference operator[](size_type i) const
{
return elems[i];
}
// at() with range check
reference at(size_type i)
{
rangecheck(i);
return elems[i];
}
const_reference at(size_type i) const
{
rangecheck(i);
return elems[i];
}
// front() and back()
reference front()
{
return elems[0];
}
const_reference front() const
{
return elems[0];
}
reference back()
{
return elems[N-1];
}
const_reference back() const
{
return elems[N-1];
}
// size is constant
static size_type size()
{
return N;
}
static bool empty()
{
return false;
}
static size_type max_size()
{
return N;
}
enum { static_size = N };
// swap (note: linear complexity)
void swap (fixed_array<T,N>& y)
{
std::swap_ranges(begin(),end(),y.begin());
}
// direct access to data
const T* data() const
{
return elems;
}
// assignment with type conversion
template <typename T2>
fixed_array<T,N>& operator= (const fixed_array<T2,N>& rhs)
{
//std::copy(rhs.begin(),rhs.end(), begin());
for (size_type i=0;i<N;i++)
elems[i] = rhs[i];
return *this;
}
// assign one value to all elements
void assign (const T& value)
{
//std::fill_n(begin(),size(),value);
for (size_type i=0;i<N;i++)
elems[i] = value;
}
inline friend std::ostream& operator << (std::ostream& out, const fixed_array<T,N>& a)
{
for( size_type i=0; i<N; i++ )
out<<a.elems[i]<<" ";
return out;
}
inline friend std::istream& operator >> (std::istream& in, fixed_array<T,N>& a)
{
for( size_type i=0; i<N; i++ )
in>>a.elems[i];
return in;
}
inline bool operator < (const fixed_array& v ) const {
for( size_type i=0; i<N; i++ ){
if( elems[i]<v[i] )
return true; // (*this)<v
else if( elems[i]>v[i] )
return false; // (*this)>v
}
return false; // (*this)==v
}
private:
// check range (may be private because it is static)
static void rangecheck (size_type i)
{
if (i >= size())
{
throw std::range_error("fixed_array");
}
}
};
template<class T>
inline fixed_array<T, 2> make_array(const T& v0, const T& v1)
{
fixed_array<T, 2> v;
v[0] = v0;
v[1] = v1;
return v;
}
template<class T>
inline fixed_array<T, 3> make_array(const T& v0, const T& v1, const T& v2)
{
fixed_array<T, 3> v;
v[0] = v0;
v[1] = v1;
v[2] = v2;
return v;
}
template<class T>
inline fixed_array<T, 4> make_array(const T& v0, const T& v1, const T& v2, const T& v3)
{
fixed_array<T, 4> v;
v[0] = v0;
v[1] = v1;
v[2] = v2;
v[3] = v3;
return v;
}
template<class T>
inline fixed_array<T, 5> make_array(const T& v0, const T& v1, const T& v2, const T& v3, const T& v4)
{
fixed_array<T, 5> v;
v[0] = v0;
v[1] = v1;
v[2] = v2;
v[3] = v3;
v[4] = v4;
return v;
}
template<class T>
inline fixed_array<T, 6> make_array(const T& v0, const T& v1, const T& v2, const T& v3, const T& v4, const T& v5)
{
fixed_array<T, 6> v;
v[0] = v0;
v[1] = v1;
v[2] = v2;
v[3] = v3;
v[4] = v4;
v[5] = v5;
return v;
}
template<class T>
inline fixed_array<T, 7> make_array(const T& v0, const T& v1, const T& v2, const T& v3, const T& v4, const T& v5, const T& v6)
{
fixed_array<T, 7> v;
v[0] = v0;
v[1] = v1;
v[2] = v2;
v[3] = v3;
v[4] = v4;
v[5] = v5;
v[6] = v6;
return v;
}
template<class T>
inline fixed_array<T, 8> make_array(const T& v0, const T& v1, const T& v2, const T& v3, const T& v4, const T& v5, const T& v6, const T& v7)
{
fixed_array<T, 8> v;
v[0] = v0;
v[1] = v1;
v[2] = v2;
v[3] = v3;
v[4] = v4;
v[5] = v5;
v[6] = v6;
v[7] = v7;
return v;
}
template<class T>
inline fixed_array<T, 9> make_array(const T& v0, const T& v1, const T& v2, const T& v3, const T& v4, const T& v5, const T& v6, const T& v7, const T& v8)
{
fixed_array<T, 9> v;
v[0] = v0;
v[1] = v1;
v[2] = v2;
v[3] = v3;
v[4] = v4;
v[5] = v5;
v[6] = v6;
v[7] = v7;
v[8] = v8;
return v;
}
template<class T>
inline fixed_array<T, 10> make_array(const T& v0, const T& v1, const T& v2, const T& v3, const T& v4, const T& v5, const T& v6, const T& v7, const T& v8, const T& v9)
{
fixed_array<T, 10> v;
v[0] = v0;
v[1] = v1;
v[2] = v2;
v[3] = v3;
v[4] = v4;
v[5] = v5;
v[6] = v6;
v[7] = v7;
v[8] = v8;
v[9] = v9;
return v;
}
} // namespace helper
} // namespace sofa
#endif
|