/*
 * Copyright (c) 2011-2019, Peter Abeles. All Rights Reserved.
 *
 * This file is part of BoofCV (http://boofcv.org).
 *
 * 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.
 */

package boofcv.alg.filter.convolve.noborder;

import boofcv.struct.convolve.*;
import boofcv.struct.image.*;

import javax.annotation.Generated;
//CONCURRENT_INLINE import boofcv.concurrency.BoofConcurrency;

/**
 *

 * Standard algorithms with no fancy optimization for convolving 1D and 2D kernels across an image.
 *

 *
 *

 * NOTE: This code was automatically generated using GenerateConvolveImageStandard_IL.
 *

 *
 * @author Peter Abeles
 */
@Generated({"boofcv.alg.filter.convolve.noborder.GenerateConvolveImageStandard_IL"})
@SuppressWarnings({"ForLoopReplaceableByForEach","Duplicates"})
public class ConvolveImageStandard_IL {

	public static void horizontal( Kernel1D_F32 kernel ,
								   InterleavedF32 src, InterleavedF32 dst ) {
		final float[] dataSrc = src.data;
		final float[] dataDst = dst.data;
		final float[] dataKer = kernel.data;

		final int offset = kernel.getOffset();
		final int kernelWidth = kernel.getWidth();
		final int numBands = src.getNumBands();

		final int endJ = src.width - (kernelWidth - 1);

		//CONCURRENT_BELOW BoofConcurrency.loopFor(0, src.height, i -> {
		for( int i = 0; i < src.height; i++ ) {
			int indexDst = dst.startIndex + i*dst.stride+offset*numBands;
			for (int j = 0; j < endJ; j++) {
				int indexSrcStart = src.startIndex + i*src.stride + j*numBands;
				for (int band = 0; band < numBands; band++) {
					int indexSrc = indexSrcStart + band;
					float total = 0;
					for (int k = 0; k < kernelWidth; k++, indexSrc += numBands) {
						total += (dataSrc[indexSrc] ) * dataKer[k];
					}
					dataDst[indexDst++] = total;
				}
			}
		}
		//CONCURRENT_ABOVE });
	}

	public static void vertical( Kernel1D_F32 kernel,
								 InterleavedF32 src, InterleavedF32 dst )
	{
		final float[] dataSrc = src.data;
		final float[] dataDst = dst.data;
		final float[] dataKer = kernel.data;

		final int offset = kernel.getOffset();
		final int kernelWidth = kernel.getWidth();
		final int numBands = src.getNumBands();

		final int imgWidth = dst.getWidth();
		final int imgHeight = dst.getHeight();

		final int yEnd = imgHeight-(kernelWidth-offset-1);

		//CONCURRENT_BELOW BoofConcurrency.loopFor(offset, yEnd, y -> {
		for( int y = offset; y < yEnd; y++ ) {
			int indexDst = dst.startIndex+y*dst.stride;
			int indexSrcStart = src.startIndex+(y-offset)*src.stride;

			for (int x = 0; x < imgWidth; x++) {
				for (int band = 0; band < numBands; band++) {
					int indexSrc = indexSrcStart + band;

					float total = 0;
					for (int k = 0; k < kernelWidth; k++) {
						total += (dataSrc[indexSrc] )* dataKer[k];
						indexSrc += src.stride;
					}
					dataDst[indexDst++] = total;
				}
				indexSrcStart += numBands;
			}
		}
		//CONCURRENT_ABOVE });
	}

	public static void convolve( Kernel2D_F32 kernel , InterleavedF32 src , InterleavedF32 dst )
	{
		final float[] dataKernel = kernel.data;
		final float[] dataSrc = src.data;
		final float[] dataDst = dst.data;

		final int width = src.getWidth();
		final int height = src.getHeight();
		final int numBands = src.getNumBands();

		int offsetL = kernel.offset;
		int offsetR = kernel.width-kernel.offset-1;

		//CONCURRENT_BELOW BoofConcurrency.loopFor(offsetL, height-offsetR, y -> {
		for( int y = offsetL; y < height-offsetR; y++ ) {
			int indexDst = dst.startIndex + y*dst.stride+offsetL*numBands;
			for( int x = offsetL; x < width-offsetR; x++ ) {
				int indexSrcStart = src.startIndex + (y-offsetL)*src.stride + (x-offsetL)*numBands;

				for (int band = 0; band < numBands; band++) {
					float total = 0;
					int indexKer = 0;
					for( int ki = 0; ki < kernel.width; ki++ ) {
						int indexSrc = indexSrcStart+ki*src.stride + band;
						for( int kj = 0; kj <  kernel.width; kj++ ) {
							total += (dataSrc[indexSrc] )* dataKernel[indexKer++];
							indexSrc += numBands;
						}
					}
					dataDst[indexDst++] = total;
				}
			}
		}
		//CONCURRENT_ABOVE });
	}

	public static void horizontal( Kernel1D_F64 kernel ,
								   InterleavedF64 src, InterleavedF64 dst ) {
		final double[] dataSrc = src.data;
		final double[] dataDst = dst.data;
		final double[] dataKer = kernel.data;

		final int offset = kernel.getOffset();
		final int kernelWidth = kernel.getWidth();
		final int numBands = src.getNumBands();

		final int endJ = src.width - (kernelWidth - 1);

		//CONCURRENT_BELOW BoofConcurrency.loopFor(0, src.height, i -> {
		for( int i = 0; i < src.height; i++ ) {
			int indexDst = dst.startIndex + i*dst.stride+offset*numBands;
			for (int j = 0; j < endJ; j++) {
				int indexSrcStart = src.startIndex + i*src.stride + j*numBands;
				for (int band = 0; band < numBands; band++) {
					int indexSrc = indexSrcStart + band;
					double total = 0;
					for (int k = 0; k < kernelWidth; k++, indexSrc += numBands) {
						total += (dataSrc[indexSrc] ) * dataKer[k];
					}
					dataDst[indexDst++] = total;
				}
			}
		}
		//CONCURRENT_ABOVE });
	}

	public static void vertical( Kernel1D_F64 kernel,
								 InterleavedF64 src, InterleavedF64 dst )
	{
		final double[] dataSrc = src.data;
		final double[] dataDst = dst.data;
		final double[] dataKer = kernel.data;

		final int offset = kernel.getOffset();
		final int kernelWidth = kernel.getWidth();
		final int numBands = src.getNumBands();

		final int imgWidth = dst.getWidth();
		final int imgHeight = dst.getHeight();

		final int yEnd = imgHeight-(kernelWidth-offset-1);

		//CONCURRENT_BELOW BoofConcurrency.loopFor(offset, yEnd, y -> {
		for( int y = offset; y < yEnd; y++ ) {
			int indexDst = dst.startIndex+y*dst.stride;
			int indexSrcStart = src.startIndex+(y-offset)*src.stride;

			for (int x = 0; x < imgWidth; x++) {
				for (int band = 0; band < numBands; band++) {
					int indexSrc = indexSrcStart + band;

					double total = 0;
					for (int k = 0; k < kernelWidth; k++) {
						total += (dataSrc[indexSrc] )* dataKer[k];
						indexSrc += src.stride;
					}
					dataDst[indexDst++] = total;
				}
				indexSrcStart += numBands;
			}
		}
		//CONCURRENT_ABOVE });
	}

	public static void convolve( Kernel2D_F64 kernel , InterleavedF64 src , InterleavedF64 dst )
	{
		final double[] dataKernel = kernel.data;
		final double[] dataSrc = src.data;
		final double[] dataDst = dst.data;

		final int width = src.getWidth();
		final int height = src.getHeight();
		final int numBands = src.getNumBands();

		int offsetL = kernel.offset;
		int offsetR = kernel.width-kernel.offset-1;

		//CONCURRENT_BELOW BoofConcurrency.loopFor(offsetL, height-offsetR, y -> {
		for( int y = offsetL; y < height-offsetR; y++ ) {
			int indexDst = dst.startIndex + y*dst.stride+offsetL*numBands;
			for( int x = offsetL; x < width-offsetR; x++ ) {
				int indexSrcStart = src.startIndex + (y-offsetL)*src.stride + (x-offsetL)*numBands;

				for (int band = 0; band < numBands; band++) {
					double total = 0;
					int indexKer = 0;
					for( int ki = 0; ki < kernel.width; ki++ ) {
						int indexSrc = indexSrcStart+ki*src.stride + band;
						for( int kj = 0; kj <  kernel.width; kj++ ) {
							total += (dataSrc[indexSrc] )* dataKernel[indexKer++];
							indexSrc += numBands;
						}
					}
					dataDst[indexDst++] = total;
				}
			}
		}
		//CONCURRENT_ABOVE });
	}

	public static void horizontal( Kernel1D_S32 kernel ,
								   InterleavedU8 src, InterleavedI16 dst ) {
		final byte[] dataSrc = src.data;
		final short[] dataDst = dst.data;
		final int[] dataKer = kernel.data;

		final int offset = kernel.getOffset();
		final int kernelWidth = kernel.getWidth();
		final int numBands = src.getNumBands();

		final int endJ = src.width - (kernelWidth - 1);

		//CONCURRENT_BELOW BoofConcurrency.loopFor(0, src.height, i -> {
		for( int i = 0; i < src.height; i++ ) {
			int indexDst = dst.startIndex + i*dst.stride+offset*numBands;
			for (int j = 0; j < endJ; j++) {
				int indexSrcStart = src.startIndex + i*src.stride + j*numBands;
				for (int band = 0; band < numBands; band++) {
					int indexSrc = indexSrcStart + band;
					int total = 0;
					for (int k = 0; k < kernelWidth; k++, indexSrc += numBands) {
						total += (dataSrc[indexSrc] & 0xFF) * dataKer[k];
					}
					dataDst[indexDst++] = (short)total;
				}
			}
		}
		//CONCURRENT_ABOVE });
	}

	public static void vertical( Kernel1D_S32 kernel,
								 InterleavedU8 src, InterleavedI16 dst )
	{
		final byte[] dataSrc = src.data;
		final short[] dataDst = dst.data;
		final int[] dataKer = kernel.data;

		final int offset = kernel.getOffset();
		final int kernelWidth = kernel.getWidth();
		final int numBands = src.getNumBands();

		final int imgWidth = dst.getWidth();
		final int imgHeight = dst.getHeight();

		final int yEnd = imgHeight-(kernelWidth-offset-1);

		//CONCURRENT_BELOW BoofConcurrency.loopFor(offset, yEnd, y -> {
		for( int y = offset; y < yEnd; y++ ) {
			int indexDst = dst.startIndex+y*dst.stride;
			int indexSrcStart = src.startIndex+(y-offset)*src.stride;

			for (int x = 0; x < imgWidth; x++) {
				for (int band = 0; band < numBands; band++) {
					int indexSrc = indexSrcStart + band;

					int total = 0;
					for (int k = 0; k < kernelWidth; k++) {
						total += (dataSrc[indexSrc] & 0xFF)* dataKer[k];
						indexSrc += src.stride;
					}
					dataDst[indexDst++] = (short)total;
				}
				indexSrcStart += numBands;
			}
		}
		//CONCURRENT_ABOVE });
	}

	public static void convolve( Kernel2D_S32 kernel , InterleavedU8 src , InterleavedI16 dst )
	{
		final int[] dataKernel = kernel.data;
		final byte[] dataSrc = src.data;
		final short[] dataDst = dst.data;

		final int width = src.getWidth();
		final int height = src.getHeight();
		final int numBands = src.getNumBands();

		int offsetL = kernel.offset;
		int offsetR = kernel.width-kernel.offset-1;

		//CONCURRENT_BELOW BoofConcurrency.loopFor(offsetL, height-offsetR, y -> {
		for( int y = offsetL; y < height-offsetR; y++ ) {
			int indexDst = dst.startIndex + y*dst.stride+offsetL*numBands;
			for( int x = offsetL; x < width-offsetR; x++ ) {
				int indexSrcStart = src.startIndex + (y-offsetL)*src.stride + (x-offsetL)*numBands;

				for (int band = 0; band < numBands; band++) {
					int total = 0;
					int indexKer = 0;
					for( int ki = 0; ki < kernel.width; ki++ ) {
						int indexSrc = indexSrcStart+ki*src.stride + band;
						for( int kj = 0; kj <  kernel.width; kj++ ) {
							total += (dataSrc[indexSrc] & 0xFF)* dataKernel[indexKer++];
							indexSrc += numBands;
						}
					}
					dataDst[indexDst++] = (short)total;
				}
			}
		}
		//CONCURRENT_ABOVE });
	}

	public static void horizontal( Kernel1D_S32 kernel ,
								   InterleavedU8 src, InterleavedS32 dst ) {
		final byte[] dataSrc = src.data;
		final int[] dataDst = dst.data;
		final int[] dataKer = kernel.data;

		final int offset = kernel.getOffset();
		final int kernelWidth = kernel.getWidth();
		final int numBands = src.getNumBands();

		final int endJ = src.width - (kernelWidth - 1);

		//CONCURRENT_BELOW BoofConcurrency.loopFor(0, src.height, i -> {
		for( int i = 0; i < src.height; i++ ) {
			int indexDst = dst.startIndex + i*dst.stride+offset*numBands;
			for (int j = 0; j < endJ; j++) {
				int indexSrcStart = src.startIndex + i*src.stride + j*numBands;
				for (int band = 0; band < numBands; band++) {
					int indexSrc = indexSrcStart + band;
					int total = 0;
					for (int k = 0; k < kernelWidth; k++, indexSrc += numBands) {
						total += (dataSrc[indexSrc] & 0xFF) * dataKer[k];
					}
					dataDst[indexDst++] = total;
				}
			}
		}
		//CONCURRENT_ABOVE });
	}

