text:
#ifndef INCLUDE_LIBYUV_ROW_H_  // NOLINT
#define INCLUDE_LIBYUV_ROW_H_

#include "libyuv/basic_types.h"

#ifdef __cplusplus
namespace libyuv {
extern "C" {
#endif

// TODO(fbarchard): Remove kMaxStride
#define kMaxStride (2880 * 4)
#define IS_ALIGNED(p, a) (!((uintptr_t)(p) & ((a) - 1)))

#if defined(__CLR_VER) || defined(COVERAGE_ENABLED) || \
    defined(TARGET_IPHONE_SIMULATOR)
#define YUV_DISABLE_ASM
#endif
// True if compiling for SSSE3 as a requirement.
#if defined(__SSSE3__) || (defined(_M_IX86_FP) && (_M_IX86_FP >= 3))
#define LIBYUV_SSSE3_ONLY
#endif

// The following are available on all x86 platforms:
#if !defined(YUV_DISABLE_ASM) && \
    (defined(_M_IX86) || defined(__x86_64__) || defined(__i386__))
// Conversions.
#define HAS_ABGRTOARGBROW_SSSE3
#define HAS_ABGRTOUVROW_SSSE3
#define HAS_ABGRTOYROW_SSSE3
#define HAS_ARGB1555TOARGBROW_SSE2
#define HAS_ARGB4444TOARGBROW_SSE2
#define HAS_ARGBTOARGB1555ROW_SSE2
#define HAS_ARGBTOARGB4444ROW_SSE2
#define HAS_ARGBTORAWROW_SSSE3
#define HAS_ARGBTORGB24ROW_SSSE3
#define HAS_ARGBTORGB565ROW_SSE2
#define HAS_ARGBTORGBAROW_SSSE3
#define HAS_ARGBTOUVROW_SSSE3
#define HAS_ARGBTOYROW_SSSE3
#define HAS_BGRATOARGBROW_SSSE3
#define HAS_BGRATOUVROW_SSSE3
#define HAS_BGRATOYROW_SSSE3
#define HAS_COPYROW_SSE2
#define HAS_COPYROW_X86
#define HAS_I400TOARGBROW_SSE2
#define HAS_I411TOARGBROW_SSSE3
#define HAS_I422TOABGRROW_SSSE3
#define HAS_I422TOARGBROW_SSSE3
#define HAS_I422TOBGRAROW_SSSE3
#define HAS_I444TOARGBROW_SSSE3
#define HAS_MIRRORROW_SSSE3
#define HAS_MIRRORROWUV_SSSE3
#define HAS_NV12TOARGBROW_SSSE3
#define HAS_NV21TOARGBROW_SSSE3
#define HAS_RAWTOARGBROW_SSSE3
#define HAS_RGB24TOARGBROW_SSSE3
#define HAS_RGB565TOARGBROW_SSE2
#define HAS_SETROW_X86
#define HAS_SPLITUV_SSE2
#define HAS_UYVYTOUV422ROW_SSE2
#define HAS_UYVYTOUVROW_SSE2
#define HAS_UYVYTOYROW_SSE2
#define HAS_YTOARGBROW_SSE2
#define HAS_YUY2TOUV422ROW_SSE2
#define HAS_YUY2TOUVROW_SSE2
#define HAS_YUY2TOYROW_SSE2

// Effects
#define HAS_ARGBAFFINEROW_SSE2
#define HAS_ARGBATTENUATEROW_SSSE3
#define HAS_ARGBBLENDROW_SSSE3
#define HAS_ARGBCOLORMATRIXROW_SSSE3
#define HAS_ARGBGRAYROW_SSSE3
#define HAS_ARGBINTERPOLATEROW_SSSE3
#define HAS_ARGBMIRRORROW_SSSE3
#define HAS_ARGBQUANTIZEROW_SSE2
#define HAS_ARGBSEPIAROW_SSSE3
#define HAS_ARGBSHADE_SSE2
#define HAS_ARGBUNATTENUATEROW_SSE2
#define HAS_COMPUTECUMULATIVESUMROW_SSE2
#define HAS_CUMULATIVESUMTOAVERAGE_SSE2
#endif

// The following are Windows only:
#if !defined(YUV_DISABLE_ASM) && defined(_M_IX86)
#define HAS_ABGRTOARGBROW_SSSE3
#define HAS_ARGBCOLORTABLEROW_X86
#define HAS_I422TORGBAROW_SSSE3
#define HAS_RGBATOARGBROW_SSSE3
#define HAS_RGBATOUVROW_SSSE3
#define HAS_RGBATOYROW_SSSE3
#endif

// The following are disabled when SSSE3 is available:
#if !defined(YUV_DISABLE_ASM) && \
    (defined(_M_IX86) || defined(__x86_64__) || defined(__i386__)) && \
    !defined(LIBYUV_SSSE3_ONLY)
#define HAS_ARGBATTENUATE_SSE2
#define HAS_ARGBBLENDROW_SSE2
#define HAS_MIRRORROW_SSE2
#endif

// The following are available on Neon platforms
#if !defined(YUV_DISABLE_ASM) && (defined(__ARM_NEON__) || defined(LIBYUV_NEON))
#define HAS_COPYROW_NEON
#define HAS_I422TOABGRROW_NEON
#define HAS_I422TOARGBROW_NEON
#define HAS_I422TOBGRAROW_NEON
#define HAS_I422TORAWROW_NEON
#define HAS_I422TORGB24ROW_NEON
#define HAS_I422TORGBAROW_NEON
#define HAS_MIRRORROW_NEON
#define HAS_MIRRORROWUV_NEON
#define HAS_SETROW_NEON
#define HAS_SPLITUV_NEON
#define HAS_UYVYTOUV422ROW_NEON
#define HAS_UYVYTOUVROW_NEON
#define HAS_UYVYTOYROW_NEON
#define HAS_YUY2TOUV422ROW_NEON
#define HAS_YUY2TOUVROW_NEON
#define HAS_YUY2TOYROW_NEON

// TODO(fbarchard): Hook these up to calling functions.
#define HAS_ABGRTOARGBROW_NEON
#define HAS_ARGBTORAWROW_NEON
#define HAS_ARGBTORGB24ROW_NEON
#define HAS_ARGBTORGBAROW_NEON
#define HAS_BGRATOARGBROW_NEON
#define HAS_NV12TOARGBROW_NEON
#define HAS_NV21TOARGBROW_NEON
#define HAS_RAWTOARGBROW_NEON
#define HAS_RGB24TOARGBROW_NEON
#define HAS_RGBATOARGBROW_NEON
#endif

#if defined(_MSC_VER) && !defined(__CLR_VER)
#define SIMD_ALIGNED(var) __declspec(align(16)) var
typedef __declspec(align(16)) int8 vec8[16];
typedef __declspec(align(16)) uint8 uvec8[16];
typedef __declspec(align(16)) int16 vec16[8];
typedef __declspec(align(16)) uint16 uvec16[8];
typedef __declspec(align(16)) int32 vec32[4];
typedef __declspec(align(16)) uint32 uvec32[4];
#elif defined(__GNUC__)
#define SIMD_ALIGNED(var) var __attribute__((aligned(16)))
typedef int8 __attribute__((vector_size(16))) vec8;
typedef uint8 __attribute__((vector_size(16))) uvec8;
typedef int16 __attribute__((vector_size(16))) vec16;
typedef uint16 __attribute__((vector_size(16))) uvec16;
typedef int32 __attribute__((vector_size(16))) vec32;
typedef uint32 __attribute__((vector_size(16))) uvec32;
#else
#define SIMD_ALIGNED(var) var
typedef int8 vec8[16];
typedef uint8 uvec8[16];
typedef int16 vec16[8];
typedef uint16 uvec16[8];
typedef int32 vec32[4];
typedef uint32 uvec32[4];
#endif

#if defined(__APPLE__) || defined(__x86_64__) || defined(__llvm__)
#define OMITFP
#else
#define OMITFP __attribute__((optimize("omit-frame-pointer")))
#endif

void I422ToARGBRow_NEON(const uint8* y_buf,
                        const uint8* u_buf,
                        const uint8* v_buf,
                        uint8* rgb_buf,
                        int width);
void I422ToBGRARow_NEON(const uint8* y_buf,
                        const uint8* u_buf,
                        const uint8* v_buf,
                        uint8* rgb_buf,
                        int width);
void I422ToABGRRow_NEON(const uint8* y_buf,
                        const uint8* u_buf,
                        const uint8* v_buf,
                        uint8* rgb_buf,
                        int width);
void I422ToRGBARow_NEON(const uint8* y_buf,
                        const uint8* u_buf,
                        const uint8* v_buf,
                        uint8* rgb_buf,
                        int width);
void I422ToRGB24Row_NEON(const uint8* y_buf,
                         const uint8* u_buf,
                         const uint8* v_buf,
                         uint8* rgb_buf,
                         int width);
void I422ToRAWRow_NEON(const uint8* y_buf,
                       const uint8* u_buf,
                       const uint8* v_buf,
                       uint8* rgb_buf,
                       int width);
void NV12ToARGBRow_NEON(const uint8* y_buf,
                        const uint8* uv_buf,
                        uint8* rgb_buf,
                        int width);
void NV21ToARGBRow_NEON(const uint8* y_buf,
                        const uint8* uv_buf,
                        uint8* rgb_buf,
                        int width);

void ARGBToYRow_SSSE3(const uint8* src_argb, uint8* dst_y, int pix);
void BGRAToYRow_SSSE3(const uint8* src_argb, uint8* dst_y, int pix);
void ABGRToYRow_SSSE3(const uint8* src_argb, uint8* dst_y, int pix);
void RGBAToYRow_SSSE3(const uint8* src_argb, uint8* dst_y, int pix);
void ARGBToYRow_Unaligned_SSSE3(const uint8* src_argb, uint8* dst_y, int pix);
void BGRAToYRow_Unaligned_SSSE3(const uint8* src_argb, uint8* dst_y, int pix);
void ABGRToYRow_Unaligned_SSSE3(const uint8* src_argb, uint8* dst_y, int pix);
void RGBAToYRow_Unaligned_SSSE3(const uint8* src_argb, uint8* dst_y, int pix);

void ARGBToUVRow_SSSE3(const uint8* src_argb0, int src_stride_argb,
                       uint8* dst_u, uint8* dst_v, int width);
void BGRAToUVRow_SSSE3(const uint8* src_argb0, int src_stride_argb,
                       uint8* dst_u, uint8* dst_v, int width);
void ABGRToUVRow_SSSE3(const uint8* src_argb0, int src_stride_argb,
                       uint8* dst_u, uint8* dst_v, int width);
void RGBAToUVRow_SSSE3(const uint8* src_argb0, int src_stride_argb,
                       uint8* dst_u, uint8* dst_v, int width);
void ARGBToUVRow_Unaligned_SSSE3(const uint8* src_argb0, int src_stride_argb,
                                 uint8* dst_u, uint8* dst_v, int width);
void BGRAToUVRow_Unaligned_SSSE3(const uint8* src_argb0, int src_stride_argb,
                                 uint8* dst_u, uint8* dst_v, int width);
void ABGRToUVRow_Unaligned_SSSE3(const uint8* src_argb0, int src_stride_argb,
                                 uint8* dst_u, uint8* dst_v, int width);
void RGBAToUVRow_Unaligned_SSSE3(const uint8* src_argb0, int src_stride_argb,
                                 uint8* dst_u, uint8* dst_v, int width);

void MirrorRow_SSSE3(const uint8* src, uint8* dst, int width);
void MirrorRow_SSE2(const uint8* src, uint8* dst, int width);
void MirrorRow_NEON(const uint8* src, uint8* dst, int width);
void MirrorRow_C(const uint8* src, uint8* dst, int width);

void MirrorRowUV_SSSE3(const uint8* src, uint8* dst_u, uint8* dst_v, int width);
void MirrorRowUV_NEON(const uint8* src, uint8* dst_u, uint8* dst_v, int width);
void MirrorRowUV_C(const uint8* src, uint8* dst_u, uint8* dst_v, int width);

void ARGBMirrorRow_SSSE3(const uint8* src, uint8* dst, int width);
void ARGBMirrorRow_C(const uint8* src, uint8* dst, int width);

void SplitUV_SSE2(const uint8* src_uv, uint8* dst_u, uint8* dst_v, int pix);
void SplitUV_NEON(const uint8* src_uv, uint8* dst_u, uint8* dst_v, int pix);
void SplitUV_C(const uint8* src_uv, uint8* dst_u, uint8* dst_v, int pix);

void CopyRow_SSE2(const uint8* src, uint8* dst, int count);
void CopyRow_X86(const uint8* src, uint8* dst, int count);
void CopyRow_NEON(const uint8* src, uint8* dst, int count);
void CopyRow_C(const uint8* src, uint8* dst, int count);

void SetRow8_X86(uint8* dst, uint32 v32, int count);
void SetRows32_X86(uint8* dst, uint32 v32, int width,
                   int dst_stride, int height);
void SetRow8_NEON(uint8* dst, uint32 v32, int count);
void SetRows32_NEON(uint8* dst, uint32 v32, int width,
                    int dst_stride, int height);
void SetRow8_C(uint8* dst, uint32 v32, int count);
void SetRows32_C(uint8* dst, uint32 v32, int width, int dst_stride, int height);

void ARGBToYRow_C(const uint8* src_argb, uint8* dst_y, int pix);
void BGRAToYRow_C(const uint8* src_argb, uint8* dst_y, int pix);
void ABGRToYRow_C(const uint8* src_argb, uint8* dst_y, int pix);
void RGBAToYRow_C(const uint8* src_argb, uint8* dst_y, int pix);

void ARGBToUVRow_C(const uint8* src_argb0, int src_stride_argb,
                   uint8* dst_u, uint8* dst_v, int width);
void BGRAToUVRow_C(const uint8* src_argb0, int src_stride_argb,
                   uint8* dst_u, uint8* dst_v, int width);
void ABGRToUVRow_C(const uint8* src_argb0, int src_stride_argb,
                   uint8* dst_u, uint8* dst_v, int width);
void RGBAToUVRow_C(const uint8* src_argb0, int src_stride_argb,
                   uint8* dst_u, uint8* dst_v, int width);

void BGRAToARGBRow_SSSE3(const uint8* src_bgra, uint8* dst_argb, int pix);
void ABGRToARGBRow_SSSE3(const uint8* src_abgr, uint8* dst_argb, int pix);
void RGBAToARGBRow_SSSE3(const uint8* src_rgba, uint8* dst_argb, int pix);
void RGB24ToARGBRow_SSSE3(const uint8* src_rgb24, uint8* dst_argb, int pix);
void RAWToARGBRow_SSSE3(const uint8* src_rgb24, uint8* dst_argb, int pix);
void ARGB1555ToARGBRow_SSE2(const uint8* src_argb, uint8* dst_argb, int pix);
void RGB565ToARGBRow_SSE2(const uint8* src_argb, uint8* dst_argb, int pix);
void ARGB4444ToARGBRow_SSE2(const uint8* src_argb, uint8* dst_argb, int pix);

void BGRAToARGBRow_NEON(const uint8* src_bgra, uint8* dst_argb, int pix);
void ABGRToARGBRow_NEON(const uint8* src_abgr, uint8* dst_argb, int pix);
void RGBAToARGBRow_NEON(const uint8* src_rgba, uint8* dst_argb, int pix);
void RGB24ToARGBRow_NEON(const uint8* src_rgb24, uint8* dst_argb, int pix);
void RAWToARGBRow_NEON(const uint8* src_rgb24, uint8* dst_argb, int pix);

void BGRAToARGBRow_C(const uint8* src_bgra, uint8* dst_argb, int pix);
void ABGRToARGBRow_C(const uint8* src_abgr, uint8* dst_argb, int pix);
void RGBAToARGBRow_C(const uint8* src_rgba, uint8* dst_argb, int pix);
void RGB24ToARGBRow_C(const uint8* src_rgb24, uint8* dst_argb, int pix);
void RAWToARGBRow_C(const uint8* src_rgb24, uint8* dst_argb, int pix);
void RGB565ToARGBRow_C(const uint8* src_rgb, uint8* dst_argb, int pix);
void ARGB1555ToARGBRow_C(const uint8* src_argb, uint8* dst_argb, int pix);
void ARGB4444ToARGBRow_C(const uint8* src_argb, uint8* dst_argb, int pix);

void ARGBToRGBARow_SSSE3(const uint8* src_argb, uint8* dst_rgb, int pix);
void ARGBToRGB24Row_SSSE3(const uint8* src_argb, uint8* dst_rgb, int pix);
void ARGBToRAWRow_SSSE3(const uint8* src_argb, uint8* dst_rgb, int pix);
void ARGBToRGB565Row_SSE2(const uint8* src_argb, uint8* dst_rgb, int pix);
void ARGBToARGB1555Row_SSE2(const uint8* src_argb, uint8* dst_rgb, int pix);
void ARGBToARGB4444Row_SSE2(const uint8* src_argb, uint8* dst_rgb, int pix);

void ARGBToRGBARow_NEON(const uint8* src_argb, uint8* dst_rgb, int pix);
void ARGBToRGB24Row_NEON(const uint8* src_argb, uint8* dst_rgb, int pix);
void ARGBToRAWRow_NEON(const uint8* src_argb, uint8* dst_rgb, int pix);

void ARGBToRGBARow_C(const uint8* src_argb, uint8* dst_rgb, int pix);
void ARGBToRGB24Row_C(const uint8* src_argb, uint8* dst_rgb, int pix);
void ARGBToRAWRow_C(const uint8* src_argb, uint8* dst_rgb, int pix);
void ARGBToRGB565Row_C(const uint8* src_argb, uint8* dst_rgb, int pix);
void ARGBToARGB1555Row_C(const uint8* src_argb, uint8* dst_rgb, int pix);
void ARGBToARGB4444Row_C(const uint8* src_argb, uint8* dst_rgb, int pix);

void I400ToARGBRow_SSE2(const uint8* src_y, uint8* dst_argb, int pix);
void I400ToARGBRow_C(const uint8* src_y, uint8* dst_argb, int pix);

void I444ToARGBRow_C(const uint8* y_buf,
                     const uint8* u_buf,
                     const uint8* v_buf,
                     uint8* argb_buf,
                     int width);

void I422ToARGBRow_C(const uint8* y_buf,
                     const uint8* u_buf,
                     const uint8* v_buf,
                     uint8* argb_buf,
                     int width);

void I411ToARGBRow_C(const uint8* y_buf,
                     const uint8* u_buf,
                     const uint8* v_buf,
                     uint8* rgb_buf,
                     int width);

void NV12ToARGBRow_C(const uint8* y_buf,
                     const uint8* uv_buf,
                     uint8* argb_buf,
                     int width);

void NV21ToARGBRow_C(const uint8* y_buf,
                     const uint8* vu_buf,
                     uint8* argb_buf,
                     int width);

void I422ToBGRARow_C(const uint8* y_buf,
                     const uint8* u_buf,
                     const uint8* v_buf,
                     uint8* bgra_buf,
                     int width);

void I422ToABGRRow_C(const uint8* y_buf,
                     const uint8* u_buf,
                     const uint8* v_buf,
                     uint8* abgr_buf,
                     int width);

void I422ToRGBARow_C(const uint8* y_buf,
                     const uint8* u_buf,
                     const uint8* v_buf,
                     uint8* rgba_buf,
                     int width);
void I422ToRGB24Row_C(const uint8* y_buf,
                      const uint8* u_buf,
                      const uint8* v_buf,
                      uint8* rgb24_buf,
                      int width);
void I422ToRAWRow_C(const uint8* y_buf,
                    const uint8* u_buf,
                    const uint8* v_buf,
                    uint8* raw_buf,
                    int width);

void YToARGBRow_C(const uint8* y_buf,
                  uint8* rgb_buf,
                  int width);

void I444ToARGBRow_SSSE3(const uint8* y_buf,
                         const uint8* u_buf,
                         const uint8* v_buf,
                         uint8* argb_buf,
                         int width);

void I422ToARGBRow_SSSE3(const uint8* y_buf,
                         const uint8* u_buf,
                         const uint8* v_buf,
                         uint8* argb_buf,
                         int width);

void I411ToARGBRow_SSSE3(const uint8* y_buf,
                         const uint8* u_buf,
                         const uint8* v_buf,
                         uint8* rgb_buf,
                         int width);

void NV12ToARGBRow_SSSE3(const uint8* y_buf,
                         const uint8* uv_buf,
                         uint8* argb_buf,
                         int width);

void NV21ToARGBRow_SSSE3(const uint8* y_buf,
                         const uint8* vu_buf,
                         uint8* argb_buf,
                         int width);

void I422ToBGRARow_SSSE3(const uint8* y_buf,
                         const uint8* u_buf,
                         const uint8* v_buf,
                         uint8* bgra_buf,
                         int width);

void I422ToABGRRow_SSSE3(const uint8* y_buf,
                         const uint8* u_buf,
                         const uint8* v_buf,
                         uint8* abgr_buf,
                         int width);

void I422ToRGBARow_SSSE3(const uint8* y_buf,
                         const uint8* u_buf,
                         const uint8* v_buf,
                         uint8* rgba_buf,
                         int width);

void I444ToARGBRow_Unaligned_SSSE3(const uint8* y_buf,
                                   const uint8* u_buf,
                                   const uint8* v_buf,
                                   uint8* argb_buf,
                                   int width);

void I422ToARGBRow_Unaligned_SSSE3(const uint8* y_buf,
                                   const uint8* u_buf,
                                   const uint8* v_buf,
                                   uint8* argb_buf,
                                   int width);

void I411ToARGBRow_Unaligned_SSSE3(const uint8* y_buf,
                                   const uint8* u_buf,
                                   const uint8* v_buf,
                                   uint8* rgb_buf,
                                   int width);

void NV12ToARGBRow_Unaligned_SSSE3(const uint8* y_buf,
                                   const uint8* uv_buf,
                                   uint8* argb_buf,
                                   int width);

void NV21ToARGBRow_Unaligned_SSSE3(const uint8* y_buf,
                                   const uint8* vu_buf,
                                   uint8* argb_buf,
                                   int width);

void I422ToBGRARow_Unaligned_SSSE3(const uint8* y_buf,
                                   const uint8* u_buf,
                                   const uint8* v_buf,
                                   uint8* bgra_buf,
                                   int width);

void I422ToABGRRow_Unaligned_SSSE3(const uint8* y_buf,
                                   const uint8* u_buf,
                                   const uint8* v_buf,
                                   uint8* abgr_buf,
                                   int width);

void I422ToRGBARow_Unaligned_SSSE3(const uint8* y_buf,
                                   const uint8* u_buf,
                                   const uint8* v_buf,
                                   uint8* rgba_buf,
                                   int width);

void I444ToARGBRow_Any_SSSE3(const uint8* y_buf,
                             const uint8* u_buf,
                             const uint8* v_buf,
                             uint8* argb_buf,
                             int width);

void I422ToARGBRow_Any_SSSE3(const uint8* y_buf,
                             const uint8* u_buf,
                             const uint8* v_buf,
                             uint8* argb_buf,
                             int width);

void I411ToARGBRow_Any_SSSE3(const uint8* y_buf,
                             const uint8* u_buf,
                             const uint8* v_buf,
                             uint8* rgb_buf,
                             int width);

void NV12ToARGBRow_Any_SSSE3(const uint8* y_buf,
                             const uint8* uv_buf,
                             uint8* argb_buf,
                             int width);

void NV21ToARGBRow_Any_SSSE3(const uint8* y_buf,
                             const uint8* vu_buf,
                             uint8* argb_buf,
                             int width);

void I422ToBGRARow_Any_SSSE3(const uint8* y_buf,
                             const uint8* u_buf,
                             const uint8* v_buf,
                             uint8* bgra_buf,
                             int width);

void I422ToABGRRow_Any_SSSE3(const uint8* y_buf,
                             const uint8* u_buf,
                             const uint8* v_buf,
                             uint8* abgr_buf,
                             int width);

void I422ToRGBARow_Any_SSSE3(const uint8* y_buf,
                             const uint8* u_buf,
                             const uint8* v_buf,
                             uint8* rgba_buf,
                             int width);

void YToARGBRow_SSE2(const uint8* y_buf,
                     uint8* argb_buf,
                     int width);

// ARGB preattenuated alpha blend.
void ARGBBlendRow_SSSE3(const uint8* src_argb0, const uint8* src_argb1,
                        uint8* dst_argb, int width);
void ARGBBlendRow_SSE2(const uint8* src_argb0, const uint8* src_argb1,
                       uint8* dst_argb, int width);
void ARGBBlendRow_C(const uint8* src_argb0, const uint8* src_argb1,
                    uint8* dst_argb, int width);

void ARGBToRGB24Row_Any_SSSE3(const uint8* src_argb, uint8* dst_rgb, int pix);
void ARGBToRAWRow_Any_SSSE3(const uint8* src_argb, uint8* dst_rgb, int pix);
void ARGBToRGB565Row_Any_SSE2(const uint8* src_argb, uint8* dst_rgb, int pix);
void ARGBToARGB1555Row_Any_SSE2(const uint8* src_argb, uint8* dst_rgb, int pix);
void ARGBToARGB4444Row_Any_SSE2(const uint8* src_argb, uint8* dst_rgb, int pix);

void ARGBToRGB24Row_Any_NEON(const uint8* src_argb, uint8* dst_rgb, int pix);
void ARGBToRAWRow_Any_NEON(const uint8* src_argb, uint8* dst_rgb, int pix);

void ARGBToYRow_Any_SSSE3(const uint8* src_argb, uint8* dst_y, int pix);
void BGRAToYRow_Any_SSSE3(const uint8* src_argb, uint8* dst_y, int pix);
void ABGRToYRow_Any_SSSE3(const uint8* src_argb, uint8* dst_y, int pix);
void RGBAToYRow_Any_SSSE3(const uint8* src_argb, uint8* dst_y, int pix);
void ARGBToUVRow_Any_SSSE3(const uint8* src_argb0, int src_stride_argb,
                           uint8* dst_u, uint8* dst_v, int width);
void BGRAToUVRow_Any_SSSE3(const uint8* src_argb0, int src_stride_argb,
                           uint8* dst_u, uint8* dst_v, int width);
void ABGRToUVRow_Any_SSSE3(const uint8* src_argb0, int src_stride_argb,
                           uint8* dst_u, uint8* dst_v, int width);
void RGBAToUVRow_Any_SSSE3(const uint8* src_argb0, int src_stride_argb,
                           uint8* dst_u, uint8* dst_v, int width);
void I422ToARGBRow_Any_NEON(const uint8* y_buf,
                            const uint8* u_buf,
                            const uint8* v_buf,
                            uint8* rgb_buf,
                            int width);
void I422ToBGRARow_Any_NEON(const uint8* y_buf,
                            const uint8* u_buf,
                            const uint8* v_buf,
                            uint8* rgb_buf,
                            int width);
void I422ToABGRRow_Any_NEON(const uint8* y_buf,
                            const uint8* u_buf,
                            const uint8* v_buf,
                            uint8* rgb_buf,
                            int width);
void I422ToRGBARow_Any_NEON(const uint8* y_buf,
                            const uint8* u_buf,
                            const uint8* v_buf,
                            uint8* rgb_buf,
                            int width);
void I422ToRGB24Row_Any_NEON(const uint8* y_buf,
                             const uint8* u_buf,
                             const uint8* v_buf,
                             uint8* rgb_buf,
                             int width);
void I422ToRAWRow_Any_NEON(const uint8* y_buf,
                           const uint8* u_buf,
                           const uint8* v_buf,
                           uint8* rgb_buf,
                           int width);
void NV12ToARGBRow_Any_NEON(const uint8* y_buf,
                            const uint8* uv_buf,
                            uint8* argb_buf,
                            int width);
void NV21ToARGBRow_Any_NEON(const uint8* y_buf,
                            const uint8* uv_buf,
                            uint8* argb_buf,
                            int width);

void YUY2ToYRow_SSE2(const uint8* src_yuy2, uint8* dst_y, int pix);
void YUY2ToUVRow_SSE2(const uint8* src_yuy2, int stride_yuy2,
                      uint8* dst_u, uint8* dst_v, int pix);
void YUY2ToUV422Row_SSE2(const uint8* src_yuy2,
                         uint8* dst_u, uint8* dst_v, int pix);
void YUY2ToYRow_Unaligned_SSE2(const uint8* src_yuy2,
                               uint8* dst_y, int pix);
void YUY2ToUVRow_Unaligned_SSE2(const uint8* src_yuy2, int stride_yuy2,
                                uint8* dst_u, uint8* dst_v, int pix);
void YUY2ToUV422Row_Unaligned_SSE2(const uint8* src_yuy2,
                                   uint8* dst_u, uint8* dst_v, int pix);
void YUY2ToYRow_NEON(const uint8* src_yuy2, uint8* dst_y, int pix);
void YUY2ToUVRow_NEON(const uint8* src_yuy2, int stride_yuy2,
                      uint8* dst_u, uint8* dst_v, int pix);
void YUY2ToUV422Row_NEON(const uint8* src_yuy2,
                         uint8* dst_u, uint8* dst_v, int pix);
void YUY2ToYRow_C(const uint8* src_yuy2, uint8* dst_y, int pix);
void YUY2ToUVRow_C(const uint8* src_yuy2, int stride_yuy2,
                   uint8* dst_u, uint8* dst_v, int pix);
void YUY2ToUV422Row_C(const uint8* src_yuy2,
                      uint8* dst_u, uint8* dst_v, int pix);
void YUY2ToYRow_Any_SSE2(const uint8* src_yuy2, uint8* dst_y, int pix);
void YUY2ToUVRow_Any_SSE2(const uint8* src_yuy2, int stride_yuy2,
                          uint8* dst_u, uint8* dst_v, int pix);
void YUY2ToUV422Row_Any_SSE2(const uint8* src_yuy2,
                             uint8* dst_u, uint8* dst_v, int pix);
void YUY2ToYRow_Any_NEON(const uint8* src_yuy2, uint8* dst_y, int pix);
void YUY2ToUVRow_Any_NEON(const uint8* src_yuy2, int stride_yuy2,
                          uint8* dst_u, uint8* dst_v, int pix);
void YUY2ToUV422Row_Any_NEON(const uint8* src_yuy2,
                             uint8* dst_u, uint8* dst_v, int pix);

void UYVYToYRow_SSE2(const uint8* src_uyvy, uint8* dst_y, int pix);
void UYVYToUVRow_SSE2(const uint8* src_uyvy, int stride_uyvy,
                      uint8* dst_u, uint8* dst_v, int pix);
void UYVYToUV422Row_SSE2(const uint8* src_uyvy,
                         uint8* dst_u, uint8* dst_v, int pix);
void UYVYToYRow_Unaligned_SSE2(const uint8* src_uyvy,
                               uint8* dst_y, int pix);
void UYVYToUVRow_Unaligned_SSE2(const uint8* src_uyvy, int stride_uyvy,
                                uint8* dst_u, uint8* dst_v, int pix);
void UYVYToUV422Row_Unaligned_SSE2(const uint8* src_uyvy,
                                   uint8* dst_u, uint8* dst_v, int pix);
void UYVYToYRow_NEON(const uint8* src_uyvy, uint8* dst_y, int pix);
void UYVYToUVRow_NEON(const uint8* src_uyvy, int stride_uyvy,
                      uint8* dst_u, uint8* dst_v, int pix);
void UYVYToUV422Row_NEON(const uint8* src_uyvy,
                         uint8* dst_u, uint8* dst_v, int pix);

void UYVYToYRow_C(const uint8* src_uyvy, uint8* dst_y, int pix);
void UYVYToUVRow_C(const uint8* src_uyvy, int stride_uyvy,
                   uint8* dst_u, uint8* dst_v, int pix);
void UYVYToUV422Row_C(const uint8* src_uyvy,
                      uint8* dst_u, uint8* dst_v, int pix);
void UYVYToYRow_Any_SSE2(const uint8* src_uyvy, uint8* dst_y, int pix);
void UYVYToUVRow_Any_SSE2(const uint8* src_uyvy, int stride_uyvy,
                          uint8* dst_u, uint8* dst_v, int pix);
void UYVYToUV422Row_Any_SSE2(const uint8* src_uyvy,
                             uint8* dst_u, uint8* dst_v, int pix);
void UYVYToYRow_Any_NEON(const uint8* src_uyvy, uint8* dst_y, int pix);
void UYVYToUVRow_Any_NEON(const uint8* src_uyvy, int stride_uyvy,
                          uint8* dst_u, uint8* dst_v, int pix);
void UYVYToUV422Row_Any_NEON(const uint8* src_uyvy,
                             uint8* dst_u, uint8* dst_v, int pix);

void ARGBAttenuateRow_C(const uint8* src_argb, uint8* dst_argb, int width);
void ARGBAttenuateRow_SSE2(const uint8* src_argb, uint8* dst_argb, int width);
void ARGBAttenuateRow_SSSE3(const uint8* src_argb, uint8* dst_argb, int width);

// Inverse table for unattenuate, shared by C and SSE2.
extern uint32 fixed_invtbl8[256];
void ARGBUnattenuateRow_C(const uint8* src_argb, uint8* dst_argb, int width);
void ARGBUnattenuateRow_SSE2(const uint8* src_argb, uint8* dst_argb, int width);

void ARGBGrayRow_C(const uint8* src_argb, uint8* dst_argb, int width);
void ARGBGrayRow_SSSE3(const uint8* src_argb, uint8* dst_argb, int width);

void ARGBSepiaRow_C(uint8* dst_argb, int width);
void ARGBSepiaRow_SSSE3(uint8* dst_argb, int width);

void ARGBColorMatrixRow_C(uint8* dst_argb, const int8* matrix_argb, int width);
void ARGBColorMatrixRow_SSSE3(uint8* dst_argb, const int8* matrix_argb,
                              int width);

void ARGBColorTableRow_C(uint8* dst_argb, const uint8* table_argb, int width);
void ARGBColorTableRow_X86(uint8* dst_argb, const uint8* table_argb, int width);

void ARGBQuantizeRow_C(uint8* dst_argb, int scale, int interval_size,
                       int interval_offset, int width);
void ARGBQuantizeRow_SSE2(uint8* dst_argb, int scale, int interval_size,
                          int interval_offset, int width);

// Used for blur.
void CumulativeSumToAverage_SSE2(const int32* topleft, const int32* botleft,
                                 int width, int area, uint8* dst, int count);
void ComputeCumulativeSumRow_SSE2(const uint8* row, int32* cumsum,
                                  const int32* previous_cumsum, int width);

void CumulativeSumToAverage_C(const int32* topleft, const int32* botleft,
                              int width, int area, uint8* dst, int count);
void ComputeCumulativeSumRow_C(const uint8* row, int32* cumsum,
                               const int32* previous_cumsum, int width);

void ARGBShadeRow_C(const uint8* src_argb, uint8* dst_argb, int width,
                    uint32 value);
void ARGBShadeRow_SSE2(const uint8* src_argb, uint8* dst_argb, int width,
                       uint32 value);

LIBYUV_API
void ARGBAffineRow_C(const uint8* src_argb, int src_argb_stride,
                     uint8* dst_argb, const float* uv_dudv, int width);
LIBYUV_API
void ARGBAffineRow_SSE2(const uint8* src_argb, int src_argb_stride,
                        uint8* dst_argb, const float* uv_dudv, int width);

void ARGBInterpolateRow_C(uint8* dst_ptr, const uint8* src_ptr,
                          ptrdiff_t src_stride,
                          int dst_width, int source_y_fraction);
void ARGBInterpolateRow_SSSE3(uint8* dst_ptr, const uint8* src_ptr,
                              ptrdiff_t src_stride, int dst_width,
                              int source_y_fraction);

#ifdef __cplusplus
}  // extern "C"
}  // namespace libyuv
#endif

