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
|
// ==========================================================================
// SeqAn - The Library for Sequence Analysis
// ==========================================================================
// Copyright (c) 2006-2026, Knut Reinert, FU Berlin
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of Knut Reinert or the FU Berlin nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
//
// ==========================================================================
// Author: Enrico Siragusa <enrico.siragusa@fu-berlin.de>
// ==========================================================================
// A Position ModifiedString represents a permutation of the host string.
#ifndef SEQAN_MODIFIER_MODIFIER_POSITION_H_
#define SEQAN_MODIFIER_MODIFIER_POSITION_H_
namespace seqan2 {
// ============================================================================
// Tags, Classes, Enums
// ============================================================================
// ----------------------------------------------------------------------------
// Tag ModPos
// ----------------------------------------------------------------------------
template <typename TPositions>
struct ModPos {};
// ============================================================================
// Metafunctions
// ============================================================================
// --------------------------------------------------------------------------
// Metafunction Cargo
// --------------------------------------------------------------------------
template <typename THost, typename TPositions>
struct Cargo<ModifiedString<THost, ModPos<TPositions> > >
{
typedef typename Pointer_<TPositions>::Type Type;
};
template <typename THost, typename TPositions>
struct Cargo<ModifiedString<THost, ModPos<TPositions> > const>
{
typedef typename Pointer_<TPositions>::Type const Type;
};
// ----------------------------------------------------------------------------
// Metafunction Value
// ----------------------------------------------------------------------------
template <typename THost, typename TPositions>
struct Value<ModifiedString<THost, ModPos<TPositions> > > : Value<THost> {};
template <typename THost, typename TPositions>
struct Value<ModifiedString<THost, ModPos<TPositions> > const> : Value<THost> {};
// ----------------------------------------------------------------------------
// Metafunction GetValue
// ----------------------------------------------------------------------------
template <typename THost, typename TPositions>
struct GetValue<ModifiedString<THost, ModPos<TPositions> > > : GetValue<THost> {};
template <typename THost, typename TPositions>
struct GetValue<ModifiedString<THost, ModPos<TPositions> > const> : GetValue<THost> {};
// ----------------------------------------------------------------------------
// Metafunction Reference
// ----------------------------------------------------------------------------
template <typename THost, typename TPositions>
struct Reference<ModifiedString<THost, ModPos<TPositions> > > : Reference<THost> {};
template <typename THost, typename TPositions>
struct Reference<ModifiedString<THost, ModPos<TPositions> > const> : Reference<THost> {};
// ----------------------------------------------------------------------------
// Metafunction Difference
// ----------------------------------------------------------------------------
template <typename THost, typename TPositions>
struct Difference<ModifiedString<THost, ModPos<TPositions> > > : Difference<TPositions> {};
// ----------------------------------------------------------------------------
// Metafunction Size
// ----------------------------------------------------------------------------
template <typename THost, typename TPositions>
struct Size<ModifiedString<THost, ModPos<TPositions> > > : Size<TPositions> {};
// ----------------------------------------------------------------------------
// Metafunction Position
// ----------------------------------------------------------------------------
template <typename THost, typename TPositions>
struct Position<ModifiedString<THost, ModPos<TPositions> > > : Position<TPositions> {};
// ----------------------------------------------------------------------------
// Metafunction Iterator
// ----------------------------------------------------------------------------
template <typename THost, typename TPositions>
struct Iterator<ModifiedString<THost, ModPos<TPositions> >, Standard>
{
typedef Iter<ModifiedString<THost, ModPos<TPositions> >, PositionIterator> Type;
};
template <typename THost, typename TPositions>
struct Iterator<ModifiedString<THost, ModPos<TPositions> > const, Standard>
{
typedef Iter<ModifiedString<THost, ModPos<TPositions> > const, PositionIterator> Type;
};
template <typename THost, typename TPositions>
struct Iterator<ModifiedString<THost, ModPos<TPositions> >, Rooted>
{
typedef Iter<ModifiedString<THost, ModPos<TPositions> >, PositionIterator> Type;
};
template <typename THost, typename TPositions>
struct Iterator<ModifiedString<THost, ModPos<TPositions> > const, Rooted>
{
typedef Iter<ModifiedString<THost, ModPos<TPositions> > const, PositionIterator> Type;
};
// ----------------------------------------------------------------------------
// Metafunction Prefix
// ----------------------------------------------------------------------------
// NOTE(esiragusa): not implemented.
// ----------------------------------------------------------------------------
// Metafunction Suffix
// ----------------------------------------------------------------------------
// NOTE(esiragusa): not implemented.
// ----------------------------------------------------------------------------
// Metafunction Infix
// ----------------------------------------------------------------------------
template <typename THost, typename TPositions>
struct Infix<ModifiedString<THost, ModPos<TPositions> > >
{
typedef ModifiedString<THost, ModPos<typename Infix<TPositions>::Type> > Type;
};
template <typename THost, typename TPositions>
struct Infix<ModifiedString<THost, ModPos<TPositions> > const>
{
typedef ModifiedString<THost, ModPos<typename Infix<TPositions>::Type> > const Type;
};
// --------------------------------------------------------------------------
// Metafunction AllowsFastRandomAccess
// --------------------------------------------------------------------------
template <typename THost, typename TPositions>
struct AllowsFastRandomAccess<ModifiedString<THost, ModPos<TPositions> > > :
And<AllowsFastRandomAccess<THost>, AllowsFastRandomAccess<TPositions> >
{};
// ============================================================================
// Functions
// ============================================================================
// --------------------------------------------------------------------------
// Function cargo()
// --------------------------------------------------------------------------
template <typename THost, typename TPositions>
inline typename Parameter_<TPositions>::Type
cargo(ModifiedString<THost, ModPos<TPositions> > & me)
{
return _toParameter<TPositions>(me._cargo);
}
template <typename THost, typename TPositions>
inline typename Parameter_<TPositions>::Type
cargo(ModifiedString<THost, ModPos<TPositions> > const & me)
{
return _toParameter<TPositions>(me._cargo);
}
// --------------------------------------------------------------------------
// Function setCargo()
// --------------------------------------------------------------------------
template <typename THost, typename TPositions>
inline void
setCargo(ModifiedString<THost, ModPos<TPositions> > & me, typename Parameter_<TPositions>::Type _cargo)
{
me._cargo = _toPointer(_cargo);
}
// ----------------------------------------------------------------------------
// Function begin()
// ----------------------------------------------------------------------------
template <typename THost, typename TPositions, typename TTagSpec>
inline typename Iterator<ModifiedString<THost, ModPos<TPositions> >, Tag<TTagSpec> const>::Type
begin(ModifiedString<THost, ModPos<TPositions> > & me, Tag<TTagSpec> const /* tag */)
{
return typename Iterator<ModifiedString<THost, ModPos<TPositions> >, Tag<TTagSpec> const>::Type(me);
}
template <typename THost, typename TPositions, typename TTagSpec>
inline typename Iterator<ModifiedString<THost, ModPos<TPositions> > const, Tag<TTagSpec> const>::Type
begin(ModifiedString<THost, ModPos<TPositions> > const & me, Tag<TTagSpec> const /* tag */)
{
return typename Iterator<ModifiedString<THost, ModPos<TPositions> > const, Tag<TTagSpec> const>::Type(me);
}
// ----------------------------------------------------------------------------
// Function end()
// ----------------------------------------------------------------------------
template <typename THost, typename TPositions, typename TTagSpec>
inline typename Iterator<ModifiedString<THost, ModPos<TPositions> >, Tag<TTagSpec> const>::Type
end(ModifiedString<THost, ModPos<TPositions> > & me, Tag<TTagSpec> const /* tag */)
{
return typename Iterator<ModifiedString<THost, ModPos<TPositions> >, Tag<TTagSpec> const>::Type(me, length(me));
}
template <typename THost, typename TPositions, typename TTagSpec>
inline typename Iterator<ModifiedString<THost, ModPos<TPositions> > const, Tag<TTagSpec> const>::Type
end(ModifiedString<THost, ModPos<TPositions> > const & me, Tag<TTagSpec> const /* tag */)
{
return typename Iterator<ModifiedString<THost, ModPos<TPositions> > const, Tag<TTagSpec> const>::Type(me, length(me));
}
// ----------------------------------------------------------------------------
// Function value()
// ----------------------------------------------------------------------------
template <typename THost, typename TPositions, typename TPos>
inline typename Reference<ModifiedString<THost, ModPos<TPositions> > >::Type
value(ModifiedString<THost, ModPos<TPositions> > & me, TPos pos)
{
return value(host(me), getValue(cargo(me), pos));
}
template <typename THost, typename TPositions, typename TPos>
inline typename Reference<ModifiedString<THost, ModPos<TPositions> > const>::Type
value(ModifiedString<THost, ModPos<TPositions> > const & me, TPos pos)
{
return value(host(me), getValue(cargo(me), pos));
}
// ----------------------------------------------------------------------------
// Function getValue()
// ----------------------------------------------------------------------------
template <typename THost, typename TPositions, typename TPos>
inline typename GetValue<ModifiedString<THost, ModPos<TPositions> > >::Type
getValue(ModifiedString<THost, ModPos<TPositions> > & me, TPos pos)
{
return getValue(host(me), getValue(cargo(me), pos));
}
template <typename THost, typename TPositions, typename TPos>
inline typename GetValue<ModifiedString<THost, ModPos<TPositions> > const>::Type
getValue(ModifiedString<THost, ModPos<TPositions> > const & me, TPos pos)
{
return getValue(host(me), getValue(cargo(me), pos));
}
// ----------------------------------------------------------------------------
// Function length()
// ----------------------------------------------------------------------------
template <typename THost, typename TPositions>
inline typename Size<ModifiedString<THost, ModPos<TPositions> > >::Type
length(ModifiedString<THost, ModPos<TPositions> > const & me)
{
return length(cargo(me));
}
// ----------------------------------------------------------------------------
// Function empty()
// ----------------------------------------------------------------------------
template <typename THost, typename TPositions>
inline bool empty(ModifiedString<THost, ModPos<TPositions> > const & me)
{
return empty(cargo(me));
}
// ----------------------------------------------------------------------------
// Function clear()
// ----------------------------------------------------------------------------
template <typename THost, typename TPositions>
inline void clear(ModifiedString<THost, ModPos<TPositions> > & me)
{
clear(cargo(me));
}
// ----------------------------------------------------------------------------
// Function resize()
// ----------------------------------------------------------------------------
// NOTE(esiragusa): a dummy implementation like ContainerView could be necessary.
// ----------------------------------------------------------------------------
// Function prefix()
// ----------------------------------------------------------------------------
// NOTE(esiragusa): not implemented.
// ----------------------------------------------------------------------------
// Function suffix()
// ----------------------------------------------------------------------------
// NOTE(esiragusa): not implemented.
// ----------------------------------------------------------------------------
// Function infix()
// ----------------------------------------------------------------------------
template <typename THost, typename TPositions, typename TPosBegin, typename TPosEnd>
inline typename Infix<ModifiedString<THost, ModPos<TPositions> > const>::Type
infix(ModifiedString<THost, ModPos<TPositions> > const & me, TPosBegin pos_begin, TPosEnd pos_end)
{
typename Infix<ModifiedString<THost, ModPos<TPositions> > const>::Type other;
setHost(other, host(me));
setCargo(other, infix(cargo(me), pos_begin, pos_end));
return other;
}
template <typename THost, typename TPositions, typename TPosBegin, typename TPosEnd>
inline typename Infix<ModifiedString<THost, ModPos<TPositions> > >::Type
infix(ModifiedString<THost, ModPos<TPositions> > & me, TPosBegin pos_begin, TPosEnd pos_end)
{
typename Infix<ModifiedString<THost, ModPos<TPositions> > >::Type other;
setHost(other, host(me));
setCargo(other, infix(cargo(me), pos_begin, pos_end));
return other;
}
// ----------------------------------------------------------------------------
// Function position()
// ----------------------------------------------------------------------------
template <typename THost, typename TPositions, typename TPos>
inline typename Position<ModifiedString<THost, ModPos<TPositions> > const>::Type
position(ModifiedString<THost, ModPos<TPositions> > const & me, TPos i)
{
return getValue(cargo(me), i);
}
// ----------------------------------------------------------------------------
// Function setPosition()
// ----------------------------------------------------------------------------
template <typename THost, typename TPositions, typename TPos>
inline void setPosition(ModifiedString<THost, ModPos<TPositions> > & me, TPos i, TPos j)
{
assignValue(cargo(me), i, j);
}
template <typename THost, typename TPositions, typename TPos>
inline void setPosition(ModifiedString<THost, ModPos<TPositions> > const & me, TPos i, TPos j)
{
assignValue(cargo(me), i, j);
}
// ----------------------------------------------------------------------------
// Functor PosLess_
// ----------------------------------------------------------------------------
template <typename THost, typename TPos = typename Position<THost>::Type, typename TPredicate = std::less<TPos> >
struct PosLess_ : public std::function<bool(TPos, TPos)>
{
THost const & _host;
TPredicate pred;
PosLess_(THost const & _host) :
_host(_host)
{}
PosLess_(THost const & _host, TPredicate const & pred) :
_host(_host),
pred(pred)
{}
bool operator()(TPos a, TPos b)
{
return pred(getValue(_host, a), getValue(_host, b));
}
};
// ----------------------------------------------------------------------------
// Function sort()
// ----------------------------------------------------------------------------
template <typename THost, typename TPositions, typename TBinaryPredicate, typename TParallelTag>
inline void sort(ModifiedString<THost, ModPos<TPositions> > & me, TBinaryPredicate p, Tag<TParallelTag> const & tag)
{
typedef typename Position<ModifiedString<THost, ModPos<TPositions> > >::Type TPos;
sort(cargo(me), PosLess_<THost, TPos, TBinaryPredicate>(host(me), p), tag);
}
template <typename THost, typename TPositions, typename TParallelTag>
inline void sort(ModifiedString<THost, ModPos<TPositions> > & me, Tag<TParallelTag> const & tag)
{
typedef typename Position<ModifiedString<THost, ModPos<TPositions> > >::Type TPos;
sort(cargo(me), PosLess_<THost, TPos>(host(me)), tag);
}
template <typename THost, typename TPositions, typename TBinaryPredicate, typename TParallelTag>
inline void sort(ModifiedString<THost, ModPos<TPositions> > const & me, TBinaryPredicate p, Tag<TParallelTag> const & tag)
{
typedef typename Position<ModifiedString<THost, ModPos<TPositions> > >::Type TPos;
sort(cargo(me), PosLess_<THost, TPos, TBinaryPredicate>(host(me), p), tag);
}
template <typename THost, typename TPositions, typename TParallelTag>
inline void sort(ModifiedString<THost, ModPos<TPositions> > const & me, Tag<TParallelTag> const & tag)
{
typedef typename Position<ModifiedString<THost, ModPos<TPositions> > >::Type TPos;
sort(cargo(me), PosLess_<THost, TPos>(host(me)), tag);
}
} // namespace seqan2
#endif // SEQAN_MODIFIER_MODIFIER_POSITION_H_
|