	public static void vertical( Kernel1D_S32 kernel,
								 InterleavedU8 src, InterleavedS32 dst )
	{
		final byte[] dataSrc = src.data;
		final int[] dataDst = dst.data;
		final int[] dataKer = kernel.data;

		final int offset = kernel.getOffset();
		final int kernelWidth = kernel.getWidth();
		final int numBands = src.getNumBands();

		final int imgWidth = dst.getWidth();
		final int imgHeight = dst.getHeight();

		final int yEnd = imgHeight-(kernelWidth-offset-1);

		//CONCURRENT_BELOW BoofConcurrency.loopFor(offset, yEnd, y -> {
		for( int y = offset; y < yEnd; y++ ) {
			int indexDst = dst.startIndex+y*dst.stride;
			int indexSrcStart = src.startIndex+(y-offset)*src.stride;

			for (int x = 0; x < imgWidth; x++) {
				for (int band = 0; band < numBands; band++) {
					int indexSrc = indexSrcStart + band;

					int total = 0;
					for (int k = 0; k < kernelWidth; k++) {
						total += (dataSrc[indexSrc] & 0xFF)* dataKer[k];
						indexSrc += src.stride;
					}
					dataDst[indexDst++] = total;
				}
				indexSrcStart += numBands;
			}
		}
		//CONCURRENT_ABOVE });
	}

	public static void convolve( Kernel2D_S32 kernel , InterleavedU8 src , InterleavedS32 dst )
	{
		final int[] dataKernel = kernel.data;
		final byte[] dataSrc = src.data;
		final int[] dataDst = dst.data;

		final int width = src.getWidth();
		final int height = src.getHeight();
		final int numBands = src.getNumBands();

		int offsetL = kernel.offset;
		int offsetR = kernel.width-kernel.offset-1;

		//CONCURRENT_BELOW BoofConcurrency.loopFor(offsetL, height-offsetR, y -> {
		for( int y = offsetL; y < height-offsetR; y++ ) {
			int indexDst = dst.startIndex + y*dst.stride+offsetL*numBands;
			for( int x = offsetL; x < width-offsetR; x++ ) {
				int indexSrcStart = src.startIndex + (y-offsetL)*src.stride + (x-offsetL)*numBands;

				for (int band = 0; band < numBands; band++) {
					int total = 0;
					int indexKer = 0;
					for( int ki = 0; ki < kernel.width; ki++ ) {
						int indexSrc = indexSrcStart+ki*src.stride + band;
						for( int kj = 0; kj <  kernel.width; kj++ ) {
							total += (dataSrc[indexSrc] & 0xFF)* dataKernel[indexKer++];
							indexSrc += numBands;
						}
					}
					dataDst[indexDst++] = total;
				}
			}
		}
		//CONCURRENT_ABOVE });
	}

	public static void vertical( Kernel1D_S32 kernel,
								 InterleavedU16 src, InterleavedI8 dst , int divisor )
	{
		final short[] dataSrc = src.data;
		final byte[] dataDst = dst.data;
		final int[] dataKer = kernel.data;

		final int offset = kernel.getOffset();
		final int kernelWidth = kernel.getWidth();
		final int numBands = src.getNumBands();
		final int halfDivisor = divisor/2;

		final int imgWidth = dst.getWidth();
		final int imgHeight = dst.getHeight();

		final int yEnd = imgHeight-(kernelWidth-offset-1);

		//CONCURRENT_BELOW BoofConcurrency.loopFor(offset, yEnd, y -> {
		for( int y = offset; y < yEnd; y++ ) {
			int indexDst = dst.startIndex+y*dst.stride;
			int indexSrcStart = src.startIndex+(y-offset)*src.stride;

			for (int x = 0; x < imgWidth; x++) {
				for (int band = 0; band < numBands; band++) {
					int indexSrc = indexSrcStart + band;

					int total = 0;
					for (int k = 0; k < kernelWidth; k++) {
						total += (dataSrc[indexSrc] & 0xFFFF)* dataKer[k];
						indexSrc += src.stride;
					}
					dataDst[indexDst++] = (byte)((total+halfDivisor)/divisor);
				}
				indexSrcStart += numBands;
			}
		}
		//CONCURRENT_ABOVE });
	}

	public static void horizontal( Kernel1D_S32 kernel ,
								   InterleavedS16 src, InterleavedI16 dst ) {
		final short[] dataSrc = src.data;
		final short[] dataDst = dst.data;
		final int[] dataKer = kernel.data;

		final int offset = kernel.getOffset();
		final int kernelWidth = kernel.getWidth();
		final int numBands = src.getNumBands();

		final int endJ = src.width - (kernelWidth - 1);

		//CONCURRENT_BELOW BoofConcurrency.loopFor(0, src.height, i -> {
		for( int i = 0; i < src.height; i++ ) {
			int indexDst = dst.startIndex + i*dst.stride+offset*numBands;
			for (int j = 0; j < endJ; j++) {
				int indexSrcStart = src.startIndex + i*src.stride + j*numBands;
				for (int band = 0; band < numBands; band++) {
					int indexSrc = indexSrcStart + band;
					int total = 0;
					for (int k = 0; k < kernelWidth; k++, indexSrc += numBands) {
						total += (dataSrc[indexSrc] ) * dataKer[k];
					}
					dataDst[indexDst++] = (short)total;
				}
			}
		}
		//CONCURRENT_ABOVE });
	}

	public static void vertical( Kernel1D_S32 kernel,
								 InterleavedS16 src, InterleavedI16 dst )
	{
		final short[] dataSrc = src.data;
		final short[] dataDst = dst.data;
		final int[] dataKer = kernel.data;

		final int offset = kernel.getOffset();
		final int kernelWidth = kernel.getWidth();
		final int numBands = src.getNumBands();

		final int imgWidth = dst.getWidth();
		final int imgHeight = dst.getHeight();

		final int yEnd = imgHeight-(kernelWidth-offset-1);

		//CONCURRENT_BELOW BoofConcurrency.loopFor(offset, yEnd, y -> {
		for( int y = offset; y < yEnd; y++ ) {
			int indexDst = dst.startIndex+y*dst.stride;
			int indexSrcStart = src.startIndex+(y-offset)*src.stride;

			for (int x = 0; x < imgWidth; x++) {
				for (int band = 0; band < numBands; band++) {
					int indexSrc = indexSrcStart + band;

					int total = 0;
					for (int k = 0; k < kernelWidth; k++) {
						total += (dataSrc[indexSrc] )* dataKer[k];
						indexSrc += src.stride;
					}
					dataDst[indexDst++] = (short)total;
				}
				indexSrcStart += numBands;
			}
		}
		//CONCURRENT_ABOVE });
	}

	public static void convolve( Kernel2D_S32 kernel , InterleavedS16 src , InterleavedI16 dst )
	{
		final int[] dataKernel = kernel.data;
		final short[] dataSrc = src.data;
		final short[] dataDst = dst.data;

		final int width = src.getWidth();
		final int height = src.getHeight();
		final int numBands = src.getNumBands();

		int offsetL = kernel.offset;
		int offsetR = kernel.width-kernel.offset-1;

		//CONCURRENT_BELOW BoofConcurrency.loopFor(offsetL, height-offsetR, y -> {
		for( int y = offsetL; y < height-offsetR; y++ ) {
			int indexDst = dst.startIndex + y*dst.stride+offsetL*numBands;
			for( int x = offsetL; x < width-offsetR; x++ ) {
				int indexSrcStart = src.startIndex + (y-offsetL)*src.stride + (x-offsetL)*numBands;

				for (int band = 0; band < numBands; band++) {
					int total = 0;
					int indexKer = 0;
					for( int ki = 0; ki < kernel.width; ki++ ) {
						int indexSrc = indexSrcStart+ki*src.stride + band;
						for( int kj = 0; kj <  kernel.width; kj++ ) {
							total += (dataSrc[indexSrc] )* dataKernel[indexKer++];
							indexSrc += numBands;
						}
					}
					dataDst[indexDst++] = (short)total;
				}
			}
		}
		//CONCURRENT_ABOVE });
	}

	public static void horizontal( Kernel1D_S32 kernel ,
								   InterleavedU8 src, InterleavedI8 dst , int divisor ) {
		final byte[] dataSrc = src.data;
		final byte[] dataDst = dst.data;
		final int[] dataKer = kernel.data;

		final int offset = kernel.getOffset();
		final int kernelWidth = kernel.getWidth();
		final int numBands = src.getNumBands();
		final int halfDivisor = divisor/2;

		final int endJ = src.width - (kernelWidth - 1);

		//CONCURRENT_BELOW BoofConcurrency.loopFor(0, src.height, i -> {
		for( int i = 0; i < src.height; i++ ) {
			int indexDst = dst.startIndex + i*dst.stride+offset*numBands;
			for (int j = 0; j < endJ; j++) {
				int indexSrcStart = src.startIndex + i*src.stride + j*numBands;
				for (int band = 0; band < numBands; band++) {
					int indexSrc = indexSrcStart + band;
					int total = 0;
					for (int k = 0; k < kernelWidth; k++, indexSrc += numBands) {
						total += (dataSrc[indexSrc] & 0xFF) * dataKer[k];
					}
					dataDst[indexDst++] = (byte)((total+halfDivisor)/divisor);
				}
			}
		}
		//CONCURRENT_ABOVE });
	}

	public static void vertical( Kernel1D_S32 kernel,
								 InterleavedU8 src, InterleavedI8 dst , int divisor )
	{
		final byte[] dataSrc = src.data;
		final byte[] dataDst = dst.data;
		final int[] dataKer = kernel.data;

		final int offset = kernel.getOffset();
		final int kernelWidth = kernel.getWidth();
		final int numBands = src.getNumBands();
		final int halfDivisor = divisor/2;

		final int imgWidth = dst.getWidth();
		final int imgHeight = dst.getHeight();

		final int yEnd = imgHeight-(kernelWidth-offset-1);

		//CONCURRENT_BELOW BoofConcurrency.loopFor(offset, yEnd, y -> {
		for( int y = offset; y < yEnd; y++ ) {
			int indexDst = dst.startIndex+y*dst.stride;
			int indexSrcStart = src.startIndex+(y-offset)*src.stride;

			for (int x = 0; x < imgWidth; x++) {
				for (int band = 0; band < numBands; band++) {
					int indexSrc = indexSrcStart + band;

					int total = 0;
					for (int k = 0; k < kernelWidth; k++) {
						total += (dataSrc[indexSrc] & 0xFF)* dataKer[k];
						indexSrc += src.stride;
					}
					dataDst[indexDst++] = (byte)((total+halfDivisor)/divisor);
				}
				indexSrcStart += numBands;
			}
		}
		//CONCURRENT_ABOVE });
	}

	public static void convolve( Kernel2D_S32 kernel , InterleavedU8 src , InterleavedI8 dst , int divisor )
	{
		final int[] dataKernel = kernel.data;
		final byte[] dataSrc = src.data;
		final byte[] dataDst = dst.data;

		final int width = src.getWidth();
		final int height = src.getHeight();
		final int numBands = src.getNumBands();
		final int halfDivisor = divisor/2;

		int offsetL = kernel.offset;
		int offsetR = kernel.width-kernel.offset-1;

		//CONCURRENT_BELOW BoofConcurrency.loopFor(offsetL, height-offsetR, y -> {
		for( int y = offsetL; y < height-offsetR; y++ ) {
			int indexDst = dst.startIndex + y*dst.stride+offsetL*numBands;
			for( int x = offsetL; x < width-offsetR; x++ ) {
				int indexSrcStart = src.startIndex + (y-offsetL)*src.stride + (x-offsetL)*numBands;

				for (int band = 0; band < numBands; band++) {
					int total = 0;
					int indexKer = 0;
					for( int ki = 0; ki < kernel.width; ki++ ) {
						int indexSrc = indexSrcStart+ki*src.stride + band;
						for( int kj = 0; kj <  kernel.width; kj++ ) {
							total += (dataSrc[indexSrc] & 0xFF)* dataKernel[indexKer++];
							indexSrc += numBands;
						}
					}
					dataDst[indexDst++] = (byte)((total+halfDivisor)/divisor);
				}
			}
		}
		//CONCURRENT_ABOVE });
	}

	public static void horizontal( Kernel1D_S32 kernel ,
								   InterleavedS16 src, InterleavedI16 dst , int divisor ) {
		final short[] dataSrc = src.data;
		final short[] dataDst = dst.data;
		final int[] dataKer = kernel.data;

		final int offset = kernel.getOffset();
		final int kernelWidth = kernel.getWidth();
		final int numBands = src.getNumBands();
		final int halfDivisor = divisor/2;

		final int endJ = src.width - (kernelWidth - 1);

		//CONCURRENT_BELOW BoofConcurrency.loopFor(0, src.height, i -> {
		for( int i = 0; i < src.height; i++ ) {
			int indexDst = dst.startIndex + i*dst.stride+offset*numBands;
			for (int j = 0; j < endJ; j++) {
				int indexSrcStart = src.startIndex + i*src.stride + j*numBands;
				for (int band = 0; band < numBands; band++) {
					int indexSrc = indexSrcStart + band;
					int total = 0;
					for (int k = 0; k < kernelWidth; k++, indexSrc += numBands) {
						total += (dataSrc[indexSrc] ) * dataKer[k];
					}
					dataDst[indexDst++] = (short)((total+halfDivisor)/divisor);
				}
			}
		}
		//CONCURRENT_ABOVE });
	}