#endif  // INCLUDE_LIBYUV_ROW_H_  NOLINT


text:
class User
  def initialize(name, money = 0)
    @name = name
    @money = money
    @memory = {}
  end

  def give_money(amount)
    if amount < 1 || amount > @money
      puts("I can't, I don't have enough money (#{@money}$)")
      return false
    end
    puts("#{@name} give #{amount}$")
    @money -= amount
    return true
  end

  def receive_money(amount)
    if amount >= 0
      @money += amount
      puts("#{@name} receive #{amount}$")
    end
  end

  def get_name
    return @name
  end

  def add_to_memory(key, value)
    @memory[:key] = value
  end

  def get_from_memory(key)
    return @memory[:key]
  end

end

class Bank

  def initialize()
    @accounts = {}
    @account_index = 0
  end

  def import_user_accounts_data(user_accounts_data)
    user_accounts_data.each do |account|
      create_account(account[:name], account[:balance])
    end
  end

  def create_account(name, balance)
    puts("Account created with id : #{@account_index} and name : #{name} with balance : #{balance}")
    @accounts[@account_index] = Account.new(name, balance)
    @account_index+=1
  end

  def open_account (user, balance=0)
    puts("#{user.get_name} Open an account")
    balance += 100
    user.add_to_memory("accountID", @account_index)
    create_account(user.get_name, balance)
  end

  def display_account_balance(user)
    id = user.get_from_memory("accountID")
    acc = @accounts[id]
    puts("Account #{id} Owner #{user.get_name} Balance #{acc.get_balance}")
  end

  def withdraw_money(user, amount)
    id = user.get_from_memory("accountID")
    acc = @accounts[id]
    if acc.get_money(amount)
      user.receive_money(amount)
      puts("#{user.get_name} withdraw #{amount} from the bank")
    end
  end

  def fill_my_account(user, amount)
    id = user.get_from_memory("accountID")
    acc = @accounts[id]
    if user.give_money(amount)
      acc.fill_account(amount)
      puts("#{user.get_name} fill his account with #{amount}")
    end
  end

  def display_stats
    average = 0
    median = 0
    creditors = 0
    debitors = 0
    dump_array = []
    @accounts.each do |key, account|
      bal = account.get_balance
      if bal >=0
        creditors+=1
      end
      if bal < 0
        debitors +=1
      end
      average += bal
      dump_array.push(bal)
    end
    sorted = dump_array.sort
    len = sorted.length
    median = (sorted[(len - 1) / 2] + sorted[len / 2]) / 2.0
    average /= @accounts.size
    puts("=============  Bank stats  =============")
    puts("Creditors : #{creditors}")
    puts("Debitors : #{debitors}")
    puts("Median : #{median}")
    puts("Average : #{average}")

  end