	public static void vertical( Kernel1D_S32 kernel,
								 InterleavedS16 src, InterleavedI16 dst , int divisor )
	{
		final short[] dataSrc = src.data;
		final short[] dataDst = dst.data;
		final int[] dataKer = kernel.data;

		final int offset = kernel.getOffset();
		final int kernelWidth = kernel.getWidth();
		final int numBands = src.getNumBands();
		final int halfDivisor = divisor/2;

		final int imgWidth = dst.getWidth();
		final int imgHeight = dst.getHeight();

		final int yEnd = imgHeight-(kernelWidth-offset-1);

		//CONCURRENT_BELOW BoofConcurrency.loopFor(offset, yEnd, y -> {
		for( int y = offset; y < yEnd; y++ ) {
			int indexDst = dst.startIndex+y*dst.stride;
			int indexSrcStart = src.startIndex+(y-offset)*src.stride;

			for (int x = 0; x < imgWidth; x++) {
				for (int band = 0; band < numBands; band++) {
					int indexSrc = indexSrcStart + band;

					int total = 0;
					for (int k = 0; k < kernelWidth; k++) {
						total += (dataSrc[indexSrc] )* dataKer[k];
						indexSrc += src.stride;
					}
					dataDst[indexDst++] = (short)((total+halfDivisor)/divisor);
				}
				indexSrcStart += numBands;
			}
		}
		//CONCURRENT_ABOVE });
	}

	public static void convolve( Kernel2D_S32 kernel , InterleavedS16 src , InterleavedI16 dst , int divisor )
	{
		final int[] dataKernel = kernel.data;
		final short[] dataSrc = src.data;
		final short[] dataDst = dst.data;

		final int width = src.getWidth();
		final int height = src.getHeight();
		final int numBands = src.getNumBands();
		final int halfDivisor = divisor/2;

		int offsetL = kernel.offset;
		int offsetR = kernel.width-kernel.offset-1;

		//CONCURRENT_BELOW BoofConcurrency.loopFor(offsetL, height-offsetR, y -> {
		for( int y = offsetL; y < height-offsetR; y++ ) {
			int indexDst = dst.startIndex + y*dst.stride+offsetL*numBands;
			for( int x = offsetL; x < width-offsetR; x++ ) {
				int indexSrcStart = src.startIndex + (y-offsetL)*src.stride + (x-offsetL)*numBands;

				for (int band = 0; band < numBands; band++) {
					int total = 0;
					int indexKer = 0;
					for( int ki = 0; ki < kernel.width; ki++ ) {
						int indexSrc = indexSrcStart+ki*src.stride + band;
						for( int kj = 0; kj <  kernel.width; kj++ ) {
							total += (dataSrc[indexSrc] )* dataKernel[indexKer++];
							indexSrc += numBands;
						}
					}
					dataDst[indexDst++] = (short)((total+halfDivisor)/divisor);
				}
			}
		}
		//CONCURRENT_ABOVE });
	}

	public static void horizontal( Kernel1D_S32 kernel ,
								   InterleavedU16 src, InterleavedI16 dst ) {
		final short[] dataSrc = src.data;
		final short[] dataDst = dst.data;
		final int[] dataKer = kernel.data;

		final int offset = kernel.getOffset();
		final int kernelWidth = kernel.getWidth();
		final int numBands = src.getNumBands();

		final int endJ = src.width - (kernelWidth - 1);

		//CONCURRENT_BELOW BoofConcurrency.loopFor(0, src.height, i -> {
		for( int i = 0; i < src.height; i++ ) {
			int indexDst = dst.startIndex + i*dst.stride+offset*numBands;
			for (int j = 0; j < endJ; j++) {
				int indexSrcStart = src.startIndex + i*src.stride + j*numBands;
				for (int band = 0; band < numBands; band++) {
					int indexSrc = indexSrcStart + band;
					int total = 0;
					for (int k = 0; k < kernelWidth; k++, indexSrc += numBands) {
						total += (dataSrc[indexSrc] & 0xFFFF) * dataKer[k];
					}
					dataDst[indexDst++] = (short)total;
				}
			}
		}
		//CONCURRENT_ABOVE });
	}

	public static void vertical( Kernel1D_S32 kernel,
								 InterleavedU16 src, InterleavedI16 dst )
	{
		final short[] dataSrc = src.data;
		final short[] dataDst = dst.data;
		final int[] dataKer = kernel.data;

		final int offset = kernel.getOffset();
		final int kernelWidth = kernel.getWidth();
		final int numBands = src.getNumBands();

		final int imgWidth = dst.getWidth();
		final int imgHeight = dst.getHeight();

		final int yEnd = imgHeight-(kernelWidth-offset-1);

		//CONCURRENT_BELOW BoofConcurrency.loopFor(offset, yEnd, y -> {
		for( int y = offset; y < yEnd; y++ ) {
			int indexDst = dst.startIndex+y*dst.stride;
			int indexSrcStart = src.startIndex+(y-offset)*src.stride;

			for (int x = 0; x < imgWidth; x++) {
				for (int band = 0; band < numBands; band++) {
					int indexSrc = indexSrcStart + band;

					int total = 0;
					for (int k = 0; k < kernelWidth; k++) {
						total += (dataSrc[indexSrc] & 0xFFFF)* dataKer[k];
						indexSrc += src.stride;
					}
					dataDst[indexDst++] = (short)total;
				}
				indexSrcStart += numBands;
			}
		}
		//CONCURRENT_ABOVE });
	}

	public static void convolve( Kernel2D_S32 kernel , InterleavedU16 src , InterleavedI16 dst )
	{
		final int[] dataKernel = kernel.data;
		final short[] dataSrc = src.data;
		final short[] dataDst = dst.data;

		final int width = src.getWidth();
		final int height = src.getHeight();
		final int numBands = src.getNumBands();

		int offsetL = kernel.offset;
		int offsetR = kernel.width-kernel.offset-1;

		//CONCURRENT_BELOW BoofConcurrency.loopFor(offsetL, height-offsetR, y -> {
		for( int y = offsetL; y < height-offsetR; y++ ) {
			int indexDst = dst.startIndex + y*dst.stride+offsetL*numBands;
			for( int x = offsetL; x < width-offsetR; x++ ) {
				int indexSrcStart = src.startIndex + (y-offsetL)*src.stride + (x-offsetL)*numBands;

				for (int band = 0; band < numBands; band++) {
					int total = 0;
					int indexKer = 0;
					for( int ki = 0; ki < kernel.width; ki++ ) {
						int indexSrc = indexSrcStart+ki*src.stride + band;
						for( int kj = 0; kj <  kernel.width; kj++ ) {
							total += (dataSrc[indexSrc] & 0xFFFF)* dataKernel[indexKer++];
							indexSrc += numBands;
						}
					}
					dataDst[indexDst++] = (short)total;
				}
			}
		}
		//CONCURRENT_ABOVE });
	}

	public static void horizontal( Kernel1D_S32 kernel ,
								   InterleavedU16 src, InterleavedI16 dst , int divisor ) {
		final short[] dataSrc = src.data;
		final short[] dataDst = dst.data;
		final int[] dataKer = kernel.data;

		final int offset = kernel.getOffset();
		final int kernelWidth = kernel.getWidth();
		final int numBands = src.getNumBands();
		final int halfDivisor = divisor/2;

		final int endJ = src.width - (kernelWidth - 1);

		//CONCURRENT_BELOW BoofConcurrency.loopFor(0, src.height, i -> {
		for( int i = 0; i < src.height; i++ ) {
			int indexDst = dst.startIndex + i*dst.stride+offset*numBands;
			for (int j = 0; j < endJ; j++) {
				int indexSrcStart = src.startIndex + i*src.stride + j*numBands;
				for (int band = 0; band < numBands; band++) {
					int indexSrc = indexSrcStart + band;
					int total = 0;
					for (int k = 0; k < kernelWidth; k++, indexSrc += numBands) {
						total += (dataSrc[indexSrc] & 0xFFFF) * dataKer[k];
					}
					dataDst[indexDst++] = (short)((total+halfDivisor)/divisor);
				}
			}
		}
		//CONCURRENT_ABOVE });
	}

	public static void vertical( Kernel1D_S32 kernel,
								 InterleavedU16 src, InterleavedI16 dst , int divisor )
	{
		final short[] dataSrc = src.data;
		final short[] dataDst = dst.data;
		final int[] dataKer = kernel.data;

		final int offset = kernel.getOffset();
		final int kernelWidth = kernel.getWidth();
		final int numBands = src.getNumBands();
		final int halfDivisor = divisor/2;

		final int imgWidth = dst.getWidth();
		final int imgHeight = dst.getHeight();

		final int yEnd = imgHeight-(kernelWidth-offset-1);

		//CONCURRENT_BELOW BoofConcurrency.loopFor(offset, yEnd, y -> {
		for( int y = offset; y < yEnd; y++ ) {
			int indexDst = dst.startIndex+y*dst.stride;
			int indexSrcStart = src.startIndex+(y-offset)*src.stride;

			for (int x = 0; x < imgWidth; x++) {
				for (int band = 0; band < numBands; band++) {
					int indexSrc = indexSrcStart + band;

					int total = 0;
					for (int k = 0; k < kernelWidth; k++) {
						total += (dataSrc[indexSrc] & 0xFFFF)* dataKer[k];
						indexSrc += src.stride;
					}
					dataDst[indexDst++] = (short)((total+halfDivisor)/divisor);
				}
				indexSrcStart += numBands;
			}
		}
		//CONCURRENT_ABOVE });
	}

	public static void convolve( Kernel2D_S32 kernel , InterleavedU16 src , InterleavedI16 dst , int divisor )
	{
		final int[] dataKernel = kernel.data;
		final short[] dataSrc = src.data;
		final short[] dataDst = dst.data;

		final int width = src.getWidth();
		final int height = src.getHeight();
		final int numBands = src.getNumBands();
		final int halfDivisor = divisor/2;

		int offsetL = kernel.offset;
		int offsetR = kernel.width-kernel.offset-1;

		//CONCURRENT_BELOW BoofConcurrency.loopFor(offsetL, height-offsetR, y -> {
		for( int y = offsetL; y < height-offsetR; y++ ) {
			int indexDst = dst.startIndex + y*dst.stride+offsetL*numBands;
			for( int x = offsetL; x < width-offsetR; x++ ) {
				int indexSrcStart = src.startIndex + (y-offsetL)*src.stride + (x-offsetL)*numBands;

				for (int band = 0; band < numBands; band++) {
					int total = 0;
					int indexKer = 0;
					for( int ki = 0; ki < kernel.width; ki++ ) {
						int indexSrc = indexSrcStart+ki*src.stride + band;
						for( int kj = 0; kj <  kernel.width; kj++ ) {
							total += (dataSrc[indexSrc] & 0xFFFF)* dataKernel[indexKer++];
							indexSrc += numBands;
						}
					}
					dataDst[indexDst++] = (short)((total+halfDivisor)/divisor);
				}
			}
		}
		//CONCURRENT_ABOVE });
	}

	public static void vertical( Kernel1D_S32 kernel,
								 InterleavedS32 src, InterleavedI16 dst , int divisor )
	{
		final int[] dataSrc = src.data;
		final short[] dataDst = dst.data;
		final int[] dataKer = kernel.data;

		final int offset = kernel.getOffset();
		final int kernelWidth = kernel.getWidth();
		final int numBands = src.getNumBands();
		final int halfDivisor = divisor/2;

		final int imgWidth = dst.getWidth();
		final int imgHeight = dst.getHeight();

		final int yEnd = imgHeight-(kernelWidth-offset-1);

		//CONCURRENT_BELOW BoofConcurrency.loopFor(offset, yEnd, y -> {
		for( int y = offset; y < yEnd; y++ ) {
			int indexDst = dst.startIndex+y*dst.stride;
			int indexSrcStart = src.startIndex+(y-offset)*src.stride;

			for (int x = 0; x < imgWidth; x++) {
				for (int band = 0; band < numBands; band++) {
					int indexSrc = indexSrcStart + band;

					int total = 0;
					for (int k = 0; k < kernelWidth; k++) {
						total += (dataSrc[indexSrc] )* dataKer[k];
						indexSrc += src.stride;
					}
					dataDst[indexDst++] = (short)((total+halfDivisor)/divisor);
				}
				indexSrcStart += numBands;
			}
		}
		//CONCURRENT_ABOVE });
	}

	public static void horizontal( Kernel1D_S32 kernel ,
								   InterleavedS32 src, InterleavedS32 dst ) {
		final int[] dataSrc = src.data;
		final int[] dataDst = dst.data;
		final int[] dataKer = kernel.data;

		final int offset = kernel.getOffset();
		final int kernelWidth = kernel.getWidth();
		final int numBands = src.getNumBands();

		final int endJ = src.width - (kernelWidth - 1);

		//CONCURRENT_BELOW BoofConcurrency.loopFor(0, src.height, i -> {
		for( int i = 0; i < src.height; i++ ) {
			int indexDst = dst.startIndex + i*dst.stride+offset*numBands;
			for (int j = 0; j < endJ; j++) {
				int indexSrcStart = src.startIndex + i*src.stride + j*numBands;
				for (int band = 0; band < numBands; band++) {
					int indexSrc = indexSrcStart + band;
					int total = 0;
					for (int k = 0; k < kernelWidth; k++, indexSrc += numBands) {
						total += (dataSrc[indexSrc] ) * dataKer[k];
					}
					dataDst[indexDst++] = total;
				}
			}
		}
		//CONCURRENT_ABOVE });
	}

	public static void vertical( Kernel1D_S32 kernel,
								 InterleavedS32 src, InterleavedS32 dst )
	{
		final int[] dataSrc = src.data;
		final int[] dataDst = dst.data;
		final int[] dataKer = kernel.data;

		final int offset = kernel.getOffset();
		final int kernelWidth = kernel.getWidth();
		final int numBands = src.getNumBands();

		final int imgWidth = dst.getWidth();
		final int imgHeight = dst.getHeight();

		final int yEnd = imgHeight-(kernelWidth-offset-1);

		//CONCURRENT_BELOW BoofConcurrency.loopFor(offset, yEnd, y -> {
		for( int y = offset; y < yEnd; y++ ) {
			int indexDst = dst.startIndex+y*dst.stride;
			int indexSrcStart = src.startIndex+(y-offset)*src.stride;

			for (int x = 0; x < imgWidth; x++) {
				for (int band = 0; band < numBands; band++) {
					int indexSrc = indexSrcStart + band;

					int total = 0;
					for (int k = 0; k < kernelWidth; k++) {
						total += (dataSrc[indexSrc] )* dataKer[k];
						indexSrc += src.stride;
					}
					dataDst[indexDst++] = total;
				}
				indexSrcStart += numBands;
			}
		}
		//CONCURRENT_ABOVE });
	}

	public static void convolve( Kernel2D_S32 kernel , InterleavedS32 src , InterleavedS32 dst )
	{
		final int[] dataKernel = kernel.data;
		final int[] dataSrc = src.data;
		final int[] dataDst = dst.data;

		final int width = src.getWidth();
		final int height = src.getHeight();
		final int numBands = src.getNumBands();

		int offsetL = kernel.offset;
		int offsetR = kernel.width-kernel.offset-1;

		//CONCURRENT_BELOW BoofConcurrency.loopFor(offsetL, height-offsetR, y -> {
		for( int y = offsetL; y < height-offsetR; y++ ) {
			int indexDst = dst.startIndex + y*dst.stride+offsetL*numBands;
			for( int x = offsetL; x < width-offsetR; x++ ) {
				int indexSrcStart = src.startIndex + (y-offsetL)*src.stride + (x-offsetL)*numBands;

				for (int band = 0; band < numBands; band++) {
					int total = 0;
					int indexKer = 0;
					for( int ki = 0; ki < kernel.width; ki++ ) {
						int indexSrc = indexSrcStart+ki*src.stride + band;
						for( int kj = 0; kj <  kernel.width; kj++ ) {
							total += (dataSrc[indexSrc] )* dataKernel[indexKer++];
							indexSrc += numBands;
						}
					}
					dataDst[indexDst++] = total;
				}
			}
		}
		//CONCURRENT_ABOVE });
	}

	public static void horizontal( Kernel1D_S32 kernel ,
								   InterleavedS32 src, InterleavedS32 dst , int divisor ) {
		final int[] dataSrc = src.data;
		final int[] dataDst = dst.data;
		final int[] dataKer = kernel.data;

		final int offset = kernel.getOffset();
		final int kernelWidth = kernel.getWidth();
		final int numBands = src.getNumBands();
		final int halfDivisor = divisor/2;

		final int endJ = src.width - (kernelWidth - 1);

		//CONCURRENT_BELOW BoofConcurrency.loopFor(0, src.height, i -> {
		for( int i = 0; i < src.height; i++ ) {
			int indexDst = dst.startIndex + i*dst.stride+offset*numBands;
			for (int j = 0; j < endJ; j++) {
				int indexSrcStart = src.startIndex + i*src.stride + j*numBands;
				for (int band = 0; band < numBands; band++) {
					int indexSrc = indexSrcStart + band;
					int total = 0;
					for (int k = 0; k < kernelWidth; k++, indexSrc += numBands) {
						total += (dataSrc[indexSrc] ) * dataKer[k];
					}
					dataDst[indexDst++] = ((total+halfDivisor)/divisor);
				}
			}
		}
		//CONCURRENT_ABOVE });
	}

	public static void vertical( Kernel1D_S32 kernel,
								 InterleavedS32 src, InterleavedS32 dst , int divisor )
	{
		final int[] dataSrc = src.data;
		final int[] dataDst = dst.data;
		final int[] dataKer = kernel.data;

		final int offset = kernel.getOffset();
		final int kernelWidth = kernel.getWidth();
		final int numBands = src.getNumBands();
		final int halfDivisor = divisor/2;

		final int imgWidth = dst.getWidth();
		final int imgHeight = dst.getHeight();

		final int yEnd = imgHeight-(kernelWidth-offset-1);

		//CONCURRENT_BELOW BoofConcurrency.loopFor(offset, yEnd, y -> {
		for( int y = offset; y < yEnd; y++ ) {
			int indexDst = dst.startIndex+y*dst.stride;
			int indexSrcStart = src.startIndex+(y-offset)*src.stride;

			for (int x = 0; x < imgWidth; x++) {
				for (int band = 0; band < numBands; band++) {
					int indexSrc = indexSrcStart + band;

					int total = 0;
					for (int k = 0; k < kernelWidth; k++) {
						total += (dataSrc[indexSrc] )* dataKer[k];
						indexSrc += src.stride;
					}
					dataDst[indexDst++] = ((total+halfDivisor)/divisor);
				}
				indexSrcStart += numBands;
			}
		}
		//CONCURRENT_ABOVE });
	}

	public static void convolve( Kernel2D_S32 kernel , InterleavedS32 src , InterleavedS32 dst , int divisor )
	{
		final int[] dataKernel = kernel.data;
		final int[] dataSrc = src.data;
		final int[] dataDst = dst.data;

		final int width = src.getWidth();
		final int height = src.getHeight();
		final int numBands = src.getNumBands();
		final int halfDivisor = divisor/2;

		int offsetL = kernel.offset;
		int offsetR = kernel.width-kernel.offset-1;

		//CONCURRENT_BELOW BoofConcurrency.loopFor(offsetL, height-offsetR, y -> {
		for( int y = offsetL; y < height-offsetR; y++ ) {
			int indexDst = dst.startIndex + y*dst.stride+offsetL*numBands;
			for( int x = offsetL; x < width-offsetR; x++ ) {
				int indexSrcStart = src.startIndex + (y-offsetL)*src.stride + (x-offsetL)*numBands;

				for (int band = 0; band < numBands; band++) {
					int total = 0;
					int indexKer = 0;
					for( int ki = 0; ki < kernel.width; ki++ ) {
						int indexSrc = indexSrcStart+ki*src.stride + band;
						for( int kj = 0; kj <  kernel.width; kj++ ) {
							total += (dataSrc[indexSrc] )* dataKernel[indexKer++];
							indexSrc += numBands;
						}
					}
					dataDst[indexDst++] = ((total+halfDivisor)/divisor);
				}
			}
		}
		//CONCURRENT_ABOVE });
	}

}

{'repo_name': 'lessthanoptimal/BoofCV', 'stars': '659', 'repo_language': 'Java', 'file_name': 'ExampleFxShowImage.java', 'mime_type': 'text/x-c', 'hash': -7702206551562678673, 'source_dataset': 'data'}


/* -*- Mode: C; c-basic-offset:8 ; indent-tabs-mode:t -*- */
/*
 * Linux usbfs backend for libusb
 * Copyright (C) 2007-2009 Daniel Drake <dsd@gentoo.org>
 * Copyright (c) 2001 Johannes Erdfelt <johannes@erdfelt.com>
 * Copyright (c) 2012-2013 Nathan Hjelm <hjelmn@mac.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

#include <config.h>

#include <assert.h>
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <poll.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/utsname.h>
#include <sys/socket.h>
#include <unistd.h>
#include <libudev.h>

#include "libusbi.h"
#include "linux_usbfs.h"

/* udev context */
static struct udev *udev_ctx = NULL;
static int udev_monitor_fd = -1;
static int udev_control_pipe[2] = {-1, -1};
static struct udev_monitor *udev_monitor = NULL;
static pthread_t linux_event_thread;

static void udev_hotplug_event(struct udev_device* udev_dev);
static void *linux_udev_event_thread_main(void *arg);

int linux_udev_start_event_monitor(void)
{
	int r;

	assert(udev_ctx == NULL);
	udev_ctx = udev_new();
	if (!udev_ctx) {
		usbi_err(NULL, "could not create udev context");
		goto err;
	}

	udev_monitor = udev_monitor_new_from_netlink(udev_ctx, "udev");
	if (!udev_monitor) {
		usbi_err(NULL, "could not initialize udev monitor");
		goto err_free_ctx;
	}

	r = udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "usb", "usb_device");
	if (r) {
		usbi_err(NULL, "could not initialize udev monitor filter for \"usb\" subsystem");
		goto err_free_monitor;
	}

	if (udev_monitor_enable_receiving(udev_monitor)) {
		usbi_err(NULL, "failed to enable the udev monitor");
		goto err_free_monitor;
	}

	udev_monitor_fd = udev_monitor_get_fd(udev_monitor);

	/* Some older versions of udev are not non-blocking by default,
	 * so make sure this is set */
	r = fcntl(udev_monitor_fd, F_GETFL);
	if (r == -1) {
		usbi_err(NULL, "getting udev monitor fd flags (%d)", errno);
		goto err_free_monitor;
	}
	r = fcntl(udev_monitor_fd, F_SETFL, r | O_NONBLOCK);
	if (r) {
		usbi_err(NULL, "setting udev monitor fd flags (%d)", errno);
		goto err_free_monitor;
	}

	r = usbi_pipe(udev_control_pipe);
	if (r) {
		usbi_err(NULL, "could not create udev control pipe");
		goto err_free_monitor;
	}

	r = pthread_create(&linux_event_thread, NULL, linux_udev_event_thread_main, NULL);
	if (r) {
		usbi_err(NULL, "creating hotplug event thread (%d)", r);
		goto err_close_pipe;
	}

	return LIBUSB_SUCCESS;

err_close_pipe:
	close(udev_control_pipe[0]);
	close(udev_control_pipe[1]);
err_free_monitor:
	udev_monitor_unref(udev_monitor);
	udev_monitor = NULL;
	udev_monitor_fd = -1;
err_free_ctx:
	udev_unref(udev_ctx);
err:
	udev_ctx = NULL;
	return LIBUSB_ERROR_OTHER;
}

int linux_udev_stop_event_monitor(void)
{
	char dummy = 1;
	int r;

	assert(udev_ctx != NULL);
	assert(udev_monitor != NULL);
	assert(udev_monitor_fd != -1);

	/* Write some dummy data to the control pipe and
	 * wait for the thread to exit */
	r = usbi_write(udev_control_pipe[1], &dummy, sizeof(dummy));
	if (r <= 0) {
		usbi_warn(NULL, "udev control pipe signal failed");
	}
	pthread_join(linux_event_thread, NULL);

	/* Release the udev monitor */
	udev_monitor_unref(udev_monitor);
	udev_monitor = NULL;
	udev_monitor_fd = -1;

	/* Clean up the udev context */
	udev_unref(udev_ctx);
	udev_ctx = NULL;

	/* close and reset control pipe */
	close(udev_control_pipe[0]);
	close(udev_control_pipe[1]);
	udev_control_pipe[0] = -1;
	udev_control_pipe[1] = -1;

	return LIBUSB_SUCCESS;
}

static void *linux_udev_event_thread_main(void *arg)
{
	char dummy;
	int r;
	struct udev_device* udev_dev;
	struct pollfd fds[] = {
		{.fd = udev_control_pipe[0],
		 .events = POLLIN},
		{.fd = udev_monitor_fd,
		 .events = POLLIN},
	};

	usbi_dbg("udev event thread entering.");

	while (poll(fds, 2, -1) >= 0) {
		if (fds[0].revents & POLLIN) {
			/* activity on control pipe, read the byte and exit */
			r = usbi_read(udev_control_pipe[0], &dummy, sizeof(dummy));
			if (r <= 0) {
				usbi_warn(NULL, "udev control pipe read failed");
			}
			break;
		}
		if (fds[1].revents & POLLIN) {
			usbi_mutex_static_lock(&linux_hotplug_lock);
			udev_dev = udev_monitor_receive_device(udev_monitor);
			if (udev_dev)
				udev_hotplug_event(udev_dev);
			usbi_mutex_static_unlock(&linux_hotplug_lock);
		}
	}

	usbi_dbg("udev event thread exiting");

	return NULL;
}