end

class Account

  def initialize(name, balance)
    @id = name
    @balance = balance
    file = File.new("#{@id}.account", "w")
    file.close
  end

  def get_money(amount)
    if verify_account_balance(amount)
      puts("Account debited with #{amount}$")
      @balance -= amount
      write_in_log_file("DEL #{amount}")
      true
    end
    write_in_log_file("DEL #{amount} FAILED")
    false
  end

  def fill_account(amount)
    if amount >= 0
      puts("account credited with #{amount}$")
      @balance += amount
      write_in_log_file("ADD #{amount}")
    end
  end

  def verify_account_balance(amount_wanted)
    if amount_wanted >= 0 && amount_wanted > @balance
      return false
    end
    return true
  end

  def get_balance
    write_in_log_file("SHO #{@balance}")
    return @balance
  end

  def get_id
    return @id
  end

  private
  def write_in_log_file(str)
    file = File.open("#{@id}.account", "a")
    file.puts(str + " #{Time.now.inspect}")
    file.close
  end

end

#MAIN

donald = User.new('Donald', 10)
picsou = User.new('Picsou', 1000000000000000)
accounts = [{name: 'Riri', balance: 200}, {name: 'Fifi', balance: -300}, {name: 'Loulou', balance: 1000}]

bank = Bank.new

bank.open_account(donald)
bank.display_account_balance(donald)

bank.fill_my_account(donald, 10)
bank.display_account_balance(donald)

bank.withdraw_money(donald, 100)
bank.display_account_balance(donald)

bank.withdraw_money(donald,4000)
bank.display_account_balance(donald)

bank.open_account(picsou, 1)
bank.display_account_balance(picsou)

bank.withdraw_money(picsou, 101)
bank.display_account_balance(picsou)

bank.import_user_accounts_data(accounts)

bank.display_stats

redpajama_set_name: RedPajamaGithub