static int udev_device_info(struct libusb_context *ctx, int detached,
			    struct udev_device *udev_dev, uint8_t *busnum,
			    uint8_t *devaddr, const char **sys_name) {
	const char *dev_node;

	dev_node = udev_device_get_devnode(udev_dev);
	if (!dev_node) {
		return LIBUSB_ERROR_OTHER;
	}

	*sys_name = udev_device_get_sysname(udev_dev);
	if (!*sys_name) {
		return LIBUSB_ERROR_OTHER;
	}

	return linux_get_device_address(ctx, detached, busnum, devaddr,
					dev_node, *sys_name);
}

static void udev_hotplug_event(struct udev_device* udev_dev)
{
	const char* udev_action;
	const char* sys_name = NULL;
	uint8_t busnum = 0, devaddr = 0;
	int detached;
	int r;

	do {
		udev_action = udev_device_get_action(udev_dev);
		if (!udev_action) {
			break;
		}

		detached = !strncmp(udev_action, "remove", 6);

		r = udev_device_info(NULL, detached, udev_dev, &busnum, &devaddr, &sys_name);
		if (LIBUSB_SUCCESS != r) {
			break;
		}

		usbi_dbg("udev hotplug event. action: %s.", udev_action);

		if (strncmp(udev_action, "add", 3) == 0) {
			linux_hotplug_enumerate(busnum, devaddr, sys_name);
		} else if (detached) {
			linux_device_disconnected(busnum, devaddr);
		} else {
			usbi_err(NULL, "ignoring udev action %s", udev_action);
		}
	} while (0);

	udev_device_unref(udev_dev);
}

int linux_udev_scan_devices(struct libusb_context *ctx)
{
	struct udev_enumerate *enumerator;
	struct udev_list_entry *devices, *entry;
	struct udev_device *udev_dev;
	const char *sys_name;
	int r;

	assert(udev_ctx != NULL);

	enumerator = udev_enumerate_new(udev_ctx);
	if (NULL == enumerator) {
		usbi_err(ctx, "error creating udev enumerator");
		return LIBUSB_ERROR_OTHER;
	}

	udev_enumerate_add_match_subsystem(enumerator, "usb");
	udev_enumerate_add_match_property(enumerator, "DEVTYPE", "usb_device");
	udev_enumerate_scan_devices(enumerator);
	devices = udev_enumerate_get_list_entry(enumerator);

	udev_list_entry_foreach(entry, devices) {
		const char *path = udev_list_entry_get_name(entry);
		uint8_t busnum = 0, devaddr = 0;

		udev_dev = udev_device_new_from_syspath(udev_ctx, path);

		r = udev_device_info(ctx, 0, udev_dev, &busnum, &devaddr, &sys_name);
		if (r) {
			udev_device_unref(udev_dev);
			continue;
		}

		linux_enumerate_device(ctx, busnum, devaddr, sys_name);
		udev_device_unref(udev_dev);
	}

	udev_enumerate_unref(enumerator);

	return LIBUSB_SUCCESS;
}

void linux_udev_hotplug_poll(void)
{
	struct udev_device* udev_dev;

	usbi_mutex_static_lock(&linux_hotplug_lock);
	do {
		udev_dev = udev_monitor_receive_device(udev_monitor);
		if (udev_dev) {
			usbi_dbg("Handling hotplug event from hotplug_poll");
			udev_hotplug_event(udev_dev);
		}
	} while (udev_dev);
	usbi_mutex_static_unlock(&linux_hotplug_lock);
}

{'repo_name': 'Tinob/Ishiiruka', 'stars': '237', 'repo_language': 'C++', 'file_name': 'config', 'mime_type': 'text/plain', 'hash': -3985445771448487678, 'source_dataset': 'data'}


            <bx_injection:injection_top_menu_before />
            __code__
            <bx_injection:injection_top_menu_after />

{'repo_name': 'unaio/una', 'stars': '147', 'repo_language': 'PHP', 'file_name': 'ru.xml', 'mime_type': 'text/xml', 'hash': -3588053230830905414, 'source_dataset': 'data'}


/* Copyright 2009 HPDI, LLC
 *
 * 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.
 */

using System;
using System.Collections;
using System.Collections.Generic;
using Hpdi.VssPhysicalLib;

namespace Hpdi.VssLogicalLib
{
    /// <summary>
    /// Represents an abstract VSS item, which is a project or file.
    /// </summary>
    /// <author>Trevor Robinson</author>
    public abstract class VssItem
    {
        protected readonly VssDatabase database;
        protected readonly VssItemName itemName;
        protected readonly string physicalPath;
        private ItemFile itemFile;

        public VssDatabase Database
        {
            get { return database; }
        }

        public VssItemName ItemName
        {
            get { return itemName; }
        }

        public bool IsProject
        {
            get { return itemName.IsProject; }
        }

        public string Name
        {
            get { return itemName.LogicalName; }
        }

        public string PhysicalName
        {
            get { return itemName.PhysicalName; }
        }

        public string PhysicalPath
        {
            get { return physicalPath; }
        }

        public string DataPath
        {
            get { return physicalPath + ItemFile.Header.DataExt; }
        }

        public int RevisionCount
        {
            get { return ItemFile.Header.Revisions; }
        }

        public IEnumerable<VssRevision> Revisions
        {
            get { return new VssRevisions<VssItem, VssRevision>(this); }
        }

        public VssRevision GetRevision(int version)
        {
            var itemFile = ItemFile;
            if (version < 1 || version > itemFile.Header.Revisions)
            {
                throw new ArgumentOutOfRangeException("version", version, "Invalid version number");
            }

            // check whether version was before branch
            if (version < itemFile.Header.FirstRevision)
            {
                if (!IsProject)
                {
                    var fileHeader = (FileHeaderRecord)itemFile.Header;
                    return database.GetItemPhysical(fileHeader.BranchFile).GetRevision(version);
                }
                else
                {
                    // should never happen; projects cannot branch
                    throw new ArgumentOutOfRangeException("version", version, "Undefined version");
                }
            }

            var revisionRecord = itemFile.GetFirstRevision();
            while (revisionRecord != null && revisionRecord.Revision < version)
            {
                revisionRecord = itemFile.GetNextRevision(revisionRecord);
            }
            if (revisionRecord == null)
            {
                throw new ArgumentException("Version not found", "version");
            }
            return CreateRevision(revisionRecord);
        }

        internal ItemFile ItemFile
        {
            get
            {
                if (itemFile == null)
                {
                    itemFile = new ItemFile(physicalPath, database.Encoding);
                }
                return itemFile;
            }
            set
            {
                itemFile = value;
            }
        }

        internal VssItem(VssDatabase database, VssItemName itemName, string physicalPath)
        {
            this.database = database;
            this.itemName = itemName;
            this.physicalPath = physicalPath;
        }

        protected VssRevision CreateRevision(RevisionRecord revision)
        {
            CommentRecord comment = null;
            if (revision.CommentLength > 0 && revision.CommentOffset > 0)
            {
                comment = new CommentRecord();
                ItemFile.ReadRecord(comment, revision.CommentOffset);
            }
            else if (revision.Action == VssPhysicalLib.Action.Label &&
                revision.LabelCommentLength > 0 && revision.LabelCommentOffset > 0)
            {
                comment = new CommentRecord();
                ItemFile.ReadRecord(comment, revision.LabelCommentOffset);
            }
            return CreateRevision(revision, comment);
        }

        protected abstract VssRevision CreateRevision(RevisionRecord revision, CommentRecord comment);

        protected class VssRevisions<ItemT, RevisionT> : IEnumerable<RevisionT>
            where ItemT : VssItem
            where RevisionT : VssRevision
        {
            private readonly ItemT item;

            internal VssRevisions(ItemT item)
            {
                this.item = item;
            }

            public IEnumerator<RevisionT> GetEnumerator()
            {
                return new VssRevisionEnumerator<ItemT, RevisionT>(item);
            }

            IEnumerator IEnumerable.GetEnumerator()
            {
                return this.GetEnumerator();
            }
        }

        private class VssRevisionEnumerator<ItemT, RevisionT> : IEnumerator<RevisionT>
            where ItemT : VssItem
            where RevisionT : VssRevision
        {
            private readonly ItemT item;
            private RevisionRecord revisionRecord;
            private RevisionT revision;
            private bool beforeFirst = true;

            internal VssRevisionEnumerator(ItemT item)
            {
                this.item = item;
            }

            public void Dispose()
            {
            }

            public void Reset()
            {
                beforeFirst = true;
            }

            public bool MoveNext()
            {
                revision = null;
                if (beforeFirst)
                {
                    revisionRecord = item.ItemFile.GetFirstRevision();
                    beforeFirst = false;
                }
                else if (revisionRecord != null)
                {
                    revisionRecord = item.ItemFile.GetNextRevision(revisionRecord);
                }
                return revisionRecord != null;
            }

            public RevisionT Current
            {
                get
                {
                    if (revisionRecord == null)
                    {
                        throw new InvalidOperationException();
                    }

                    if (revision == null)
                    {
                        revision = (RevisionT)item.CreateRevision(revisionRecord);
                    }

                    return revision;
                }
            }

            object IEnumerator.Current
            {
                get { return this.Current; }
            }
        }
    }
}

{'repo_name': 'trevorr/vss2git', 'stars': '111', 'repo_language': 'C#', 'file_name': 'AssemblyInfo.cs', 'mime_type': 'text/plain', 'hash': -3334620056721528439, 'source_dataset': 'data'}


// DO NOT EDIT THIS FILE - it is machine generated -*- c++ -*-

#ifndef __gnu_javax_swing_text_html_css_CSSParserException__
#define __gnu_javax_swing_text_html_css_CSSParserException__

#pragma interface

#include <java/io/IOException.h>
extern "Java"
{
  namespace gnu
  {
    namespace javax
    {
      namespace swing
      {
        namespace text
        {
          namespace html
          {
            namespace css
            {
                class CSSParserException;
            }
          }
        }
      }
    }
  }
}

class gnu::javax::swing::text::html::css::CSSParserException : public ::java::io::IOException
{

public:
  CSSParserException(::java::lang::String *);
  static ::java::lang::Class class$;
};

#endif // __gnu_javax_swing_text_html_css_CSSParserException__

{'repo_name': 'jcmvbkbc/gcc-xtensa', 'stars': '121', 'repo_language': 'C', 'file_name': 'api.html', 'mime_type': 'text/xml', 'hash': 6967908110769723505, 'source_dataset': 'data'}


// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright (c) 2013, Google Inc.
 *
 * (C) Copyright 2008 Semihalf
 *
 * (C) Copyright 2000-2006
 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
 */

#include <common.h>
#include <fdt_support.h>
#include <fdtdec.h>
#include <env.h>
#include <errno.h>
#include <image.h>
#include <linux/libfdt.h>
#include <mapmem.h>
#include <asm/io.h>
#include <tee/optee.h>

#ifndef CONFIG_SYS_FDT_PAD
#define CONFIG_SYS_FDT_PAD 0x3000
#endif

/* adding a ramdisk needs 0x44 bytes in version 2008.10 */
#define FDT_RAMDISK_OVERHEAD	0x80

DECLARE_GLOBAL_DATA_PTR;

static void fdt_error(const char *msg)
{
	puts("ERROR: ");
	puts(msg);
	puts(" - must RESET the board to recover.\n");
}

#if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT)
static const image_header_t *image_get_fdt(ulong fdt_addr)
{
	const image_header_t *fdt_hdr = map_sysmem(fdt_addr, 0);

	image_print_contents(fdt_hdr);

	puts("   Verifying Checksum ... ");
	if (!image_check_hcrc(fdt_hdr)) {
		fdt_error("fdt header checksum invalid");
		return NULL;
	}

	if (!image_check_dcrc(fdt_hdr)) {
		fdt_error("fdt checksum invalid");
		return NULL;
	}
	puts("OK\n");

	if (!image_check_type(fdt_hdr, IH_TYPE_FLATDT)) {
		fdt_error("uImage is not a fdt");
		return NULL;
	}
	if (image_get_comp(fdt_hdr) != IH_COMP_NONE) {
		fdt_error("uImage is compressed");
		return NULL;
	}
	if (fdt_check_header((void *)image_get_data(fdt_hdr)) != 0) {
		fdt_error("uImage data is not a fdt");
		return NULL;
	}
	return fdt_hdr;
}
#endif

static void boot_fdt_reserve_region(struct lmb *lmb, uint64_t addr,
				    uint64_t size)
{
	long ret;

	ret = lmb_reserve(lmb, addr, size);
	if (ret >= 0) {
		debug("   reserving fdt memory region: addr=%llx size=%llx\n",
		      (unsigned long long)addr, (unsigned long long)size);
	} else {
		puts("ERROR: reserving fdt memory region failed ");
		printf("(addr=%llx size=%llx)\n",
		       (unsigned long long)addr, (unsigned long long)size);
	}
}

/**
 * boot_fdt_add_mem_rsv_regions - Mark the memreserve and reserved-memory
 * sections as unusable
 * @lmb: pointer to lmb handle, will be used for memory mgmt
 * @fdt_blob: pointer to fdt blob base address
 *
 * Adds the and reserved-memorymemreserve regions in the dtb to the lmb block.
 * Adding the memreserve regions prevents u-boot from using them to store the
 * initrd or the fdt blob.
 */
void boot_fdt_add_mem_rsv_regions(struct lmb *lmb, void *fdt_blob)
{
	uint64_t addr, size;
	int i, total, ret;
	int nodeoffset, subnode;
	struct fdt_resource res;

	if (fdt_check_header(fdt_blob) != 0)
		return;

	/* process memreserve sections */
	total = fdt_num_mem_rsv(fdt_blob);
	for (i = 0; i < total; i++) {
		if (fdt_get_mem_rsv(fdt_blob, i, &addr, &size) != 0)
			continue;
		boot_fdt_reserve_region(lmb, addr, size);
	}

	/* process reserved-memory */
	nodeoffset = fdt_subnode_offset(fdt_blob, 0, "reserved-memory");
	if (nodeoffset >= 0) {
		subnode = fdt_first_subnode(fdt_blob, nodeoffset);
		while (subnode >= 0) {
			/* check if this subnode has a reg property */
			ret = fdt_get_resource(fdt_blob, subnode, "reg", 0,
					       &res);
			if (!ret) {
				addr = res.start;
				size = res.end - res.start + 1;
				boot_fdt_reserve_region(lmb, addr, size);
			}

			subnode = fdt_next_subnode(fdt_blob, subnode);
		}
	}
}

/**
 * boot_relocate_fdt - relocate flat device tree
 * @lmb: pointer to lmb handle, will be used for memory mgmt
 * @of_flat_tree: pointer to a char* variable, will hold fdt start address
 * @of_size: pointer to a ulong variable, will hold fdt length
 *
 * boot_relocate_fdt() allocates a region of memory within the bootmap and
 * relocates the of_flat_tree into that region, even if the fdt is already in
 * the bootmap.  It also expands the size of the fdt by CONFIG_SYS_FDT_PAD
 * bytes.
 *
 * of_flat_tree and of_size are set to final (after relocation) values
 *
 * returns:
 *      0 - success
 *      1 - failure
 */
int boot_relocate_fdt(struct lmb *lmb, char **of_flat_tree, ulong *of_size)
{
	void	*fdt_blob = *of_flat_tree;
	void	*of_start = NULL;
	char	*fdt_high;
	ulong	of_len = 0;
	int	err;
	int	disable_relocation = 0;

	/* nothing to do */
	if (*of_size == 0)
		return 0;

	if (fdt_check_header(fdt_blob) != 0) {
		fdt_error("image is not a fdt");
		goto error;
	}

	/* position on a 4K boundary before the alloc_current */
	/* Pad the FDT by a specified amount */
	of_len = *of_size + CONFIG_SYS_FDT_PAD;

	/* If fdt_high is set use it to select the relocation address */
	fdt_high = env_get("fdt_high");
	if (fdt_high) {
		void *desired_addr = (void *)simple_strtoul(fdt_high, NULL, 16);

		if (((ulong) desired_addr) == ~0UL) {
			/* All ones means use fdt in place */
			of_start = fdt_blob;
			lmb_reserve(lmb, (ulong)of_start, of_len);
			disable_relocation = 1;
		} else if (desired_addr) {
			of_start =
			    (void *)(ulong) lmb_alloc_base(lmb, of_len, 0x1000,
							   (ulong)desired_addr);
			if (of_start == NULL) {
				puts("Failed using fdt_high value for Device Tree");
				goto error;
			}
		} else {
			of_start =
			    (void *)(ulong) lmb_alloc(lmb, of_len, 0x1000);
		}
	} else {
		of_start =
		    (void *)(ulong) lmb_alloc_base(lmb, of_len, 0x1000,
						   env_get_bootm_mapsize()
						   + env_get_bootm_low());
	}

	if (of_start == NULL) {
		puts("device tree - allocation error\n");
		goto error;
	}

	if (disable_relocation) {
		/*
		 * We assume there is space after the existing fdt to use
		 * for padding
		 */
		fdt_set_totalsize(of_start, of_len);
		printf("   Using Device Tree in place at %p, end %p\n",
		       of_start, of_start + of_len - 1);
	} else {
		debug("## device tree at %p ... %p (len=%ld [0x%lX])\n",
		      fdt_blob, fdt_blob + *of_size - 1, of_len, of_len);

		printf("   Loading Device Tree to %p, end %p ... ",
		       of_start, of_start + of_len - 1);

		err = fdt_open_into(fdt_blob, of_start, of_len);
		if (err != 0) {
			fdt_error("fdt move failed");
			goto error;
		}
		puts("OK\n");
	}

	*of_flat_tree = of_start;
	*of_size = of_len;

	if (CONFIG_IS_ENABLED(CMD_FDT))
		set_working_fdt_addr(map_to_sysmem(*of_flat_tree));
	return 0;

error:
	return 1;
}

/**
 * boot_get_fdt - main fdt handling routine
 * @argc: command argument count
 * @argv: command argument list
 * @arch: architecture (IH_ARCH_...)
 * @images: pointer to the bootm images structure
 * @of_flat_tree: pointer to a char* variable, will hold fdt start address
 * @of_size: pointer to a ulong variable, will hold fdt length
 *
 * boot_get_fdt() is responsible for finding a valid flat device tree image.
 * Curently supported are the following ramdisk sources:
 *      - multicomponent kernel/ramdisk image,
 *      - commandline provided address of decicated ramdisk image.
 *
 * returns:
 *     0, if fdt image was found and valid, or skipped
 *     of_flat_tree and of_size are set to fdt start address and length if
 *     fdt image is found and valid
 *
 *     1, if fdt image is found but corrupted
 *     of_flat_tree and of_size are set to 0 if no fdt exists
 */
int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
		bootm_headers_t *images, char **of_flat_tree, ulong *of_size)
{
#if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT)
	const image_header_t *fdt_hdr;
	ulong		load, load_end;
	ulong		image_start, image_data, image_end;
#endif
	ulong		img_addr;
	ulong		fdt_addr;
	char		*fdt_blob = NULL;
	void		*buf;
#if CONFIG_IS_ENABLED(FIT)
	const char	*fit_uname_config = images->fit_uname_cfg;
	const char	*fit_uname_fdt = NULL;
	ulong		default_addr;
	int		fdt_noffset;
#endif
	const char *select = NULL;

	*of_flat_tree = NULL;
	*of_size = 0;

	img_addr = (argc == 0) ? load_addr : simple_strtoul(argv[0], NULL, 16);
	buf = map_sysmem(img_addr, 0);

	if (argc > 2)
		select = argv[2];
	if (select || genimg_has_config(images)) {
#if CONFIG_IS_ENABLED(FIT)
		if (select) {
			/*
			 * If the FDT blob comes from the FIT image and the
			 * FIT image address is omitted in the command line
			 * argument, try to use ramdisk or os FIT image
			 * address or default load address.
			 */
			if (images->fit_uname_rd)
				default_addr = (ulong)images->fit_hdr_rd;
			else if (images->fit_uname_os)
				default_addr = (ulong)images->fit_hdr_os;
			else
				default_addr = load_addr;

			if (fit_parse_conf(select, default_addr,
					   &fdt_addr, &fit_uname_config)) {
				debug("*  fdt: config '%s' from image at 0x%08lx\n",
				      fit_uname_config, fdt_addr);
			} else if (fit_parse_subimage(select, default_addr,
				   &fdt_addr, &fit_uname_fdt)) {
				debug("*  fdt: subimage '%s' from image at 0x%08lx\n",
				      fit_uname_fdt, fdt_addr);
			} else
#endif
			{
				fdt_addr = simple_strtoul(select, NULL, 16);
				debug("*  fdt: cmdline image address = 0x%08lx\n",
				      fdt_addr);
			}
#if CONFIG_IS_ENABLED(FIT)
		} else {
			/* use FIT configuration provided in first bootm
			 * command argument
			 */
			fdt_addr = map_to_sysmem(images->fit_hdr_os);
			fdt_noffset = fit_get_node_from_config(images,
							       FIT_FDT_PROP,
							       fdt_addr);
			if (fdt_noffset == -ENOENT)
				return 0;
			else if (fdt_noffset < 0)
				return 1;
		}
#endif
		debug("## Checking for 'FDT'/'FDT Image' at %08lx\n",
		      fdt_addr);

		/*
		 * Check if there is an FDT image at the
		 * address provided in the second bootm argument
		 * check image type, for FIT images get a FIT node.
		 */
		buf = map_sysmem(fdt_addr, 0);
		switch (genimg_get_format(buf)) {
#if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT)
		case IMAGE_FORMAT_LEGACY:
			/* verify fdt_addr points to a valid image header */
			printf("## Flattened Device Tree from Legacy Image at %08lx\n",
			       fdt_addr);
			fdt_hdr = image_get_fdt(fdt_addr);
			if (!fdt_hdr)
				goto no_fdt;

			/*
			 * move image data to the load address,
			 * make sure we don't overwrite initial image
			 */
			image_start = (ulong)fdt_hdr;
			image_data = (ulong)image_get_data(fdt_hdr);
			image_end = image_get_image_end(fdt_hdr);

			load = image_get_load(fdt_hdr);
			load_end = load + image_get_data_size(fdt_hdr);

			if (load == image_start ||
			    load == image_data) {
				fdt_addr = load;
				break;
			}

			if ((load < image_end) && (load_end > image_start)) {
				fdt_error("fdt overwritten");
				goto error;
			}

			debug("   Loading FDT from 0x%08lx to 0x%08lx\n",
			      image_data, load);

			memmove((void *)load,
				(void *)image_data,
				image_get_data_size(fdt_hdr));

			fdt_addr = load;
			break;
#endif
		case IMAGE_FORMAT_FIT:
			/*
			 * This case will catch both: new uImage format
			 * (libfdt based) and raw FDT blob (also libfdt
			 * based).
			 */
#if CONFIG_IS_ENABLED(FIT)
			/* check FDT blob vs FIT blob */
			if (fit_check_format(buf)) {
				ulong load, len;

				fdt_noffset = boot_get_fdt_fit(images,
					fdt_addr, &fit_uname_fdt,
					&fit_uname_config,
					arch, &load, &len);

				images->fit_hdr_fdt = map_sysmem(fdt_addr, 0);
				images->fit_uname_fdt = fit_uname_fdt;
				images->fit_noffset_fdt = fdt_noffset;
				fdt_addr = load;

				break;
			} else
#endif
			{
				/*
				 * FDT blob
				 */
				debug("*  fdt: raw FDT blob\n");
				printf("## Flattened Device Tree blob at %08lx\n",
				       (long)fdt_addr);
			}
			break;
		default:
			puts("ERROR: Did not find a cmdline Flattened Device Tree\n");
			goto no_fdt;
		}

		printf("   Booting using the fdt blob at %#08lx\n", fdt_addr);
		fdt_blob = map_sysmem(fdt_addr, 0);
	} else if (images->legacy_hdr_valid &&
			image_check_type(&images->legacy_hdr_os_copy,
					 IH_TYPE_MULTI)) {
		ulong fdt_data, fdt_len;

		/*
		 * Now check if we have a legacy multi-component image,
		 * get second entry data start address and len.
		 */
		printf("## Flattened Device Tree from multi component Image at %08lX\n",
		       (ulong)images->legacy_hdr_os);

		image_multi_getimg(images->legacy_hdr_os, 2, &fdt_data,
				   &fdt_len);
		if (fdt_len) {
			fdt_blob = (char *)fdt_data;
			printf("   Booting using the fdt at 0x%p\n", fdt_blob);

			if (fdt_check_header(fdt_blob) != 0) {
				fdt_error("image is not a fdt");
				goto error;
			}

			if (fdt_totalsize(fdt_blob) != fdt_len) {
				fdt_error("fdt size != image size");
				goto error;
			}
		} else {
			debug("## No Flattened Device Tree\n");
			goto no_fdt;
		}
#ifdef CONFIG_ANDROID_BOOT_IMAGE
	} else if (genimg_get_format(buf) == IMAGE_FORMAT_ANDROID) {
		struct andr_img_hdr *hdr = buf;
		ulong fdt_data, fdt_len;

		if (!android_image_get_second(hdr, &fdt_data, &fdt_len) &&
		    !fdt_check_header((char *)fdt_data)) {
			fdt_blob = (char *)fdt_data;
			if (fdt_totalsize(fdt_blob) != fdt_len)
				goto error;

			debug("## Using FDT in Android image second area\n");
		} else {
			fdt_addr = env_get_hex("fdtaddr", 0);
			if (!fdt_addr)
				goto no_fdt;

			fdt_blob = map_sysmem(fdt_addr, 0);
			if (fdt_check_header(fdt_blob))
				goto no_fdt;

			debug("## Using FDT at ${fdtaddr}=Ox%lx\n", fdt_addr);
		}
#endif
	} else {
		debug("## No Flattened Device Tree\n");
		goto no_fdt;
	}

	*of_flat_tree = fdt_blob;
	*of_size = fdt_totalsize(fdt_blob);
	debug("   of_flat_tree at 0x%08lx size 0x%08lx\n",
	      (ulong)*of_flat_tree, *of_size);

	return 0;

no_fdt:
	debug("Continuing to boot without FDT\n");
	return 0;
error:
	return 1;
}