text:
<!DOCTYPE html>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="generator" content="rustdoc">
    <meta name="description" content="API documentation for the Rust `iovec` struct in crate `libc`.">
    <meta name="keywords" content="rust, rustlang, rust-lang, iovec">

    <title>libc::iovec - Rust</title>

    <link rel="stylesheet" type="text/css" href="../normalize.css">
    <link rel="stylesheet" type="text/css" href="../rustdoc.css">
    <link rel="stylesheet" type="text/css" href="../main.css">

    <link rel="shortcut icon" href="https://doc.rust-lang.org/favicon.ico">

libc

        <form class="search-form js-only">

                <input class="search-input" name="search"
                       autocomplete="off"
                       placeholder="Click or press 'S' to search, '?' for more options…"
                       type="search">

        </form>

Struct libc::<wbr>iovec

                       [−]

               [src]

#[repr(C)]

pub struct iovec {
    pub iov_base: *mut c_void,
    pub iov_len: size_t,
}

Fields

                           iov_base: *mut c_void

                           iov_len: size_t

Trait Implementations

impl Copy for iovec

[src]

impl Clone for iovec

[src]

fn clone(&self) -> iovec

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)
1.0.0

Performs copy-assignment from source. Read more

Help

Keyboard Shortcuts

?

Show this help dialog

S

Focus the search field

⇤

Move up in search results

⇥

Move down in search results

⏎

Go to active search result

+

Collapse/expand all sections

Search Tricks

                    Prefix searches with a type followed by a colon (e.g.
                    fn:) to restrict the search to a given type.

                    Accepted types are: fn, mod,
                    struct, enum,
                    trait, type, macro,
                    and const.

                    Search functions by type signature (e.g.
                    vec -> usize or * -> vec)


text:
The term macro generally refers to a function that rewrites code prior to any attempt to make sense of it. Whether Coffeescript is a macro preprocessor over Javascript or a language in its own right is a matter of taste. Macros can get arbitrarily complex. We will keep ours as simple as practical.

Our simplest type of macro is an anchor. It is surrounded with a triglyph on both sides, e.g. ` ~<$macro$>~ `, where the triglyph selected is one that will not appear in either order in the target language.

Second rule: if the triglyphs are `~<$` and `$>~`, then `$><$` must also be an invalid token in the targeted language. We will use this rule for chaining macros. Those are also the default triglyphs in code blocks, if none are provided.

We will provide a mechanism for defining macro glyphs in the ```` ```config ```` blocks, later. For now we're hard wiring them. Marmalade has one, which I won't type until the code is sanitized to allow literal quoting of the macro form. The Clojure macros are `#|(` and `)|#` with the tetraglyph form `)||(`. They are syntax errors and likely to stay so. If it turns into anything legitimate, it will be a block comment a la Common Lisp. Rich has declared his opposition.

To make life simple, we'll reuse this for Instaparse grammar files also. It's decidedly gibberish in that language also.

It's quite possible to write a legit Marmalade file that doesn't use any Markdown macros. Without macros in the code blocks, there will be no tangle. The default behavior around a code block with no macros is to include it in the weave but not the tangle. Often this is what we want, if we are quoting a short piece of code that never gets used or that has been deprecated in favor of better code.

Anchor macros have an interior syntax. The simplest takes the form ` ~<$name$>~ `. The typical use is as a point in code for macro expansion. If so, Arachne will attempt to fill the macro from a code block called `~<$source:name$>~`. `source` is a keyword, not a variable.

Another keyword form is `~<$file:/src/file.extn$>~`. Any code block containing such a macro at the top will end up in that file, after all other macros are fully expanded.

There is a short continuation form used to intersperse code and commentary. Let's say we're targeting foo-lang, and we have declared a ```` ```foo-lang ```` block that has started a file. If the next foo-lang block looks like ```` ```foo-lang~ ```` with a `~` after it, that block continues in the same file.

Each language may be considered namespaced in this regard, so if you are interweaving two or more languages, each will go into the current file. Try to keep things easy to follow.

###Macro Predicates

In addition, a macro may have a prefix, which is an ordinary symbol which must end in the character `?`. In the configuration, the prefix may be set to 'true' or 'false'. If the prefix is false, the macro doesn't exist.

This is a simple `#ifdef` kind of refinement that lets use build multiple versions from a single codebase.

I am wary of adding more complexity than this.

So here's a small grammar for parsing macros, once they have been located.

```grammar
#|(file:macro.grammar)|#

(* A Micro Grammar For Macros *)

mac-name = prefix? command ':' mac-id
         | mac-id
         ;

prefix = #'[0-9A-Za-z.!+\- ]+\?'

mac-id = #'[0-9A-Za-z.!+\-_/ ]*'
         ;

command = #'[0-9A-Za-z.!+\-_ ]+'
          ;
```

Which does pretty much what you'd expect, restricting our macros to alphanumerics, `-`,`.`,`!`, and `+` for now. `?` and `:` may be found once each, must be in that order if both are present, and furthermore `?` joins the prefix so that it is parsed as `debug?` not `debug` `?`.

##Container Macros

Anchor macros are the simple kind. We use them to assign code blocks to files and to expand code into place. The other kind we offer are container macros, which look essentially like this: `` `<$macro:name$><$ some arbitrary code $>` ``. Simplest use case is optional code where the macro body is just a prefix and the code is included if that prefix is true. This form will also be defined for the `file:` and `source:` forms, but needn't be used. It is clearer and less error prone to use these as headers for discrete code blocks. Since we're going to the trouble to define containers, it would be good if our commands do something sensible in all cases for both forms.

Early on, I considered allowing arbitrary chains of this form. That sounds like a hassle and other than maybe disguishing try/catch/finally type forms I can't come up with a use case. Strikes me as a distraction at present.

The current macro parser is anchor-only and Clojure specific. It looks like this:

```grammar
#|(file:clj-macro.grammar)|#
(* A Mini Grammar for Literate Clojure Macros in Marmalade *)

code-body = (code-line | blank-line)+ ;

<code-line> = (#'[^\n#|(]+' | macro | punc) (!blank-line '\n')* ;

macro = <mac-start> mac-name <mac-end> ;

<mac-start> = '#|(' ;

<mac-name> = !mac-end #'[^)]+' ;

<mac-end> = ')|#' ;

<punc> = !mac-start #'[#|(]+' ;

<blank-line> = '\n' sp #'[\n]+' ;

<sp> = #'[ \t]*' ;

<ws> = #'[\s]+';

```

We need to dynamically generate variations on this by overloading the definitions of `mac-start`, `mac-end` and `punc` off the config block, at some point relatively soon. I'll put off adding continuation macros untl that point, or until I decide I want to actually use one.


text:
package com.scv.slackgo.services;

import android.app.IntentService;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder;
import android.text.TextUtils;
import android.util.Log;

import com.google.android.gms.location.Geofence;
import com.google.android.gms.location.GeofenceStatusCodes;
import com.google.android.gms.location.GeofencingEvent;
import com.scv.slackgo.R;
import com.scv.slackgo.activities.LocationsListActivity;
import com.scv.slackgo.helpers.GeofenceUtils;
import com.scv.slackgo.models.Channel;
import com.scv.slackgo.models.LocationsStore;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Observable;
import java.util.Observer;
import java.util.Set;

/**
 * Listens for geofence transition changes.
 */
public class GeofenceTransitionsIntentService extends IntentService implements Observer {

    protected static final String TAG = "GeofenceTransitionsIS";
    private Map<String, List<Channel>> channelsForLocationMap;
    private List<Channel> channelsList;
    private LocationsStore locationsStore;

    public GeofenceTransitionsIntentService() {
        super(TAG);
    }

    @Override
    public void onCreate() {
        super.onCreate();
        locationsStore = LocationsStore.getInstance();
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        GeofencingEvent event = GeofencingEvent.fromIntent(intent);
        if (event.hasError()) {
            Log.e(TAG, "GeofencingEvent Error: " + event.getErrorCode());
            String description = getGeofenceTransitionDetails(event);
            sendNotification(getString(R.string.generic_notification_title), description);
            return;
        }
        int transitionType = event.getGeofenceTransition();
        channelsForLocationMap = GeofenceUtils.getChannelsForGeofences(locationsStore, event.getTriggeringGeofences());
        if (channelsList == null) {
            channelsList = locationsStore.getChannelsList();
        }

        Set<String> channelNames = new HashSet<>();
        for (List<Channel>channelList : channelsForLocationMap.values()) {
            for (Channel channel : channelList) {
                channelNames.add(channel.getName());
            }
        }
        String channels = TextUtils.join(", ", channelNames);
        String locations = TextUtils.join(", ", channelsForLocationMap.keySet());

        String title = "";
        String message = "";
        SlackApiService slackApiService = new SlackApiService(this);
        if (transitionType == Geofence.GEOFENCE_TRANSITION_ENTER) {
            title = getString(R.string.entering_geofence_title, locations);
            message = getString(R.string.entering_geofence_message, channels);
            joinChannelsFromGeofences(event.getTriggeringGeofences(), slackApiService);
        } else if (transitionType == Geofence.GEOFENCE_TRANSITION_EXIT) {
            title = getString(R.string.going_out_geofence_title, locations);
            message = getString(R.string.going_out_geofence_message, channels);
            leaveChannelsFromGeofences(event.getTriggeringGeofences(), slackApiService);
        }
        sendNotification(title, message);
    }

    @Override
    public void update(Observable observable, Object data) {
        if (data != null) {
            channelsList = (ArrayList<Channel>) data;
        }
    }

    private static String getGeofenceTransitionDetails(GeofencingEvent event) {
        String transitionString =
                GeofenceStatusCodes.getStatusCodeString(event.getGeofenceTransition());
        List triggeringIDs = new ArrayList();
        for (Geofence geofence : event.getTriggeringGeofences()) {
            triggeringIDs.add(geofence.getRequestId());
        }
        return String.format("%s: %s", transitionString, TextUtils.join(", ", triggeringIDs));
    }

    private void sendNotification(String title, String message) {
        // Create an explicit content Intent that starts MainActivity.
        Intent notificationIntent = new Intent(getApplicationContext(), LocationsListActivity.class);

        // Get a PendingIntent containing the entire back stack.
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
        stackBuilder.addParentStack(LocationsListActivity.class).addNextIntent(notificationIntent);
        PendingIntent notificationPendingIntent =
                stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

        // Get a notification builder that's compatible with platform versions >= 4
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

        // Define the notification settings.
        builder.setColor(Color.RED)
                .setSmallIcon(R.drawable.common_ic_googleplayservices)
                .setContentTitle(title)
                .setContentText(message)
                .setContentIntent(notificationPendingIntent)
                .setAutoCancel(true);

        // Fire and notify the built Notification.
        NotificationManager notificationManager =
                (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(0, builder.build());
    }

    //Leave channels from geofence in transition
    private void leaveChannelsFromGeofences(List<Geofence> geofences, SlackApiService slackApiService) {
        for (Geofence geofence : geofences) {
            List<Channel> channels = channelsForLocationMap.get(geofence.getRequestId());
            for (Channel channel : channels) {
                slackApiService.leaveChannel(channel.getId());
            }
        }
    }

    //Join channels from geofences in transition
    private void joinChannelsFromGeofences(List<Geofence> geofences, SlackApiService slackApiService) {
        for (Geofence geofence : geofences) {
            List<Channel> channels = channelsForLocationMap.get(geofence.getRequestId());
            for (Channel channel : channels) {
                slackApiService.joinChannel(channel.getName());
            }
        }
    }
}


text:
var async = require('async');
var colors = require('colors');
var pg = require('pg');
var types = require('pg').types;
types.setTypeParser(1700, 'text', parseFloat);
var _ = require('underscore');
var jwt = require('jsonwebtoken');
var pool = require('../../server.js').pool;

var fs = require("fs");
var dir_1 = "/../../sql/queries/users/";
var dir_2 = "/../../sql/queries/documents/";
var query_get_user = fs.readFileSync(__dirname + dir_1 + 'get.sql', 'utf8').toString();
var query_search_documents_by_user = fs.readFileSync(__dirname + dir_2 + 'search_by_user.sql', 'utf8').toString();

// SEARCH BY USER
exports.request = function(req, res) {

    async.waterfall([
        function(callback){
            // Connect to database
            pool.connect(function(err, client, done) {
                if(err) {
                    callback(err, 500);
                } else {
                    callback(null, client, done);
                }
            });
        },
        function(client, done, callback) {
            // Authorization
            if(req.headers.authorization) {
                var token = req.headers.authorization.substring(7);

                // Verify token
                jwt.verify(token, process.env.JWTSECRET, function(err, decoded) {
                    if(err){
                        callback(new Error("Authorization failed"), 401);
                    } else {
                        if(decoded.member){
                            callback(null, client, done);
                        } else {
                            callback(new Error("Authorization failed"), 401);
                        }
                    }
                });
            } else {
                callback(new Error("Authorization failed"), 401);
            }
        },
        function(client, done, callback) {
            // Database query
            client.query(query_get_user, [
                req.params.user_id
            ], function(err, result) {
                done();
                if (err) {
                    callback(err, 500);
                } else {
                    // Check if User exists
                    if (result.rows.length === 0) {
                        callback(new Error("User not found"), 404);
                    } else {
                        callback(null, client, done);
                    }
                }
            });
        },
        function(client, done, callback) {
            // Preparing parameters
            var params = [];

            // Pagination parameters
            params.push(Number(req.query.offset) || null );
            params.push(Number(req.query.limit) || null );

            // Sorting
            params.push(req.query.orderby || 'created.desc');

            // Filter by user
            params.push(req.params.user_id);

            callback(null, client, done, params);
        },
        function(client, done, params, callback) {
            // Database query
            client.query(query_search_documents_by_user, params, function(err, result) {
                done();
                if (err) {
                    callback(err, 500);
                } else {
                    callback(null, 200, result.rows);
                }
            });
        }
    ], function(err, code, result) {
        if(err){
            console.error(colors.red(err));
            res.status(code).send(err.message);
        } else {
            res.status(code).send(result);
        }
    });
};


text:
package com.dianaui.universal.core.client.ui.base;

import com.google.gwt.dom.client.Element;
import com.google.gwt.text.shared.testing.PassthroughParser;
import com.google.gwt.text.shared.testing.PassthroughRenderer;

public class TextBoxBase extends ValueBoxBase<String> {