/*
 * Verify the device tree.
 *
 * This function is called after all device tree fix-ups have been enacted,
 * so that the final device tree can be verified.  The definition of "verified"
 * is up to the specific implementation.  However, it generally means that the
 * addresses of some of the devices in the device tree are compared with the
 * actual addresses at which U-Boot has placed them.
 *
 * Returns 1 on success, 0 on failure.  If 0 is returned, U-Boot will halt the
 * boot process.
 */
__weak int ft_verify_fdt(void *fdt)
{
	return 1;
}

__weak int arch_fixup_fdt(void *blob)
{
	return 0;
}

int image_setup_libfdt(bootm_headers_t *images, void *blob,
		       int of_size, struct lmb *lmb)
{
	ulong *initrd_start = &images->initrd_start;
	ulong *initrd_end = &images->initrd_end;
	int ret = -EPERM;
	int fdt_ret;

	if (fdt_root(blob) < 0) {
		printf("ERROR: root node setup failed\n");
		goto err;
	}
	if (fdt_chosen(blob) < 0) {
		printf("ERROR: /chosen node create failed\n");
		goto err;
	}
	if (arch_fixup_fdt(blob) < 0) {
		printf("ERROR: arch-specific fdt fixup failed\n");
		goto err;
	}
	/* Update ethernet nodes */
	fdt_fixup_ethernet(blob);
	if (IMAGE_OF_BOARD_SETUP) {
		fdt_ret = ft_board_setup(blob, gd->bd);
		if (fdt_ret) {
			printf("ERROR: board-specific fdt fixup failed: %s\n",
			       fdt_strerror(fdt_ret));
			goto err;
		}
	}
	if (IMAGE_OF_SYSTEM_SETUP) {
		fdt_ret = ft_system_setup(blob, gd->bd);
		if (fdt_ret) {
			printf("ERROR: system-specific fdt fixup failed: %s\n",
			       fdt_strerror(fdt_ret));
			goto err;
		}
	}

	fdt_ret = optee_copy_fdt_nodes(gd->fdt_blob, blob);
	if (fdt_ret) {
		printf("ERROR: transfer of optee nodes to new fdt failed: %s\n",
		       fdt_strerror(fdt_ret));
		goto err;
	}

	/* Delete the old LMB reservation */
	if (lmb)
		lmb_free(lmb, (phys_addr_t)(u32)(uintptr_t)blob,
			 (phys_size_t)fdt_totalsize(blob));

	ret = fdt_shrink_to_minimum(blob, 0);
	if (ret < 0)
		goto err;
	of_size = ret;

	if (*initrd_start && *initrd_end) {
		of_size += FDT_RAMDISK_OVERHEAD;
		fdt_set_totalsize(blob, of_size);
	}
	/* Create a new LMB reservation */
	if (lmb)
		lmb_reserve(lmb, (ulong)blob, of_size);

	fdt_initrd(blob, *initrd_start, *initrd_end);
	if (!ft_verify_fdt(blob))
		goto err;

#if defined(CONFIG_SOC_KEYSTONE)
	if (IMAGE_OF_BOARD_SETUP)
		ft_board_setup_ex(blob, gd->bd);
#endif

	return 0;
err:
	printf(" - must RESET the board to recover.\n\n");

	return ret;
}

{'repo_name': 'Xilinx/u-boot-xlnx', 'stars': '350', 'repo_language': 'C', 'file_name': 'Makefile', 'mime_type': 'text/plain', 'hash': -5006007911993697670, 'source_dataset': 'data'}


package com.openwebstart.proxy.linux;

interface LinuxProxyProviderConstants {

    String GNOME_PROXY_MODE = "org.gnome.system.proxy:mode";
    String GNOME_PROXY_AUTOCONFIG_URL = "org.gnome.system.proxy:autoconfig-url";
    String GNOME_PROXY_IGNORE_HOSTS = "org.gnome.system.proxy:ignore-hosts";
    String GNOME_PROXY_HTTP_HOST = "org.gnome.system.proxy.http:host";
    String GNOME_PROXY_HTTP_PORT = "org.gnome.system.proxy.http:port";
    String GNOME_PROXY_HTTPS_HOST = "org.gnome.system.proxy.https:host";
    String GNOME_PROXY_HTTPS_PORT = "org.gnome.system.proxy.https:port";
    String GNOME_PROXY_FTP_HOST = "org.gnome.system.proxy.ftp:host";
    String GNOME_PROXY_FTP_PORT = "org.gnome.system.proxy.ftp:port";
    String GNOME_PROXY_SOCKS_HOST = "org.gnome.system.proxy.socks:host";
    String GNOME_PROXY_SOCKS_PORT = "org.gnome.system.proxy.socks:port";
    // not supported because only valid fro HTTP - see manual of gsettings
    String GNOME_PROXY_USE_AUTHENTICATION = "org.gnome.system.proxy.http:use-authentication";

    String PROPERTY_HTTP_PROXY = "http_proxy";
    String PROPERTY_HTTPS_PROXY = "https_proxy";
    String PROPERTY_FTP_PROXY = "ftp_proxy";
    String PROPERTY_NO_PROXY = "no_proxy";
}

{'repo_name': 'karakun/OpenWebStart', 'stars': '134', 'repo_language': 'Java', 'file_name': 'MavenWrapperDownloader.java', 'mime_type': 'text/x-c', 'hash': -8111166046576432255, 'source_dataset': 'data'}


{'repo_name': 'Needlworks/Textcube', 'stars': '195', 'repo_language': 'PHP', 'file_name': 'plugin-config.css', 'mime_type': 'text/plain', 'hash': -4559406718524170706, 'source_dataset': 'data'}


import "dart:async";
import "dart:convert";

import 'package:gql/language.dart';
import 'package:graphql/src/exceptions/exceptions.dart';
import 'package:graphql/src/link/error/link_error.dart';
import 'package:graphql/src/link/http/link_http.dart';
import 'package:graphql/src/link/link.dart';
import 'package:graphql/src/link/operation.dart';
import "package:http/http.dart" as http;
import "package:mockito/mockito.dart";
import "package:test/test.dart";

class MockClient extends Mock implements http.Client {}

void main() {
  group('error link', () {
    MockClient client;
    Operation query;
    HttpLink httpLink;

    setUp(() {
      client = MockClient();
      query = Operation(
        documentNode: parseString('query Operation {}'),
        operationName: 'Operation',
      );
      httpLink = HttpLink(
        uri: '/graphql-test',
        httpClient: client,
      );
    });

    test('network error', () async {
      bool called = false;

      when(
        client.send(any),
      ).thenAnswer(
        (_) => Future.value(
          http.StreamedResponse(
            Stream.fromIterable(
              [utf8.encode('{}')],
            ),
            400,
          ),
        ),
      );

      final errorLink = ErrorLink(errorHandler: (response) {
        if (response.exception.clientException != null) {
          called = true;
        }
      });

      Exception exception;

      try {
        await execute(
          link: errorLink.concat(httpLink),
          operation: query,
        ).first;
      } on Exception catch (e) {
        exception = e;
      }

      expect(
        exception,
        const TypeMatcher<ClientException>(),
      );
      expect(
        called,
        true,
      );
    });

    test('graphql error', () async {
      bool called = false;

      when(
        client.send(any),
      ).thenAnswer(
        (_) => Future.value(
          http.StreamedResponse(
            Stream.fromIterable(
              [utf8.encode('{"errors":[{"message":"error"}]}')],
            ),
            200,
          ),
        ),
      );

      final errorLink = ErrorLink(errorHandler: (response) {
        if (response.exception.graphqlErrors != null) {
          called = true;
        }
      });

      await execute(
        link: errorLink.concat(httpLink),
        operation: query,
      ).first;

      expect(
        called,
        true,
      );
    });
  });
}

{'repo_name': 'zino-app/graphql-flutter', 'stars': '2064', 'repo_language': 'Dart', 'file_name': 'config.yml', 'mime_type': 'text/plain', 'hash': 6838431675118720201, 'source_dataset': 'data'}


/*
    pybind11/attr.h: Infrastructure for processing custom
    type and function attributes

    Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>

    All rights reserved. Use of this source code is governed by a
    BSD-style license that can be found in the LICENSE file.
*/

#pragma once

#include "cast.h"

NAMESPACE_BEGIN(PYBIND11_NAMESPACE)

/// \addtogroup annotations
/// @{

/// Annotation for methods
struct is_method { handle class_; is_method(const handle &c) : class_(c) { } };

/// Annotation for operators
struct is_operator { };

/// Annotation for parent scope
struct scope { handle value; scope(const handle &s) : value(s) { } };

/// Annotation for documentation
struct doc { const char *value; doc(const char *value) : value(value) { } };

/// Annotation for function names
struct name { const char *value; name(const char *value) : value(value) { } };

/// Annotation indicating that a function is an overload associated with a given "sibling"
struct sibling { handle value; sibling(const handle &value) : value(value.ptr()) { } };

/// Annotation indicating that a class derives from another given type
template <typename T> struct base {
    PYBIND11_DEPRECATED("base<T>() was deprecated in favor of specifying 'T' as a template argument to class_")
    base() { }
};

/// Keep patient alive while nurse lives
template <size_t Nurse, size_t Patient> struct keep_alive { };

/// Annotation indicating that a class is involved in a multiple inheritance relationship
struct multiple_inheritance { };

/// Annotation which enables dynamic attributes, i.e. adds `__dict__` to a class
struct dynamic_attr { };

/// Annotation which enables the buffer protocol for a type
struct buffer_protocol { };

/// Annotation which requests that a special metaclass is created for a type
struct metaclass {
    handle value;

    PYBIND11_DEPRECATED("py::metaclass() is no longer required. It's turned on by default now.")
    metaclass() {}

    /// Override pybind11's default metaclass
    explicit metaclass(handle value) : value(value) { }
};

/// Annotation that marks a class as local to the module:
struct module_local { const bool value; constexpr module_local(bool v = true) : value(v) { } };

/// Annotation to mark enums as an arithmetic type
struct arithmetic { };

/** \rst
    A call policy which places one or more guard variables (``Ts...``) around the function call.

    For example, this definition:

    .. code-block:: cpp

        m.def("foo", foo, py::call_guard<T>());

    is equivalent to the following pseudocode:

    .. code-block:: cpp

        m.def("foo", [](args...) {
            T scope_guard;
            return foo(args...); // forwarded arguments
        });
 \endrst */
template <typename... Ts> struct call_guard;

template <> struct call_guard<> { using type = detail::void_type; };

template <typename T>
struct call_guard<T> {
    static_assert(std::is_default_constructible<T>::value,
                  "The guard type must be default constructible");

    using type = T;
};

template <typename T, typename... Ts>
struct call_guard<T, Ts...> {
    struct type {
        T guard{}; // Compose multiple guard types with left-to-right default-constructor order
        typename call_guard<Ts...>::type next{};
    };
};

/// @} annotations

NAMESPACE_BEGIN(detail)
/* Forward declarations */
enum op_id : int;
enum op_type : int;
struct undefined_t;
template <op_id id, op_type ot, typename L = undefined_t, typename R = undefined_t> struct op_;
inline void keep_alive_impl(size_t Nurse, size_t Patient, function_call &call, handle ret);

/// Internal data structure which holds metadata about a keyword argument
struct argument_record {
    const char *name;  ///< Argument name
    const char *descr; ///< Human-readable version of the argument value
    handle value;      ///< Associated Python object
    bool convert : 1;  ///< True if the argument is allowed to convert when loading
    bool none : 1;     ///< True if None is allowed when loading

    argument_record(const char *name, const char *descr, handle value, bool convert, bool none)
        : name(name), descr(descr), value(value), convert(convert), none(none) { }
};

/// Internal data structure which holds metadata about a bound function (signature, overloads, etc.)
struct function_record {
    function_record()
        : is_constructor(false), is_new_style_constructor(false), is_stateless(false),
          is_operator(false), has_args(false), has_kwargs(false), is_method(false) { }

    /// Function name
    char *name = nullptr; /* why no C++ strings? They generate heavier code.. */

    // User-specified documentation string
    char *doc = nullptr;

    /// Human-readable version of the function signature
    char *signature = nullptr;

    /// List of registered keyword arguments
    std::vector<argument_record> args;

    /// Pointer to lambda function which converts arguments and performs the actual call
    handle (*impl) (function_call &) = nullptr;

    /// Storage for the wrapped function pointer and captured data, if any
    void *data[3] = { };

    /// Pointer to custom destructor for 'data' (if needed)
    void (*free_data) (function_record *ptr) = nullptr;

    /// Return value policy associated with this function
    return_value_policy policy = return_value_policy::automatic;

    /// True if name == '__init__'
    bool is_constructor : 1;

    /// True if this is a new-style `__init__` defined in `detail/init.h`
    bool is_new_style_constructor : 1;

    /// True if this is a stateless function pointer
    bool is_stateless : 1;

    /// True if this is an operator (__add__), etc.
    bool is_operator : 1;

    /// True if the function has a '*args' argument
    bool has_args : 1;

    /// True if the function has a '**kwargs' argument
    bool has_kwargs : 1;

    /// True if this is a method
    bool is_method : 1;

    /// Number of arguments (including py::args and/or py::kwargs, if present)
    std::uint16_t nargs;

    /// Python method object
    PyMethodDef *def = nullptr;

    /// Python handle to the parent scope (a class or a module)
    handle scope;

    /// Python handle to the sibling function representing an overload chain
    handle sibling;

    /// Pointer to next overload
    function_record *next = nullptr;
};

/// Special data structure which (temporarily) holds metadata about a bound class
struct type_record {
    PYBIND11_NOINLINE type_record()
        : multiple_inheritance(false), dynamic_attr(false), buffer_protocol(false), module_local(false) { }

    /// Handle to the parent scope
    handle scope;

    /// Name of the class
    const char *name = nullptr;

    // Pointer to RTTI type_info data structure
    const std::type_info *type = nullptr;

    /// How large is the underlying C++ type?
    size_t type_size = 0;

    /// How large is the type's holder?
    size_t holder_size = 0;

    /// The global operator new can be overridden with a class-specific variant
    void *(*operator_new)(size_t) = ::operator new;

    /// Function pointer to class_<..>::init_instance
    void (*init_instance)(instance *, const void *) = nullptr;

    /// Function pointer to class_<..>::dealloc
    void (*dealloc)(detail::value_and_holder &) = nullptr;

    /// List of base classes of the newly created type
    list bases;

    /// Optional docstring
    const char *doc = nullptr;

    /// Custom metaclass (optional)
    handle metaclass;

    /// Multiple inheritance marker
    bool multiple_inheritance : 1;

    /// Does the class manage a __dict__?
    bool dynamic_attr : 1;

    /// Does the class implement the buffer protocol?
    bool buffer_protocol : 1;

    /// Is the default (unique_ptr) holder type used?
    bool default_holder : 1;

    /// Is the class definition local to the module shared object?
    bool module_local : 1;

    PYBIND11_NOINLINE void add_base(const std::type_info &base, void *(*caster)(void *)) {
        auto base_info = detail::get_type_info(base, false);
        if (!base_info) {
            std::string tname(base.name());
            detail::clean_type_id(tname);
            pybind11_fail("generic_type: type \"" + std::string(name) +
                          "\" referenced unknown base type \"" + tname + "\"");
        }

        if (default_holder != base_info->default_holder) {
            std::string tname(base.name());
            detail::clean_type_id(tname);
            pybind11_fail("generic_type: type \"" + std::string(name) + "\" " +
                    (default_holder ? "does not have" : "has") +
                    " a non-default holder type while its base \"" + tname + "\" " +
                    (base_info->default_holder ? "does not" : "does"));
        }

        bases.append((PyObject *) base_info->type);

        if (base_info->type->tp_dictoffset != 0)
            dynamic_attr = true;

        if (caster)
            base_info->implicit_casts.emplace_back(type, caster);
    }
};

inline function_call::function_call(function_record &f, handle p) :
        func(f), parent(p) {
    args.reserve(f.nargs);
    args_convert.reserve(f.nargs);
}

/// Tag for a new-style `__init__` defined in `detail/init.h`
struct is_new_style_constructor { };

/**
 * Partial template specializations to process custom attributes provided to
 * cpp_function_ and class_. These are either used to initialize the respective
 * fields in the type_record and function_record data structures or executed at
 * runtime to deal with custom call policies (e.g. keep_alive).
 */
template <typename T, typename SFINAE = void> struct process_attribute;

template <typename T> struct process_attribute_default {
    /// Default implementation: do nothing
    static void init(const T &, function_record *) { }
    static void init(const T &, type_record *) { }
    static void precall(function_call &) { }
    static void postcall(function_call &, handle) { }
};

/// Process an attribute specifying the function's name
template <> struct process_attribute<name> : process_attribute_default<name> {
    static void init(const name &n, function_record *r) { r->name = const_cast<char *>(n.value); }
};

/// Process an attribute specifying the function's docstring
template <> struct process_attribute<doc> : process_attribute_default<doc> {
    static void init(const doc &n, function_record *r) { r->doc = const_cast<char *>(n.value); }
};

/// Process an attribute specifying the function's docstring (provided as a C-style string)
template <> struct process_attribute<const char *> : process_attribute_default<const char *> {
    static void init(const char *d, function_record *r) { r->doc = const_cast<char *>(d); }
    static void init(const char *d, type_record *r) { r->doc = const_cast<char *>(d); }
};
template <> struct process_attribute<char *> : process_attribute<const char *> { };

/// Process an attribute indicating the function's return value policy
template <> struct process_attribute<return_value_policy> : process_attribute_default<return_value_policy> {
    static void init(const return_value_policy &p, function_record *r) { r->policy = p; }
};

/// Process an attribute which indicates that this is an overloaded function associated with a given sibling
template <> struct process_attribute<sibling> : process_attribute_default<sibling> {
    static void init(const sibling &s, function_record *r) { r->sibling = s.value; }
};

/// Process an attribute which indicates that this function is a method
template <> struct process_attribute<is_method> : process_attribute_default<is_method> {
    static void init(const is_method &s, function_record *r) { r->is_method = true; r->scope = s.class_; }
};

/// Process an attribute which indicates the parent scope of a method
template <> struct process_attribute<scope> : process_attribute_default<scope> {
    static void init(const scope &s, function_record *r) { r->scope = s.value; }
};

/// Process an attribute which indicates that this function is an operator
template <> struct process_attribute<is_operator> : process_attribute_default<is_operator> {
    static void init(const is_operator &, function_record *r) { r->is_operator = true; }
};

template <> struct process_attribute<is_new_style_constructor> : process_attribute_default<is_new_style_constructor> {
    static void init(const is_new_style_constructor &, function_record *r) { r->is_new_style_constructor = true; }
};

/// Process a keyword argument attribute (*without* a default value)
template <> struct process_attribute<arg> : process_attribute_default<arg> {
    static void init(const arg &a, function_record *r) {
        if (r->is_method && r->args.empty())
            r->args.emplace_back("self", nullptr, handle(), true /*convert*/, false /*none not allowed*/);
        r->args.emplace_back(a.name, nullptr, handle(), !a.flag_noconvert, a.flag_none);
    }
};

/// Process a keyword argument attribute (*with* a default value)
template <> struct process_attribute<arg_v> : process_attribute_default<arg_v> {
    static void init(const arg_v &a, function_record *r) {
        if (r->is_method && r->args.empty())
            r->args.emplace_back("self", nullptr /*descr*/, handle() /*parent*/, true /*convert*/, false /*none not allowed*/);

        if (!a.value) {
#if !defined(NDEBUG)
            std::string descr("'");
            if (a.name) descr += std::string(a.name) + ": ";
            descr += a.type + "'";
            if (r->is_method) {
                if (r->name)
                    descr += " in method '" + (std::string) str(r->scope) + "." + (std::string) r->name + "'";
                else
                    descr += " in method of '" + (std::string) str(r->scope) + "'";
            } else if (r->name) {
                descr += " in function '" + (std::string) r->name + "'";
            }
            pybind11_fail("arg(): could not convert default argument "
                          + descr + " into a Python object (type not registered yet?)");
#else
            pybind11_fail("arg(): could not convert default argument "
                          "into a Python object (type not registered yet?). "
                          "Compile in debug mode for more information.");
#endif
        }
        r->args.emplace_back(a.name, a.descr, a.value.inc_ref(), !a.flag_noconvert, a.flag_none);
    }
};

/// Process a parent class attribute.  Single inheritance only (class_ itself already guarantees that)
template <typename T>
struct process_attribute<T, enable_if_t<is_pyobject<T>::value>> : process_attribute_default<handle> {
    static void init(const handle &h, type_record *r) { r->bases.append(h); }
};

/// Process a parent class attribute (deprecated, does not support multiple inheritance)
template <typename T>
struct process_attribute<base<T>> : process_attribute_default<base<T>> {
    static void init(const base<T> &, type_record *r) { r->add_base(typeid(T), nullptr); }
};

/// Process a multiple inheritance attribute
template <>
struct process_attribute<multiple_inheritance> : process_attribute_default<multiple_inheritance> {
    static void init(const multiple_inheritance &, type_record *r) { r->multiple_inheritance = true; }
};

template <>
struct process_attribute<dynamic_attr> : process_attribute_default<dynamic_attr> {
    static void init(const dynamic_attr &, type_record *r) { r->dynamic_attr = true; }
};

template <>
struct process_attribute<buffer_protocol> : process_attribute_default<buffer_protocol> {
    static void init(const buffer_protocol &, type_record *r) { r->buffer_protocol = true; }
};

template <>
struct process_attribute<metaclass> : process_attribute_default<metaclass> {
    static void init(const metaclass &m, type_record *r) { r->metaclass = m.value; }
};

template <>
struct process_attribute<module_local> : process_attribute_default<module_local> {
    static void init(const module_local &l, type_record *r) { r->module_local = l.value; }
};

/// Process an 'arithmetic' attribute for enums (does nothing here)
template <>
struct process_attribute<arithmetic> : process_attribute_default<arithmetic> {};

template <typename... Ts>
struct process_attribute<call_guard<Ts...>> : process_attribute_default<call_guard<Ts...>> { };

/**
 * Process a keep_alive call policy -- invokes keep_alive_impl during the
 * pre-call handler if both Nurse, Patient != 0 and use the post-call handler
 * otherwise
 */
template <size_t Nurse, size_t Patient> struct process_attribute<keep_alive<Nurse, Patient>> : public process_attribute_default<keep_alive<Nurse, Patient>> {
    template <size_t N = Nurse, size_t P = Patient, enable_if_t<N != 0 && P != 0, int> = 0>
    static void precall(function_call &call) { keep_alive_impl(Nurse, Patient, call, handle()); }
    template <size_t N = Nurse, size_t P = Patient, enable_if_t<N != 0 && P != 0, int> = 0>
    static void postcall(function_call &, handle) { }
    template <size_t N = Nurse, size_t P = Patient, enable_if_t<N == 0 || P == 0, int> = 0>
    static void precall(function_call &) { }
    template <size_t N = Nurse, size_t P = Patient, enable_if_t<N == 0 || P == 0, int> = 0>
    static void postcall(function_call &call, handle ret) { keep_alive_impl(Nurse, Patient, call, ret); }
};

/// Recursively iterate over variadic template arguments
template <typename... Args> struct process_attributes {
    static void init(const Args&... args, function_record *r) {
        int unused[] = { 0, (process_attribute<typename std::decay<Args>::type>::init(args, r), 0) ... };
        ignore_unused(unused);
    }
    static void init(const Args&... args, type_record *r) {
        int unused[] = { 0, (process_attribute<typename std::decay<Args>::type>::init(args, r), 0) ... };
        ignore_unused(unused);
    }
    static void precall(function_call &call) {
        int unused[] = { 0, (process_attribute<typename std::decay<Args>::type>::precall(call), 0) ... };
        ignore_unused(unused);
    }
    static void postcall(function_call &call, handle fn_ret) {
        int unused[] = { 0, (process_attribute<typename std::decay<Args>::type>::postcall(call, fn_ret), 0) ... };
        ignore_unused(unused);
    }
};

template <typename T>
using is_call_guard = is_instantiation<call_guard, T>;

/// Extract the ``type`` from the first `call_guard` in `Extras...` (or `void_type` if none found)
template <typename... Extra>
using extract_guard_t = typename exactly_one_t<is_call_guard, call_guard<>, Extra...>::type;

/// Check the number of named arguments at compile time
template <typename... Extra,
          size_t named = constexpr_sum(std::is_base_of<arg, Extra>::value...),
          size_t self  = constexpr_sum(std::is_same<is_method, Extra>::value...)>
constexpr bool expected_num_args(size_t nargs, bool has_args, bool has_kwargs) {
    return named == 0 || (self + named + has_args + has_kwargs) == nargs;
}

NAMESPACE_END(detail)
NAMESPACE_END(PYBIND11_NAMESPACE)

{'repo_name': 'luigifreda/pyslam', 'stars': '652', 'repo_language': 'Python', 'file_name': 'H_1_3', 'mime_type': 'text/plain', 'hash': -5532664656741957058, 'source_dataset': 'data'}


/*
 Copyright 1995-2015 Esri

   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.

 For additional information, contact:
 Environmental Systems Research Institute, Inc.
 Attn: Contracts Dept
 380 New York Street
 Redlands, California, USA 92373

 email: contracts@esri.com
 */
package com.esri.core.geometry;

/**
 * Generalizes geometries using Douglas-Peucker algorithm.
 */
public abstract class OperatorGeneralize extends Operator {
  @Override
  public Type getType() {
    return Type.Generalize;
  }

  /**
   * Performs the Generalize operation on a geometry set. Point and
   * multipoint geometries are left unchanged. An envelope is converted to a
   * polygon.
   *
   */
  public abstract GeometryCursor execute(GeometryCursor geoms,
          double maxDeviation, boolean bRemoveDegenerateParts,
          ProgressTracker progressTracker);

  /**
   * Performs the Generalize operation on a single geometry. Point and
   * multipoint geometries are left unchanged. An envelope is converted to a
   * polygon.
   */
  public abstract Geometry execute(Geometry geom, double maxDeviation,
          boolean bRemoveDegenerateParts, ProgressTracker progressTracker);

  public static OperatorGeneralize local() {
    return (OperatorGeneralize) OperatorFactoryLocal.getInstance().getOperator(Type.Generalize);
  }

}

{'repo_name': 'Esri/geometry-api-java', 'stars': '538', 'repo_language': 'Java', 'file_name': 'TestWkbImportOnPostgresST.java', 'mime_type': 'text/x-java', 'hash': -3041244467627877989, 'source_dataset': 'data'}