    protected TextBoxBase(final Element elem) {
        super(elem, PassthroughRenderer.instance(), PassthroughParser.instance());
    }

    @Override
    public String getValue() {
        final String raw = super.getValue();
        return raw == null ? "" : raw;
    }

}


text:
`basic_dsp_vector` offers several feature flags which determine how the calculation is performed. All feature flags are still experimental and under investigation, so it's highly recommended to read their description below before activating it.

The next table marks the allowed combinations for feature flags with an `X`.

|             | use_sse2 | use_avx2 | use_gpu | no_std |
|:----------:|:-------:|:-------:|:------:|:------:|
| use_sse2    |    X    |    X     |    X   |    X   |
| use_avx2    |    X    |    X     |    X   |    X   |
| use_gpu     |    X    |    X     |    X   |        |
| no_std      |    X    |    X     |        |    X   |

# SIMD support: `use_sse2` and `use_avx2`
Activate with: `--features use_sse2` or `--features use_avx2`. Requires Rust Nightly.

This enables explicit [SSE2](https://en.wikipedia.org/wiki/Streaming_SIMD_Extensions) and [AVX2](https://en.wikipedia.org/wiki/Advanced_Vector_Extensions) support. `SSE2` and `AVX2` are vector instructions which are supported by some CPUs (e.g. Intel and AMD) which speed up the calculations. Without any of those feature flags the lib relies on `rustc` to vectorize the code, and typically `rustc` does a very good job on that as long as it's called with the correct arguments (`-C target-cpu=native -C target-feature=+sse2,+sse3,+avx2,+avx`). There are however some cases where explicit vectorization is useful. The feature flags require the `stdsimd` crate.

# GPU support: `use_gpu`
Activate with: `--features use_gpu`.

`use_gpu` relies on `opencl` and `clFFT` to implement some operations (right now `fft` and `convolve_signal`) on the GPU. GPUs have the advantage that they allow highly parallel processing which is beneficial for many DSP operations. However GPUs also have the disadvantage that they have a high latency, which means that it takes time to move data to the GPU and back to the host CPU. For a library like `basic_dsp_vector` with many low level DSP operations, the high latency is a major drawback. Therefore the GPU is only used if the vector length exceeds a predefined threshold.

To run `basic_dsp_vector` with `use_gpu` at least one `opencl` driver must be installed (e.g. one of Intel, NVidia or AMD) and the `clFFT` library must be in the library path. Users should keep in mind that many consumer GPUs are optimized for `f32` operations and will be rather slow on `f64` data.

# Embedded support: `no_std`
Activate with: `--no-default-features`.

`--no-default-features` will disable the `std` feature flag. `basic_dsp_vector` will then compile using only [Rust core](https://doc.rust-lang.org/core/) and without any threading. This allows the lib to be used in more restrictive environments, e.g. embedded devices.

Keep in mind that `rustfft` still depends on `std`.


text:
WHENEVER SQLERROR EXIT SQL.SQLCODE

SET DEFINE ON

ALTER SESSION SET CURRENT_SCHEMA=&_vUsername
/

SET DEFINE OFF

CREATE OR REPLACE PACKAGE TWOFACTOR_INTERNAL AS

  -- Code Gen
  TYPE CODEROW IS RECORD(
    CODE VARCHAR2(6 CHAR)); --Only to give column a name
  TYPE CODES IS TABLE OF CODEROW;
  FUNCTION CODEGEN(PSECRET IN VARCHAR2, PGAP IN NUMBER) RETURN CODES
    PIPELINED;
  -- Support Functions
  FUNCTION URLGEN(PUSER IN VARCHAR2, PPASS IN VARCHAR2 DEFAULT NULL) RETURN VARCHAR2;
  FUNCTION CODECHECK(PUSER IN VARCHAR2, PCODE IN VARCHAR2, PPASS IN VARCHAR2 DEFAULT NULL) RETURN BOOLEAN;
  -- Sets
  PROCEDURE SETSTATUS(PUSER IN VARCHAR2, PSTATUS IN VARCHAR2);
  PROCEDURE SETVALIDATED(PUSER IN VARCHAR2);
  PROCEDURE SETAUTHENTICATED;
  -- Manipulate
  PROCEDURE ADDUSER(PUSER IN VARCHAR2, PGAP IN NUMBER DEFAULT NULL, PPASS IN VARCHAR2 DEFAULT NULL);
  PROCEDURE REMUSER(PUSER IN VARCHAR2);
  PROCEDURE CLEANMEMORY(PUSER IN VARCHAR2);
  FUNCTION ADDMEMORY(PUSER IN VARCHAR2, PINT IN INTERVAL DAY TO SECOND DEFAULT INTERVAL '7' DAY) RETURN BOOLEAN;
  -- Checks
  FUNCTION ISUSERSETUP(PUSER IN VARCHAR2) RETURN BOOLEAN;
  FUNCTION ISUSERENABLED(PUSER IN VARCHAR2) RETURN BOOLEAN;
  FUNCTION ISUSERVALIDATED(PUSER IN VARCHAR2) RETURN BOOLEAN;
  -- Login Refresh
  PROCEDURE CHECKANDAUTHUSER;
END TWOFACTOR_INTERNAL;
/

CREATE OR REPLACE PACKAGE BODY TWOFACTOR_INTERNAL AS
  /************************************************************************

   OraTOtP - Oracle Time-based One-time Password
   Copyright 2016  Rodrigo Jorge <http://www.dbarj.com.br/>

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

  ************************************************************************/
  CBASE32             CONSTANT VARCHAR2(32 CHAR) := 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
  DEFAULT_SECRET_PASS CONSTANT VARCHAR2(30 CHAR) := 'DBA-RJ'; -- If changed, any generated Key w/o password may stop working.

  FUNCTION ENCKEY(PDEC IN VARCHAR2, PPASS IN VARCHAR2) RETURN RAW IS
    L_SEC_RAW       RAW(16) := UTL_RAW.CAST_TO_RAW(PDEC); -- Key size = 16 characters = 16 bytes
    L_PASS_RAW      RAW(30) := UTL_RAW.CAST_TO_RAW(PPASS); -- Pass size = Max 30 characters = 30 bytes
    L_HASH_KEY      RAW(20); -- SHA1 = 160 bits = 20 bytes
    L_ENCRYPTED_RAW RAW(24); -- FACKEYS.KEY%TYPE does not work for INVISIBLE cols
  BEGIN
    -- Target is not to protect, just make it not obvious
    L_HASH_KEY      := DBMS_CRYPTO.HASH(L_PASS_RAW, DBMS_CRYPTO.HASH_SH1);
    L_ENCRYPTED_RAW := DBMS_CRYPTO.ENCRYPT(L_SEC_RAW, DBMS_CRYPTO.DES_CBC_PKCS5, L_HASH_KEY);
    RETURN L_ENCRYPTED_RAW;
  END ENCKEY;

  FUNCTION DECKEY(PENC IN RAW, PPASS IN VARCHAR2) RETURN VARCHAR2 IS
    L_PASS_RAW        RAW(30) := UTL_RAW.CAST_TO_RAW(PPASS); -- Pass size = Max 30 characters = 30 bytes
    L_HASH_KEY        RAW(20); -- SHA1 = 160 bits = 20 bytes
    L_UNENCRYPTED_RAW RAW(16); -- Key size = 16 characters = 16 bytes
  BEGIN
    -- Target is not to protect, just make it not obvious
    L_HASH_KEY        := DBMS_CRYPTO.HASH(L_PASS_RAW, DBMS_CRYPTO.HASH_SH1);
    L_UNENCRYPTED_RAW := DBMS_CRYPTO.DECRYPT(PENC, DBMS_CRYPTO.DES_CBC_PKCS5, L_HASH_KEY);
    RETURN UTL_RAW.CAST_TO_VARCHAR2(L_UNENCRYPTED_RAW);
  END DECKEY;

  FUNCTION REPLACEINENCSTR(PSRCSTR IN VARCHAR2, POLDSUB IN VARCHAR2, PNEWSUB IN VARCHAR2) RETURN VARCHAR2 IS
    VSTRNOHEXA VARCHAR2(2000 CHAR) := REGEXP_REPLACE(PSRCSTR, '%[[:xdigit:]]{2}', '---');
    VNTH       NUMBER := 1;
    VPOS       NUMBER := 1;
    VOUTPUT    VARCHAR2(2000 CHAR) := PSRCSTR;
  BEGIN
    WHILE VPOS <> 0
    LOOP
      VPOS := INSTR(VSTRNOHEXA, POLDSUB, 1, VNTH);
      IF VPOS <> 0
      THEN
        VOUTPUT := SUBSTR(VOUTPUT, 1, VPOS - 1 + ((LENGTH(PNEWSUB) - 1) * (VNTH - 1))) || PNEWSUB || SUBSTR(VOUTPUT, VPOS + 1 + ((LENGTH(PNEWSUB) - 1) * (VNTH - 1)));
        VNTH    := VNTH + 1;
      END IF;
    END LOOP;
    RETURN VOUTPUT;
  END REPLACEINENCSTR;

  FUNCTION CONVURLENCODE(PSTR IN VARCHAR2) RETURN VARCHAR2 IS
    VSTR VARCHAR2(2000 CHAR) := PSTR;
  BEGIN
    -- Need to come first
    VSTR := REPLACE(VSTR, ' ', '%20');
    VSTR := REPLACE(VSTR, '!', '%21');
    VSTR := REPLACE(VSTR, '"', '%22');
    VSTR := REPLACE(VSTR, '#', '%23');
    VSTR := REPLACE(VSTR, '$', '%24');
    VSTR := REPLACEINENCSTR(VSTR, '%', '%25'); -- To avoid replacing already encoded chars
    VSTR := REPLACE(VSTR, '&', '%26');
    VSTR := REPLACE(VSTR, '''', '%27');
    VSTR := REPLACE(VSTR, '(', '%28');
    VSTR := REPLACE(VSTR, ')', '%29');
    VSTR := REPLACE(VSTR, '*', '%2A');
    VSTR := REPLACE(VSTR, '+', '%2B');
    VSTR := REPLACE(VSTR, ',', '%2C');
    VSTR := REPLACE(VSTR, '-', '%2D');
    VSTR := REPLACE(VSTR, '.', '%2E');
    VSTR := REPLACE(VSTR, '/', '%2F');
    VSTR := REPLACEINENCSTR(VSTR, '0', '%30'); -- To avoid replacing already encoded chars
    VSTR := REPLACEINENCSTR(VSTR, '1', '%31');
    VSTR := REPLACEINENCSTR(VSTR, '2', '%32');
    VSTR := REPLACEINENCSTR(VSTR, '3', '%33');
    VSTR := REPLACEINENCSTR(VSTR, '4', '%34');
    VSTR := REPLACEINENCSTR(VSTR, '5', '%35');
    VSTR := REPLACEINENCSTR(VSTR, '6', '%36');
    VSTR := REPLACEINENCSTR(VSTR, '7', '%37');
    VSTR := REPLACEINENCSTR(VSTR, '8', '%38');
    VSTR := REPLACEINENCSTR(VSTR, '9', '%39');
    VSTR := REPLACE(VSTR, ':', '%3A');
    VSTR := REPLACE(VSTR, ';', '%3B');
    VSTR := REPLACE(VSTR, '<', '%3C');
    VSTR := REPLACE(VSTR, '=', '%3D');
    VSTR := REPLACE(VSTR, '>', '%3E');
    VSTR := REPLACE(VSTR, '?', '%3F');
    VSTR := REPLACE(VSTR, '@', '%40');
    VSTR := REPLACEINENCSTR(VSTR, 'A', '%41'); -- To avoid replacing already encoded chars
    VSTR := REPLACEINENCSTR(VSTR, 'B', '%42');
    VSTR := REPLACEINENCSTR(VSTR, 'C', '%43');
    VSTR := REPLACEINENCSTR(VSTR, 'D', '%44');
    VSTR := REPLACEINENCSTR(VSTR, 'E', '%45');
    VSTR := REPLACEINENCSTR(VSTR, 'F', '%46');
    VSTR := REPLACE(VSTR, 'G', '%47');
    VSTR := REPLACE(VSTR, 'H', '%48');
    VSTR := REPLACE(VSTR, 'I', '%49');
    VSTR := REPLACE(VSTR, 'J', '%4A');
    VSTR := REPLACE(VSTR, 'K', '%4B');
    VSTR := REPLACE(VSTR, 'L', '%4C');
    VSTR := REPLACE(VSTR, 'M', '%4D');
    VSTR := REPLACE(VSTR, 'N', '%4E');
    VSTR := REPLACE(VSTR, 'O', '%4F');
    VSTR := REPLACE(VSTR, 'P', '%50');
    VSTR := REPLACE(VSTR, 'Q', '%51');
    VSTR := REPLACE(VSTR, 'R', '%52');
    VSTR := REPLACE(VSTR, 'S', '%53');
    VSTR := REPLACE(VSTR, 'T', '%54');
    VSTR := REPLACE(VSTR, 'U', '%55');
    VSTR := REPLACE(VSTR, 'V', '%56');
    VSTR := REPLACE(VSTR, 'W', '%57');
    VSTR := REPLACE(VSTR, 'X', '%58');
    VSTR := REPLACE(VSTR, 'Y', '%59');
    VSTR := REPLACE(VSTR, 'Z', '%5A');
    VSTR := REPLACE(VSTR, '[', '%5B');
    VSTR := REPLACE(VSTR, '\', '%5C');
    VSTR := REPLACE(VSTR, ']', '%5D');
    VSTR := REPLACE(VSTR, '^', '%5E');
    VSTR := REPLACE(VSTR, '_', '%5F');
    VSTR := REPLACE(VSTR, '`', '%60');
    VSTR := REPLACE(VSTR, 'a', '%61');
    VSTR := REPLACE(VSTR, 'b', '%62');
    VSTR := REPLACE(VSTR, 'c', '%63');
    VSTR := REPLACE(VSTR, 'd', '%64');
    VSTR := REPLACE(VSTR, 'e', '%65');
    VSTR := REPLACE(VSTR, 'f', '%66');
    VSTR := REPLACE(VSTR, 'g', '%67');
    VSTR := REPLACE(VSTR, 'h', '%68');
    VSTR := REPLACE(VSTR, 'i', '%69');
    VSTR := REPLACE(VSTR, 'j', '%6A');
    VSTR := REPLACE(VSTR, 'k', '%6B');
    VSTR := REPLACE(VSTR, 'l', '%6C');
    VSTR := REPLACE(VSTR, 'm', '%6D');
    VSTR := REPLACE(VSTR, 'n', '%6E');
    VSTR := REPLACE(VSTR, 'o', '%6F');
    VSTR := REPLACE(VSTR, 'p', '%70');
    VSTR := REPLACE(VSTR, 'q', '%71');
    VSTR := REPLACE(VSTR, 'r', '%72');
    VSTR := REPLACE(VSTR, 's', '%73');
    VSTR := REPLACE(VSTR, 't', '%74');
    VSTR := REPLACE(VSTR, 'u', '%75');
    VSTR := REPLACE(VSTR, 'v', '%76');
    VSTR := REPLACE(VSTR, 'w', '%77');
    VSTR := REPLACE(VSTR, 'x', '%78');
    VSTR := REPLACE(VSTR, 'y', '%79');
    VSTR := REPLACE(VSTR, 'z', '%7A');
    VSTR := REPLACE(VSTR, '{', '%7B');
    VSTR := REPLACE(VSTR, '|', '%7C');
    VSTR := REPLACE(VSTR, '}', '%7D');
    VSTR := REPLACE(VSTR, '~', '%7E');
    RETURN VSTR;
  END;

  FUNCTION GETSECRET(PUSER IN VARCHAR2, PPASS IN VARCHAR2) RETURN VARCHAR2 IS
    VKEY RAW(24); -- FACKEYS.KEY%TYPE does not work for INVISIBLE cols
  BEGIN
    SELECT KEY INTO VKEY FROM FACKEYS WHERE USERNAME = PUSER;
    RETURN DECKEY(VKEY, PPASS);
  END GETSECRET;

  FUNCTION GETGAP(PUSER IN VARCHAR2) RETURN NUMBER IS
    VGAP FACKEYS.TIME_GAP%TYPE;
  BEGIN
    SELECT TIME_GAP INTO VGAP FROM FACKEYS WHERE USERNAME = PUSER;
    RETURN VGAP;
  END GETGAP;

  FUNCTION GETMEMORY(PUSER IN VARCHAR2) RETURN NUMBER IS
    VMEM FACKEYS.MAX_TRUSTED_SOURCES%TYPE;
  BEGIN
    SELECT MAX_TRUSTED_SOURCES INTO VMEM FROM FACKEYS WHERE USERNAME = PUSER;
    RETURN VMEM;
  END GETMEMORY;

  FUNCTION CANTRYNOW(PUSER IN VARCHAR2) RETURN BOOLEAN IS
    VBFORCEPROT BFORCEPROT%ROWTYPE;
  BEGIN
    BEGIN
      SELECT * INTO VBFORCEPROT FROM BFORCEPROT WHERE USERNAME = PUSER FOR UPDATE;
    EXCEPTION
      WHEN NO_DATA_FOUND THEN
        RETURN TRUE;
    END;
    IF VBFORCEPROT.FIRST_FAILED IS NULL
       AND VBFORCEPROT.TRIES IS NULL
    THEN
      RETURN TRUE;
    ELSIF SYSTIMESTAMP > VBFORCEPROT.FIRST_FAILED + NUMTODSINTERVAL(VBFORCEPROT.WAIT_DURATION, 'SECOND')
          OR VBFORCEPROT.TRIES < VBFORCEPROT.MAX_TRIES
    THEN
      RETURN TRUE;
    ELSE
      RETURN FALSE;
    END IF;
  END CANTRYNOW;

  FUNCTION SECRETGEN RETURN VARCHAR2 IS
    VSECRET VARCHAR2(16 CHAR) := '';
  BEGIN
    $IF DBMS_DB_VERSION.VER_LE_10 $THEN
    SELECT REPLACE(WM_CONCAT(SUBSTR(CBASE32, TRUNC(DBMS_RANDOM.VALUE(1, 33)), 1)), ',', '')
    $ELSIF DBMS_DB_VERSION.VER_LE_11_1 $THEN
    SELECT REPLACE(WM_CONCAT(SUBSTR(CBASE32, TRUNC(DBMS_RANDOM.VALUE(1, 33)), 1)), ',', '')
    $ELSE
    SELECT LISTAGG(SUBSTR(CBASE32, TRUNC(DBMS_RANDOM.VALUE(1, 33)), 1)) WITHIN GROUP(ORDER BY ROWNUM)
    $END
    INTO   VSECRET
    FROM   DUAL
    CONNECT BY LEVEL <= 16;

    RETURN VSECRET;
  END SECRETGEN;

  FUNCTION CODEGEN(PSECRET IN VARCHAR2, PGAP IN NUMBER) RETURN CODES
    PIPELINED IS

    VBITS        VARCHAR2(80 CHAR) := ''; --16 char * 5 bits / Bits representing secret position on CBASE32
    VHEXABITS    VARCHAR2(500) := ''; -- VBITS in HEXA representation
    VUTIME       NUMBER(38); -- Unix time / POSIX Time / Epoch time
    VUTIME30CHK  VARCHAR2(16); -- Unix time in 30 secs chunks (Hexa)
    VLUTIME30CHK VARCHAR2(16); -- Unix time in 30 secs chunks (Hexa) - Last Value used
    VUTIMERANGE  NUMBER(38); -- Unix time adjusted with Gap secs
    VMAC         RAW(100);
    VOFFSET      NUMBER;
    VP1          NUMBER;
    VP2          NUMBER := POWER(2, 31) - 1;
    VOUTKEY      CODEROW; -- Store the output

    FUNCTION NUM_TO_BIN(PNUM NUMBER) RETURN VARCHAR2 IS
      VBIN VARCHAR2(8);
      VNUM NUMBER := PNUM;
    BEGIN
      IF VNUM = 0
      THEN
        RETURN '0';
      END IF;
      WHILE VNUM > 0
      LOOP
        VBIN := MOD(VNUM, 2) || VBIN;
        VNUM := FLOOR(VNUM / 2);
      END LOOP;
      RETURN VBIN;
    END NUM_TO_BIN;

    FUNCTION BIN_TO_HEX(PNUM VARCHAR2) RETURN VARCHAR2 IS
      VHEX  VARCHAR2(20);
      VHEXC VARCHAR2(1);
    BEGIN
      IF PNUM = 0
      THEN
        RETURN '0';
      END IF;
      FOR I IN 1 .. LENGTH(PNUM) / 4
      LOOP
        SELECT LTRIM(TO_CHAR(BIN_TO_NUM(TO_NUMBER(SUBSTR(PNUM, ((I - 1) * 4) + 1, 1)), TO_NUMBER(SUBSTR(PNUM, ((I - 1) * 4) + 2, 1)), TO_NUMBER(SUBSTR(PNUM, ((I - 1) * 4) + 3, 1)), TO_NUMBER(SUBSTR(PNUM, ((I - 1) * 4) + 4, 1))), 'x')) INTO VHEXC FROM DUAL;
        VHEX := VHEX || VHEXC;
      END LOOP;
      RETURN VHEX;
    END BIN_TO_HEX;

  BEGIN

    FOR C IN 1 .. LENGTH(PSECRET)
    LOOP
      VBITS := VBITS || LPAD(NUM_TO_BIN(INSTR(CBASE32, SUBSTR(PSECRET, C, 1)) - 1), 5, '0');
    END LOOP;

    VHEXABITS := BIN_TO_HEX(VBITS);

    SELECT EXTRACT(DAY FROM(DIFF)) * 86400 + EXTRACT(HOUR FROM(DIFF)) * 3600 + EXTRACT(MINUTE FROM(DIFF)) * 60 + EXTRACT(SECOND FROM(DIFF)) N INTO VUTIME FROM (SELECT CURRENT_TIMESTAMP - TIMESTAMP '1970-01-01 00:00:00 +00:00' DIFF FROM DUAL);

    VUTIMERANGE := VUTIME - FLOOR(PGAP);

    WHILE TRUE
    LOOP
      SELECT LPAD(LTRIM(TO_CHAR(FLOOR(VUTIMERANGE / 30), 'xxxxxxxxxxxxxxxx')), 16, '0') INTO VUTIME30CHK FROM DUAL;
      IF VLUTIME30CHK = VUTIME30CHK -- If last run and code don't change
      THEN
        EXIT;
      END IF;
      VMAC         := DBMS_CRYPTO.MAC(SRC => HEXTORAW(VUTIME30CHK), TYP => DBMS_CRYPTO.HMAC_SH1, KEY => HEXTORAW(VHEXABITS));
      VOFFSET      := TO_NUMBER(SUBSTR(RAWTOHEX(VMAC), -1, 1), 'x');
      VP1          := TO_NUMBER(SUBSTR(RAWTOHEX(VMAC), VOFFSET * 2 + 1, 8), 'xxxxxxxx');
      VOUTKEY.CODE := SUBSTR(BITAND(VP1, VP2), -6, 6);
      PIPE ROW(VOUTKEY);
      VLUTIME30CHK := VUTIME30CHK;
      VUTIMERANGE  := LEAST(VUTIMERANGE + 30, VUTIME + FLOOR(PGAP));
    END LOOP;
    RETURN;
  END CODEGEN;

  FUNCTION GET_GLOBAL_NAME RETURN VARCHAR2 IS
    VGNAME GLOBAL_NAME.GLOBAL_NAME%TYPE;
  BEGIN
    SELECT GLOBAL_NAME INTO VGNAME FROM GLOBAL_NAME;
    RETURN VGNAME;
  END GET_GLOBAL_NAME;

  FUNCTION URLGEN(PUSER IN VARCHAR2, PPASS IN VARCHAR2 DEFAULT NULL) RETURN VARCHAR2 IS
    VPASS VARCHAR2(30 CHAR) := NVL(PPASS, DEFAULT_SECRET_PASS);
    VURLBASE  CONSTANT VARCHAR2(61 CHAR) := 'https://www.google.com/chart?chs=200x200&chld=M|0&cht=qr&chl=';
    VURLOPATH CONSTANT VARCHAR2(62 CHAR) := 'otpauth://totp/#USER#@#SERVER#?secret=#SECRET#&issuer=#ISSUER#';
    VURL  VARCHAR2(2000 CHAR);
    VUSER VARCHAR2(30 CHAR) := REPLACE(PUSER, '#', '+');
    $IF DBMS_DB_VERSION.VER_LE_10 $THEN
    VSERVER VARCHAR2(200 CHAR) := UPPER(SYS_CONTEXT('USERENV', 'DB_NAME'));
    $ELSIF DBMS_DB_VERSION.VER_LE_11 $THEN
    VSERVER VARCHAR2(200 CHAR) := UPPER(SYS_CONTEXT('USERENV', 'DB_NAME'));
    $ELSE
    VSERVER VARCHAR2(200 CHAR) := UPPER(SYS_CONTEXT('USERENV', 'CON_NAME'));
    $END
    VISSUER VARCHAR2(200 CHAR) := 'DB Server - ' || LOWER(GET_GLOBAL_NAME);
  BEGIN
    VURL := VURLOPATH;
    VURL := REPLACE(VURL, '#USER#', VUSER);
    VURL := REPLACE(VURL, '#SERVER#', VSERVER);
    VURL := REPLACE(VURL, '#SECRET#', GETSECRET(PUSER, VPASS));
    VURL := REPLACE(VURL, '#ISSUER#', VISSUER);
    VURL := VURLBASE || CONVURLENCODE(VURL);
    --VURL := VURLBASE || VURL;
    RETURN VURL;
  END URLGEN;

  PROCEDURE SETSTATUS(PUSER IN VARCHAR2, PSTATUS IN VARCHAR2) IS
  BEGIN
    UPDATE FACKEYS SET STATUS = PSTATUS WHERE USERNAME = PUSER;
    COMMIT;
  END SETSTATUS;

  PROCEDURE SETVALIDATED(PUSER IN VARCHAR2) IS
  BEGIN
    UPDATE FACKEYS SET VALIDATED = 'VALIDATED' WHERE USERNAME = PUSER;
    COMMIT;
  END SETVALIDATED;

  PROCEDURE SETAUTHENTICATED IS
  BEGIN
    DBMS_SESSION.SET_CONTEXT('TWOFACTOR_CTX', 'AUTHENTICATED', 'TRUE');
  END SETAUTHENTICATED;

  PROCEDURE INCLASTTRY(PUSER IN VARCHAR2, PCLEAN IN BOOLEAN DEFAULT FALSE) IS
    VBFORCEPROT BFORCEPROT%ROWTYPE;
  BEGIN
    BEGIN
      SELECT * INTO VBFORCEPROT FROM BFORCEPROT WHERE USERNAME = PUSER;
    EXCEPTION
      WHEN NO_DATA_FOUND THEN
        RETURN;
    END;
    IF PCLEAN -- If code is right, clean data
    THEN
      IF VBFORCEPROT.FIRST_FAILED IS NOT NULL
      THEN
        UPDATE BFORCEPROT
        SET    FIRST_FAILED = NULL,
               TRIES        = NULL
        WHERE  USERNAME = PUSER;
      END IF;
    ELSIF VBFORCEPROT.FIRST_FAILED IS NULL -- If code is wrong and this is the first wrong attempt
    THEN
      UPDATE BFORCEPROT
      SET    FIRST_FAILED = SYSTIMESTAMP,
             TRIES        = 1
      WHERE  USERNAME = PUSER;
    ELSIF SYSTIMESTAMP > VBFORCEPROT.FIRST_FAILED + NUMTODSINTERVAL(VBFORCEPROT.WAIT_DURATION, 'SECOND') -- If code is wrong and this is already too far from the first wrong attempt
    THEN
      UPDATE BFORCEPROT
      SET    FIRST_FAILED = SYSTIMESTAMP,
             TRIES        = 1
      WHERE  USERNAME = PUSER;
    ELSE
      -- If code is wrong and we are still inside tries window
      UPDATE BFORCEPROT SET TRIES = LEAST(TRIES + 1, MAX_TRIES) WHERE USERNAME = PUSER;
    END IF;
    COMMIT;
  END INCLASTTRY;

  FUNCTION CODECHECK(PUSER IN VARCHAR2, PCODE IN VARCHAR2, PPASS IN VARCHAR2 DEFAULT NULL) RETURN BOOLEAN IS
    VPASS   VARCHAR2(30 CHAR) := NVL(PPASS, DEFAULT_SECRET_PASS);
    VFIND   NUMBER;
    VSECRET VARCHAR2(16 CHAR);
    VGAP    FACKEYS.TIME_GAP%TYPE;
  BEGIN
    -- To avoid BForce, check if user can try
    IF NOT (CANTRYNOW(PUSER)) -- CANTRYNOW lock the user row to avoid parallel execution of this function = Parallel BForce Attack
    THEN
      ROLLBACK; -- Release Lock of "FOR UPDATE" inside CANTRYNOW
      RETURN FALSE;
    END IF;
    VGAP := GETGAP(PUSER);
    BEGIN
      VSECRET := GETSECRET(PUSER, VPASS);
      -- Wrong Password throughs exception on GETSECRET -> DECKEY
    EXCEPTION
      WHEN OTHERS THEN
        INCLASTTRY(PUSER);
        RETURN FALSE;
    END;
    SELECT COUNT(*) INTO VFIND FROM TABLE(CODEGEN(VSECRET, VGAP)) WHERE CODE = PCODE;
    IF VFIND = 0
    THEN
      INCLASTTRY(PUSER);
      RETURN FALSE;
    ELSE
      INCLASTTRY(PUSER, TRUE);
      RETURN TRUE;
    END IF;
  END CODECHECK;

  PROCEDURE ADDUSER(PUSER IN VARCHAR2, PGAP IN NUMBER DEFAULT NULL, PPASS IN VARCHAR2 DEFAULT NULL) IS
    VPASS VARCHAR2(30 CHAR) := NVL(PPASS, DEFAULT_SECRET_PASS);
    VKEY  RAW(24) := ENCKEY(SECRETGEN, VPASS); -- FACKEYS.KEY%TYPE does not work for INVISIBLE cols
  BEGIN
    IF PGAP IS NULL -- This could be avoided on 12c+ with new "DEFAULT ON NULL" clause, but not on prior versions
    THEN
      INSERT INTO FACKEYS
        (USERNAME,
         KEY)
      VALUES
        (PUSER,
         VKEY);
    ELSE
      INSERT INTO FACKEYS
        (USERNAME,
         KEY,
         TIME_GAP)
      VALUES
        (PUSER,
         VKEY,
         PGAP);
    END IF;
    INSERT INTO BFORCEPROT (USERNAME) VALUES (PUSER);
    COMMIT;
  END ADDUSER;

  PROCEDURE REMUSER(PUSER IN VARCHAR2) IS
  BEGIN
    DELETE FROM FACKEYS WHERE USERNAME = PUSER;
    COMMIT;
  END REMUSER;

  FUNCTION HASMEMORY(PUSER IN VARCHAR2) RETURN BOOLEAN IS
    VFIND NUMBER;
  BEGIN
    SELECT COUNT(*)
    INTO   VFIND
    FROM   TRUSTEDLOCS
    WHERE  USERNAME = PUSER
    AND    SYSTIMESTAMP BETWEEN START_DATE AND END_DATE;
    IF VFIND >= GETMEMORY(PUSER)
    THEN
      RETURN FALSE;
    ELSE
      RETURN TRUE;
    END IF;
  END HASMEMORY;

  PROCEDURE REMMEMORY IS
  BEGIN
    DELETE TRUSTEDLOCS B
    WHERE  EXISTS (SELECT 1
            FROM   V$SESSION A
            WHERE  A.AUDSID = SYS_CONTEXT('USERENV', 'SESSIONID')
            AND    A.SID = SYS_CONTEXT('USERENV', 'SID')
            AND    A.USERNAME = B.USERNAME
            AND    A.OSUSER = B.OSUSER
            AND    A.MACHINE = B.MACHINE
            AND    A.TERMINAL = B.TERMINAL
            AND    A.PROGRAM = B.PROGRAM
            AND    B.IP_ADDRESS = SYS_CONTEXT('USERENV', 'IP_ADDRESS')
            AND    SYSTIMESTAMP BETWEEN B.START_DATE AND B.END_DATE);
    -- Do not COMMIT; --ADDMEMORY will commit
  END REMMEMORY;

  FUNCTION ADDMEMORY(PUSER IN VARCHAR2, PINT INTERVAL DAY TO SECOND DEFAULT INTERVAL '7' DAY) RETURN BOOLEAN IS
    VREM TRUSTEDLOCS%ROWTYPE;
    VINT INTERVAL DAY TO SECOND := NVL(PINT, INTERVAL '7' DAY);
    CURSOR C1 IS
      SELECT MAX_TRUSTED_SOURCES FROM FACKEYS WHERE USERNAME = PUSER FOR UPDATE; -- Just to get a user lock, nothing will be changed
  BEGIN
    -- Locks here are to avoid parallel memory attack
    OPEN C1; -- Get lock for user
    IF HASMEMORY(PUSER)
    THEN
      -- Module and Action removed as they are defined after login trigger from DBMS_APPLICATION_INFO.
      SELECT USERNAME,
             OSUSER,
             MACHINE,
             TERMINAL,
             PROGRAM,
             SYS_CONTEXT('USERENV', 'IP_ADDRESS') IP_ADDRESS
      INTO   VREM.USERNAME,
             VREM.OSUSER,
             VREM.MACHINE,
             VREM.TERMINAL,
             VREM.PROGRAM,
             VREM.IP_ADDRESS
      FROM   V$SESSION
      WHERE  AUDSID = SYS_CONTEXT('USERENV', 'SESSIONID')
      AND    SID = SYS_CONTEXT('USERENV', 'SID');
      VREM.START_DATE := SYSTIMESTAMP;
      VREM.END_DATE   := VREM.START_DATE + VINT;
      INSERT INTO TRUSTEDLOCS VALUES VREM;
      COMMIT; -- Release lock
      CLOSE C1;
      RETURN TRUE;
    ELSE
      -- Memory is Full
      ROLLBACK; -- Release lock
      CLOSE C1;
      RETURN FALSE;
    END IF;
  EXCEPTION
    WHEN DUP_VAL_ON_INDEX THEN
      REMMEMORY;
      RETURN ADDMEMORY(PUSER, VINT);
  END ADDMEMORY;

  PROCEDURE CLEANMEMORY(PUSER IN VARCHAR2) IS
  BEGIN
    DELETE TRUSTEDLOCS WHERE USERNAME = PUSER;
    COMMIT;
  END CLEANMEMORY;

  FUNCTION ISUSERSETUP(PUSER IN VARCHAR2) RETURN BOOLEAN IS
    VFIND NUMBER;
  BEGIN
    SELECT COUNT(*) INTO VFIND FROM FACKEYS WHERE USERNAME = PUSER;
    IF VFIND = 0
    THEN
      RETURN FALSE;
    ELSE
      RETURN TRUE;
    END IF;
  END ISUSERSETUP;

  FUNCTION ISUSERENABLED(PUSER IN VARCHAR2) RETURN BOOLEAN IS
    VFIND NUMBER;
  BEGIN
    SELECT COUNT(*)
    INTO   VFIND
    FROM   FACKEYS
    WHERE  USERNAME = PUSER
    AND    STATUS = 'ENABLED';
    IF VFIND = 0
    THEN
      RETURN FALSE;
    ELSE
      RETURN TRUE;
    END IF;
  END ISUSERENABLED;

  FUNCTION ISUSERVALIDATED(PUSER IN VARCHAR2) RETURN BOOLEAN IS
    VFIND NUMBER;
  BEGIN
    SELECT COUNT(*)
    INTO   VFIND
    FROM   FACKEYS
    WHERE  USERNAME = PUSER
    AND    VALIDATED = 'VALIDATED';
    IF VFIND = 0
    THEN
      RETURN FALSE;
    ELSE
      RETURN TRUE;
    END IF;
  END ISUSERVALIDATED;

  FUNCTION ISUSERREMEMBERED RETURN BOOLEAN IS
    VFIND NUMBER;
  BEGIN
    SELECT COUNT(*)
    INTO   VFIND
    FROM   V$SESSION A,
           TRUSTEDLOCS B
    WHERE  A.AUDSID = SYS_CONTEXT('USERENV', 'SESSIONID')
    AND    A.SID = SYS_CONTEXT('USERENV', 'SID')
    AND    A.USERNAME = B.USERNAME
    AND    A.OSUSER = B.OSUSER
    AND    A.MACHINE = B.MACHINE
    AND    NVL(A.TERMINAL, ' ') = NVL(B.TERMINAL, ' ')
    AND    A.PROGRAM = B.PROGRAM
    AND    NVL(B.IP_ADDRESS, ' ') = NVL(SYS_CONTEXT('USERENV', 'IP_ADDRESS'), ' ')
    AND    SYSTIMESTAMP BETWEEN B.START_DATE AND B.END_DATE;
    IF VFIND = 0
    THEN
      RETURN FALSE;
    ELSE
      RETURN TRUE;
    END IF;
  END ISUSERREMEMBERED;

  PROCEDURE CHECKANDAUTHUSER AS
    VUSER CONSTANT VARCHAR2(30 CHAR) := SYS_CONTEXT('USERENV', 'SESSION_USER');
  BEGIN
    IF NOT ISUSERSETUP(VUSER) -- Not Setup
    THEN
      DBMS_SESSION.SET_CONTEXT('TWOFACTOR_CTX', 'AUTHENTICATED', 'NOT SETUP');
    ELSIF NOT ISUSERVALIDATED(VUSER) -- Not Validated
    THEN
      DBMS_SESSION.SET_CONTEXT('TWOFACTOR_CTX', 'AUTHENTICATED', 'NOT VALIDATED');
    ELSIF NOT ISUSERENABLED(VUSER) -- Not Enabled
    THEN
      DBMS_SESSION.SET_CONTEXT('TWOFACTOR_CTX', 'AUTHENTICATED', 'NOT ENABLED');
    ELSIF ISUSERREMEMBERED() -- Is Remembered!
    THEN
      SETAUTHENTICATED;
    ELSE
      DBMS_SESSION.SET_CONTEXT('TWOFACTOR_CTX', 'AUTHENTICATED', 'FALSE');
    END IF;

  END CHECKANDAUTHUSER;

END TWOFACTOR_INTERNAL;
/


text:
from django.views.generic import ListView, DetailView

from erp_test.models import Row
from erp_client.views.common import (
    BaseDeleteView, BaseUpdateView, BaseCreateView)
from erp_client.forms import RowForm

class RowModelMixin(object):
    model = Row

class RowListView(RowModelMixin, ListView):
    template_name = 'erp_client/rows/list.html'

class RowDetailView(RowModelMixin, DetailView):
    template_name = 'erp_client/rows/detail.html'

class RowUpdateView(RowModelMixin, BaseUpdateView):
    form_class = RowForm

class RowCreateView(RowModelMixin, BaseCreateView):
    form_class = RowForm

class RowDeleteView(RowModelMixin, BaseDeleteView):
    pass


text:
using System;
using System.Threading;

namespace Amib.Threading.Internal
{
    public abstract class WorkItemsGroupBase : IWorkItemsGroup
    {
        #region Private Fields

        /// <summary>
        /// Contains the name of this instance of SmartThreadPool.
        /// Can be changed by the user.
        /// </summary>
        private string _name = "WorkItemsGroupBase";

        /// <summary>
        /// Inidcates if the SmartThreadPool/WorkItemsGroup is idle.
        /// Its value is true if the _isIdleWaitHandle is set.
        /// </summary>
        private bool _isIdle = true;

        #endregion

        #region IWorkItemsGroup Members

        #region Public Methods

        /// <summary>
        /// Get/Set the name of the SmartThreadPool/WorkItemsGroup instance
        /// </summary>
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        #endregion

        #region Abstract Methods

        public abstract int Concurrency { get; set; }
        public abstract int WaitingCallbacks { get; }
        public abstract object[] GetStates();
        public abstract WIGStartInfo WIGStartInfo { get; }
        public abstract void Start();
        public abstract void Cancel(bool abortExecution);
        public abstract bool WaitForIdle(int millisecondsTimeout);
        public abstract event WorkItemsGroupIdleHandler OnIdle;

        internal abstract void Enqueue(WorkItem workItem);
        internal virtual void PreQueueWorkItem() { }

        #endregion

        #region Common Base Methods

        /// <summary>
        /// Cancel all the work items.
        /// Same as Cancel(false)
        /// </summary>
        public virtual void Cancel()
        {
            Cancel(false);
        }

        /// <summary>
        /// Wait for the SmartThreadPool/WorkItemsGroup to be idle
        /// </summary>
        public void WaitForIdle()
        {
            WaitForIdle(Timeout.Infinite);
        }

        /// <summary>
        /// Wait for the SmartThreadPool/WorkItemsGroup to be idle
        /// </summary>
        public bool WaitForIdle(TimeSpan timeout)
        {
            return WaitForIdle((int)timeout.TotalMilliseconds);
        }

        /// <summary>
        /// IsIdle is true when there are no work items running or queued.
        /// </summary>
        public bool IsIdle
        {
            get { return _isIdle; }
            protected set { _isIdle = value; }
        }

        #endregion

        #region QueueWorkItem

        /// <summary>
        /// Queue a work item
        /// </summary>
        /// <param name="callback">A callback to execute</param>
        /// <returns>Returns a work item result</returns>
        public IWorkItemResult QueueWorkItem(WorkItemCallback callback)
        {
            WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback);
            Enqueue(workItem);
            return workItem.GetWorkItemResult();
        }

        /// <summary>
        /// Queue a work item
        /// </summary>
        /// <param name="callback">A callback to execute</param>
        /// <param name="workItemPriority">The priority of the work item</param>
        /// <returns>Returns a work item result</returns>
        public IWorkItemResult QueueWorkItem(WorkItemCallback callback, WorkItemPriority workItemPriority)
        {
            PreQueueWorkItem();
            WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, workItemPriority);
            Enqueue(workItem);
            return workItem.GetWorkItemResult();
        }

        /// <summary>
        /// Queue a work item
        /// </summary>
        /// <param name="workItemInfo">Work item info</param>
        /// <param name="callback">A callback to execute</param>
        /// <returns>Returns a work item result</returns>
        public IWorkItemResult QueueWorkItem(WorkItemInfo workItemInfo, WorkItemCallback callback)
        {
            PreQueueWorkItem();
            WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, workItemInfo, callback);
            Enqueue(workItem);
            return workItem.GetWorkItemResult();
        }

        /// <summary>
        /// Queue a work item
        /// </summary>
        /// <param name="callback">A callback to execute</param>
        /// <param name="state">
        /// The context object of the work item. Used for passing arguments to the work item.
        /// </param>
        /// <returns>Returns a work item result</returns>
        public IWorkItemResult QueueWorkItem(WorkItemCallback callback, object state)
        {
            WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state);
            Enqueue(workItem);
            return workItem.GetWorkItemResult();
        }

        /// <summary>
        /// Queue a work item
        /// </summary>
        /// <param name="callback">A callback to execute</param>
        /// <param name="state">
        /// The context object of the work item. Used for passing arguments to the work item.
        /// </param>
        /// <param name="workItemPriority">The work item priority</param>
        /// <returns>Returns a work item result</returns>
        public IWorkItemResult QueueWorkItem(WorkItemCallback callback, object state, WorkItemPriority workItemPriority)
        {
            PreQueueWorkItem();
            WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state, workItemPriority);
            Enqueue(workItem);
            return workItem.GetWorkItemResult();
        }

        /// <summary>
        /// Queue a work item
        /// </summary>
        /// <param name="workItemInfo">Work item information</param>
        /// <param name="callback">A callback to execute</param>
        /// <param name="state">
        /// The context object of the work item. Used for passing arguments to the work item.
        /// </param>
        /// <returns>Returns a work item result</returns>
        public IWorkItemResult QueueWorkItem(WorkItemInfo workItemInfo, WorkItemCallback callback, object state)
        {
            PreQueueWorkItem();
            WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, workItemInfo, callback, state);
            Enqueue(workItem);
            return workItem.GetWorkItemResult();
        }

        /// <summary>
        /// Queue a work item
        /// </summary>
        /// <param name="callback">A callback to execute</param>
        /// <param name="state">
        /// The context object of the work item. Used for passing arguments to the work item.
        /// </param>
        /// <param name="postExecuteWorkItemCallback">
        /// A delegate to call after the callback completion
        /// </param>
        /// <returns>Returns a work item result</returns>
        public IWorkItemResult QueueWorkItem(
            WorkItemCallback callback,
            object state,
            PostExecuteWorkItemCallback postExecuteWorkItemCallback)
        {
            PreQueueWorkItem();
            WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state, postExecuteWorkItemCallback);
            Enqueue(workItem);
            return workItem.GetWorkItemResult();
        }

        /// <summary>
        /// Queue a work item
        /// </summary>
        /// <param name="callback">A callback to execute</param>
        /// <param name="state">
        /// The context object of the work item. Used for passing arguments to the work item.
        /// </param>
        /// <param name="postExecuteWorkItemCallback">
        /// A delegate to call after the callback completion
        /// </param>
        /// <param name="workItemPriority">The work item priority</param>
        /// <returns>Returns a work item result</returns>
        public IWorkItemResult QueueWorkItem(
            WorkItemCallback callback,
            object state,
            PostExecuteWorkItemCallback postExecuteWorkItemCallback,
            WorkItemPriority workItemPriority)
        {
            PreQueueWorkItem();
            WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state, postExecuteWorkItemCallback, workItemPriority);
            Enqueue(workItem);
            return workItem.GetWorkItemResult();
        }

        /// <summary>
        /// Queue a work item
        /// </summary>
        /// <param name="callback">A callback to execute</param>
        /// <param name="state">
        /// The context object of the work item. Used for passing arguments to the work item.
        /// </param>
        /// <param name="postExecuteWorkItemCallback">
        /// A delegate to call after the callback completion
        /// </param>
        /// <param name="callToPostExecute">Indicates on which cases to call to the post execute callback</param>
        /// <returns>Returns a work item result</returns>
        public IWorkItemResult QueueWorkItem(
            WorkItemCallback callback,
            object state,
            PostExecuteWorkItemCallback postExecuteWorkItemCallback,
            CallToPostExecute callToPostExecute)
        {
            PreQueueWorkItem();
            WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state, postExecuteWorkItemCallback, callToPostExecute);
            Enqueue(workItem);
            return workItem.GetWorkItemResult();
        }

        /// <summary>
        /// Queue a work item
        /// </summary>
        /// <param name="callback">A callback to execute</param>
        /// <param name="state">
        /// The context object of the work item. Used for passing arguments to the work item.
        /// </param>
        /// <param name="postExecuteWorkItemCallback">
        /// A delegate to call after the callback completion
        /// </param>
        /// <param name="callToPostExecute">Indicates on which cases to call to the post execute callback</param>
        /// <param name="workItemPriority">The work item priority</param>
        /// <returns>Returns a work item result</returns>
        public IWorkItemResult QueueWorkItem(
            WorkItemCallback callback,
            object state,
            PostExecuteWorkItemCallback postExecuteWorkItemCallback,
            CallToPostExecute callToPostExecute,
            WorkItemPriority workItemPriority)
        {
            PreQueueWorkItem();
            WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state, postExecuteWorkItemCallback, callToPostExecute, workItemPriority);
            Enqueue(workItem);
            return workItem.GetWorkItemResult();
        }

        #endregion

        #region QueueWorkItem(Action<...>)

        public IWorkItemResult QueueWorkItem(Action action)
        {
            PreQueueWorkItem();
            WorkItem workItem = WorkItemFactory.CreateWorkItem(
                this,
                WIGStartInfo,
                delegate
                {
                    action.Invoke();
                    return null;
                });
            Enqueue(workItem);
            return workItem.GetWorkItemResult();
        }

        public IWorkItemResult QueueWorkItem<T>(Action<T> action, T arg)
        {
            PreQueueWorkItem();
            WorkItem workItem = WorkItemFactory.CreateWorkItem(
                this,
                WIGStartInfo,
                delegate
                {
                    action.Invoke(arg);
                    return null;
                },
                WIGStartInfo.FillStateWithArgs ? new object[] { arg } : null);
            Enqueue(workItem);
            return workItem.GetWorkItemResult();
        }

        public IWorkItemResult QueueWorkItem<T1, T2>(Action<T1, T2> action, T1 arg1, T2 arg2)
        {
            PreQueueWorkItem();
            WorkItem workItem = WorkItemFactory.CreateWorkItem(
                this,
                WIGStartInfo,
                delegate
                {
                    action.Invoke(arg1, arg2);
                    return null;
                },
                WIGStartInfo.FillStateWithArgs ? new object[] { arg1, arg2 } : null);
            Enqueue(workItem);
            return workItem.GetWorkItemResult();
        }

        public IWorkItemResult QueueWorkItem<T1, T2, T3>(Action<T1, T2, T3> action, T1 arg1, T2 arg2, T3 arg3)
        {
            PreQueueWorkItem();
            WorkItem workItem = WorkItemFactory.CreateWorkItem(
                this,
                WIGStartInfo,
                delegate
                {
                    action.Invoke(arg1, arg2, arg3);
                    return null;
                },
                WIGStartInfo.FillStateWithArgs ? new object[] { arg1, arg2, arg3 } : null);
            Enqueue(workItem);
            return workItem.GetWorkItemResult();
        }

        public IWorkItemResult QueueWorkItem<T1, T2, T3, T4>(
            Action<T1, T2, T3, T4> action, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
        {
            PreQueueWorkItem();
            WorkItem workItem = WorkItemFactory.CreateWorkItem(
                           this,
                           WIGStartInfo,
                           delegate
                           {
                               action.Invoke(arg1, arg2, arg3, arg4);
                               return null;
                           },
                           WIGStartInfo.FillStateWithArgs ? new object[] { arg1, arg2, arg3, arg4 } : null);
            Enqueue(workItem);
            return workItem.GetWorkItemResult();
        }

        #endregion

        #region QueueWorkItem(Func<...>)

        public IWorkItemResult<TResult> QueueWorkItem<TResult>(Func<TResult> func)
        {
            PreQueueWorkItem();
            WorkItem workItem = WorkItemFactory.CreateWorkItem(
                            this,
                            WIGStartInfo,
                            delegate
                            {
                                return func.Invoke();
                            });
            Enqueue(workItem);
            return new WorkItemResultTWrapper<TResult>(workItem.GetWorkItemResult());
        }

        public IWorkItemResult<TResult> QueueWorkItem<T, TResult>(Func<T, TResult> func, T arg)
        {
            PreQueueWorkItem();
            WorkItem workItem = WorkItemFactory.CreateWorkItem(
                this,
                WIGStartInfo,
                delegate
                {
                    return func.Invoke(arg);
                },
                WIGStartInfo.FillStateWithArgs ? new object[] { arg } : null);
            Enqueue(workItem);
            return new WorkItemResultTWrapper<TResult>(workItem.GetWorkItemResult());
        }

        public IWorkItemResult<TResult> QueueWorkItem<T1, T2, TResult>(Func<T1, T2, TResult> func, T1 arg1, T2 arg2)
        {
            PreQueueWorkItem();
            WorkItem workItem = WorkItemFactory.CreateWorkItem(
                            this,
                            WIGStartInfo,
                            delegate
                            {
                                return func.Invoke(arg1, arg2);
                            },
                           WIGStartInfo.FillStateWithArgs ? new object[] { arg1, arg2 } : null);
            Enqueue(workItem);
            return new WorkItemResultTWrapper<TResult>(workItem.GetWorkItemResult());
        }

        public IWorkItemResult<TResult> QueueWorkItem<T1, T2, T3, TResult>(
            Func<T1, T2, T3, TResult> func, T1 arg1, T2 arg2, T3 arg3)
        {
            PreQueueWorkItem();
            WorkItem workItem = WorkItemFactory.CreateWorkItem(
                            this,
                            WIGStartInfo,
                            delegate
                            {
                                return func.Invoke(arg1, arg2, arg3);
                            },
                           WIGStartInfo.FillStateWithArgs ? new object[] { arg1, arg2, arg3 } : null);
            Enqueue(workItem);
            return new WorkItemResultTWrapper<TResult>(workItem.GetWorkItemResult());
        }

        public IWorkItemResult<TResult> QueueWorkItem<T1, T2, T3, T4, TResult>(
            Func<T1, T2, T3, T4, TResult> func, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
        {
            PreQueueWorkItem();
            WorkItem workItem = WorkItemFactory.CreateWorkItem(
                            this,
                            WIGStartInfo,
                            delegate
                            {
                                return func.Invoke(arg1, arg2, arg3, arg4);
                            },
                           WIGStartInfo.FillStateWithArgs ? new object[] { arg1, arg2, arg3, arg4 } : null);
            Enqueue(workItem);
            return new WorkItemResultTWrapper<TResult>(workItem.GetWorkItemResult());
        }

        #endregion

        #endregion
    }
}