<commit_before>// ***************************************************************************
//
//   Generated automatically by genwrapper.
//   Please DO NOT EDIT this file!
//
// ***************************************************************************

#include <osgIntrospection/ReflectionMacros>
#include <osgIntrospection/TypedMethodInfo>
#include <osgIntrospection/StaticMethodInfo>
#include <osgIntrospection/Attributes>

#include <osg/Camera>
#include <osg/FrameStamp>
#include <osg/GraphicsThread>
#include <osg/Node>
#include <osg/Timer>
#include <osgViewer/Viewer>

// Must undefine IN and OUT macros defined in Windows headers
#ifdef IN
#undef IN
#endif
#ifdef OUT
#undef OUT
#endif

TYPE_NAME_ALIAS(std::vector< osg::GraphicsContext * >, osgViewer::Viewer::Contexts);

TYPE_NAME_ALIAS(std::vector< osgViewer::GraphicsWindow * >, osgViewer::Viewer::Windows);

TYPE_NAME_ALIAS(std::vector< osg::Camera * >, osgViewer::Viewer::Cameras);

BEGIN_ENUM_REFLECTOR(osgViewer::Viewer::ThreadingModel)
	I_EnumLabel(osgViewer::Viewer::SingleThreaded);
	I_EnumLabel(osgViewer::Viewer::ThreadPerContext);
	I_EnumLabel(osgViewer::Viewer::ThreadPerCamera);
END_REFLECTOR

BEGIN_ENUM_REFLECTOR(osgViewer::Viewer::BarrierPosition)
	I_EnumLabel(osgViewer::Viewer::BeforeSwapBuffers);
	I_EnumLabel(osgViewer::Viewer::AfterSwapBuffers);
END_REFLECTOR

BEGIN_OBJECT_REFLECTOR(osgViewer::Viewer)
	I_BaseType(osgViewer::View);
	I_Constructor0(____Viewer,
	               "",
	               "");
	I_Method0(bool, isRealized,
	          __bool__isRealized,
	          "Get whether at least of one of this viewers windows are realized. ",
	          "");
	I_Method0(void, realize,
	          __void__realize,
	          "set up windows and associated threads. ",
	          "");
	I_Method1(void, setDone, IN, bool, done,
	          __void__setDone__bool,
	          "",
	          "");
	I_Method0(bool, done,
	          __bool__done,
	          "",
	          "");
	I_Method1(void, setStartTick, IN, osg::Timer_t, tick,
	          __void__setStartTick__osg_Timer_t,
	          "",
	          "");
	I_Method0(osg::Timer_t, getStartTick,
	          __osg_Timer_t__getStartTick,
	          "",
	          "");
	I_MethodWithDefaults1(void, setReferenceTime, IN, double, time, 0.0,
	                      __void__setReferenceTime__double,
	                      "",
	                      "");
	I_Method1(void, setFrameStamp, IN, osg::FrameStamp *, frameStamp,
	          __void__setFrameStamp__osg_FrameStamp_P1,
	          "",
	          "");
	I_Method0(osg::FrameStamp *, getFrameStamp,
	          __osg_FrameStamp_P1__getFrameStamp,
	          "",
	          "");
	I_Method0(const osg::FrameStamp *, getFrameStamp,
	          __C5_osg_FrameStamp_P1__getFrameStamp,
	          "",
	          "");
	I_Method1(void, setSceneData, IN, osg::Node *, node,
	          __void__setSceneData__osg_Node_P1,
	          "",
	          "");
	I_Method1(void, setThreadingModel, IN, osgViewer::Viewer::ThreadingModel, threadingModel,
	          __void__setThreadingModel__ThreadingModel,
	          "Set the threading model the rendering traversals will use. ",
	          "");
	I_Method0(osgViewer::Viewer::ThreadingModel, getThreadingModel,
	          __ThreadingModel__getThreadingModel,
	          "Get the threading model the rendering traversals will use. ",
	          "");
	I_Method1(void, setUseMainThreadForRenderingTraversals, IN, bool, flag,
	          __void__setUseMainThreadForRenderingTraversals__bool,
	          "Set whether the main thread, calling frame(), should be used for the rendering traversals. ",
	          "");
	I_Method0(bool, getUseMainThreadForRenderingTraversals,
	          __bool__getUseMainThreadForRenderingTraversals,
	          "Get whether the main thread, calling frame(), should be used for the rendering traversals. ",
	          "");
	I_Method1(void, setEndBarrierPosition, IN, osgViewer::Viewer::BarrierPosition, bp,
	          __void__setEndBarrierPosition__BarrierPosition,
	          "Set the position of the end barrier. ",
	          "AfterSwapBuffers will may result is slightly higher framerates, by may lead to inconcistent swapping between different windows. BeforeSwapBuffers may lead to slightly lower framerate, but improve consistency in timing of swap buffers, especially important if you are likely to consistently break frame. ");
	I_Method0(osgViewer::Viewer::BarrierPosition, getEndBarrierPosition,
	          __BarrierPosition__getEndBarrierPosition,
	          "Get the end barrier position. ",
	          "");
	I_Method1(void, setKeyEventSetsDone, IN, int, key,
	          __void__setKeyEventSetsDone__int,
	          "Set the key event that the viewer checks on each frame to see if the viewer's done flag should be set to signal end of viewers main loop. ",
	          "Default value is Escape (osgGA::GUIEVentAdapter::KEY_Escape). Setting to 0 switches off the feature. ");
	I_Method0(int, getKeyEventSetsDone,
	          __int__getKeyEventSetsDone,
	          "get the key event that the viewer checks on each frame to see if the viewer's done flag. ",
	          "");
	I_Method1(void, setQuitEventSetsDone, IN, bool, flag,
	          __void__setQuitEventSetsDone__bool,
	          "if the flag is true, the viewer set its done flag when a QUIT_APPLICATION is received, false disables this feature ",
	          "");
	I_Method0(bool, getQuitEventSetsDone,
	          __bool__getQuitEventSetsDone,
	          "",
	          "true if the viewer respond to the QUIT_APPLICATION-event  ");
	I_Method0(int, run,
	          __int__run,
	          "Execute a main frame loop. ",
	          "Equivialant to while (!viewer.done()) viewer.frame(); Also calls realize() if the viewer is not already realized, and installs trackball manipulator if one is not already assigned.");
	I_MethodWithDefaults1(void, frame, IN, double, simulationTime, USE_REFERENCE_TIME,
	                      __void__frame__double,
	                      "Render a complete new frame. ",
	                      "Calls advance(), eventTraversal(), updateTraversal(), renderingTraversals(). ");
	I_MethodWithDefaults1(void, advance, IN, double, simulationTime, USE_REFERENCE_TIME,
	                      __void__advance__double,
	                      "",
	                      "");
	I_Method0(void, eventTraversal,
	          __void__eventTraversal,
	          "",
	          "");
	I_Method0(void, updateTraversal,
	          __void__updateTraversal,
	          "",
	          "");
	I_Method0(void, renderingTraversals,
	          __void__renderingTraversals,
	          "",
	          "");
	I_Method1(void, setCameraWithFocus, IN, osg::Camera *, camera,
	          __void__setCameraWithFocus__osg_Camera_P1,
	          "",
	          "");
	I_Method0(osg::Camera *, getCameraWithFocus,
	          __osg_Camera_P1__getCameraWithFocus,
	          "",
	          "");
	I_Method0(const osg::Camera *, getCameraWithFocus,
	          __C5_osg_Camera_P1__getCameraWithFocus,
	          "",
	          "");
	I_MethodWithDefaults2(void, getContexts, IN, osgViewer::Viewer::Contexts &, contexts, , IN, bool, onlyValid, true,
	                      __void__getContexts__Contexts_R1__bool,
	                      "",
	                      "");
	I_MethodWithDefaults2(void, getWindows, IN, osgViewer::Viewer::Windows &, windows, , IN, bool, onlyValid, true,
	                      __void__getWindows__Windows_R1__bool,
	                      "",
	                      "");
	I_MethodWithDefaults2(void, getCameras, IN, osgViewer::Viewer::Cameras &, cameras, , IN, bool, onlyActive, true,
	                      __void__getCameras__Cameras_R1__bool,
	                      "",
	                      "");
	I_Method1(void, setRealizeOperation, IN, osg::Operation *, op,
	          __void__setRealizeOperation__osg_Operation_P1,
	          "Set the graphics operation to call on realization of the viewers graphics windows. ",
	          "");
	I_Method0(osg::Operation *, getRealizeOperation,
	          __osg_Operation_P1__getRealizeOperation,
	          "Get the graphics operation to call on realization of the viewers graphics windows. ",
	          "");
	I_Method0(void, stopThreading,
	          __void__stopThreading,
	          "Stop any threads begin run by viewer. ",
	          "");
	I_Method0(void, startThreading,
	          __void__startThreading,
	          "Start any threads required by the viewer, as per viewers ThreadingModel. ",
	          "");
	I_Method0(void, setUpRenderingSupport,
	          __void__setUpRenderingSupport,
	          "Set up the Operations to render the various viewer cameras on the viewers graphics windows. ",
	          "");
	I_SimpleProperty(osg::Camera *, CameraWithFocus,
	                 __osg_Camera_P1__getCameraWithFocus,
	                 __void__setCameraWithFocus__osg_Camera_P1);
	I_SimpleProperty(bool, Done,
	                 0,
	                 __void__setDone__bool);
	I_SimpleProperty(osgViewer::Viewer::BarrierPosition, EndBarrierPosition,
	                 __BarrierPosition__getEndBarrierPosition,
	                 __void__setEndBarrierPosition__BarrierPosition);
	I_SimpleProperty(osg::FrameStamp *, FrameStamp,
	                 __osg_FrameStamp_P1__getFrameStamp,
	                 __void__setFrameStamp__osg_FrameStamp_P1);
	I_SimpleProperty(int, KeyEventSetsDone,
	                 __int__getKeyEventSetsDone,
	                 __void__setKeyEventSetsDone__int);
	I_SimpleProperty(bool, QuitEventSetsDone,
	                 __bool__getQuitEventSetsDone,
	                 __void__setQuitEventSetsDone__bool);
	I_SimpleProperty(osg::Operation *, RealizeOperation,
	                 __osg_Operation_P1__getRealizeOperation,
	                 __void__setRealizeOperation__osg_Operation_P1);
	I_SimpleProperty(double, ReferenceTime,
	                 0,
	                 __void__setReferenceTime__double);
	I_SimpleProperty(osg::Node *, SceneData,
	                 0,
	                 __void__setSceneData__osg_Node_P1);
	I_SimpleProperty(osg::Timer_t, StartTick,
	                 __osg_Timer_t__getStartTick,
	                 __void__setStartTick__osg_Timer_t);
	I_SimpleProperty(osgViewer::Viewer::ThreadingModel, ThreadingModel,
	                 __ThreadingModel__getThreadingModel,
	                 __void__setThreadingModel__ThreadingModel);
	I_SimpleProperty(bool, UseMainThreadForRenderingTraversals,
	                 __bool__getUseMainThreadForRenderingTraversals,
	                 __void__setUseMainThreadForRenderingTraversals__bool);
END_REFLECTOR

STD_VECTOR_REFLECTOR(std::vector< osg::Camera * >);

<commit_msg>Updated wrappers<commit_after>// ***************************************************************************
//
//   Generated automatically by genwrapper.
//   Please DO NOT EDIT this file!
//
// ***************************************************************************

#include <osgIntrospection/ReflectionMacros>
#include <osgIntrospection/TypedMethodInfo>
#include <osgIntrospection/StaticMethodInfo>
#include <osgIntrospection/Attributes>

#include <osg/Camera>
#include <osg/FrameStamp>
#include <osg/GraphicsThread>
#include <osg/Node>
#include <osg/Timer>
#include <osgViewer/Viewer>

// Must undefine IN and OUT macros defined in Windows headers
#ifdef IN
#undef IN
#endif
#ifdef OUT
#undef OUT
#endif

TYPE_NAME_ALIAS(std::vector< osg::GraphicsContext * >, osgViewer::Viewer::Contexts);

TYPE_NAME_ALIAS(std::vector< osgViewer::GraphicsWindow * >, osgViewer::Viewer::Windows);

TYPE_NAME_ALIAS(std::vector< osg::Camera * >, osgViewer::Viewer::Cameras);

TYPE_NAME_ALIAS(std::vector< OpenThreads::Thread * >, osgViewer::Viewer::Threads);

TYPE_NAME_ALIAS(std::vector< osg::OperationsThread * >, osgViewer::Viewer::OperationsThreads);

BEGIN_ENUM_REFLECTOR(osgViewer::Viewer::ThreadingModel)
	I_EnumLabel(osgViewer::Viewer::SingleThreaded);
	I_EnumLabel(osgViewer::Viewer::CullDrawThreadPerContext);
	I_EnumLabel(osgViewer::Viewer::DrawThreadPerContext);
	I_EnumLabel(osgViewer::Viewer::CullThreadPerCameraDrawThreadPerContext);
	I_EnumLabel(osgViewer::Viewer::AutomaticSelection);
END_REFLECTOR

BEGIN_ENUM_REFLECTOR(osgViewer::Viewer::BarrierPosition)
	I_EnumLabel(osgViewer::Viewer::BeforeSwapBuffers);
	I_EnumLabel(osgViewer::Viewer::AfterSwapBuffers);
END_REFLECTOR

BEGIN_OBJECT_REFLECTOR(osgViewer::Viewer)
	I_BaseType(osgViewer::View);
	I_Constructor0(____Viewer,
	               "",
	               "");
	I_Method0(bool, isRealized,
	          __bool__isRealized,
	          "Get whether at least of one of this viewers windows are realized. ",
	          "");
	I_Method0(void, realize,
	          __void__realize,
	          "set up windows and associated threads. ",
	          "");
	I_Method1(void, setDone, IN, bool, done,
	          __void__setDone__bool,
	          "",
	          "");
	I_Method0(bool, done,
	          __bool__done,
	          "",
	          "");
	I_Method1(void, setStartTick, IN, osg::Timer_t, tick,
	          __void__setStartTick__osg_Timer_t,
	          "",
	          "");
	I_Method0(osg::Timer_t, getStartTick,
	          __osg_Timer_t__getStartTick,
	          "",
	          "");
	I_MethodWithDefaults1(void, setReferenceTime, IN, double, time, 0.0,
	                      __void__setReferenceTime__double,
	                      "",
	                      "");
	I_Method1(void, setFrameStamp, IN, osg::FrameStamp *, frameStamp,
	          __void__setFrameStamp__osg_FrameStamp_P1,
	          "",
	          "");
	I_Method0(osg::FrameStamp *, getFrameStamp,
	          __osg_FrameStamp_P1__getFrameStamp,
	          "",
	          "");
	I_Method0(const osg::FrameStamp *, getFrameStamp,
	          __C5_osg_FrameStamp_P1__getFrameStamp,
	          "",
	          "");
	I_Method1(void, setSceneData, IN, osg::Node *, node,
	          __void__setSceneData__osg_Node_P1,
	          "",
	          "");
	I_Method1(void, setThreadingModel, IN, osgViewer::Viewer::ThreadingModel, threadingModel,
	          __void__setThreadingModel__ThreadingModel,
	          "Set the threading model the rendering traversals will use. ",
	          "");
	I_Method0(osgViewer::Viewer::ThreadingModel, getThreadingModel,
	          __ThreadingModel__getThreadingModel,
	          "Get the threading model the rendering traversals will use. ",
	          "");
	I_Method1(void, setUseMainThreadForRenderingTraversals, IN, bool, flag,
	          __void__setUseMainThreadForRenderingTraversals__bool,
	          "Set whether the main thread, calling frame(), should be used for the rendering traversals. ",
	          "");
	I_Method0(bool, getUseMainThreadForRenderingTraversals,
	          __bool__getUseMainThreadForRenderingTraversals,
	          "Get whether the main thread, calling frame(), should be used for the rendering traversals. ",
	          "");
	I_Method0(osgViewer::Viewer::ThreadingModel, suggestBestThreadingModel,
	          __ThreadingModel__suggestBestThreadingModel,
	          "Let the viewer suggest the best threading model for the viewers camera/window setup and the hardware available. ",
	          "");
	I_Method1(void, setEndBarrierPosition, IN, osgViewer::Viewer::BarrierPosition, bp,
	          __void__setEndBarrierPosition__BarrierPosition,
	          "Set the position of the end barrier. ",
	          "AfterSwapBuffers will may result is slightly higher framerates, by may lead to inconcistent swapping between different windows. BeforeSwapBuffers may lead to slightly lower framerate, but improve consistency in timing of swap buffers, especially important if you are likely to consistently break frame. ");
	I_Method0(osgViewer::Viewer::BarrierPosition, getEndBarrierPosition,
	          __BarrierPosition__getEndBarrierPosition,
	          "Get the end barrier position. ",
	          "");
	I_Method1(void, setKeyEventSetsDone, IN, int, key,
	          __void__setKeyEventSetsDone__int,
	          "Set the key event that the viewer checks on each frame to see if the viewer's done flag should be set to signal end of viewers main loop. ",
	          "Default value is Escape (osgGA::GUIEVentAdapter::KEY_Escape). Setting to 0 switches off the feature. ");
	I_Method0(int, getKeyEventSetsDone,
	          __int__getKeyEventSetsDone,
	          "get the key event that the viewer checks on each frame to see if the viewer's done flag. ",
	          "");
	I_Method1(void, setQuitEventSetsDone, IN, bool, flag,
	          __void__setQuitEventSetsDone__bool,
	          "if the flag is true, the viewer set its done flag when a QUIT_APPLICATION is received, false disables this feature ",
	          "");
	I_Method0(bool, getQuitEventSetsDone,
	          __bool__getQuitEventSetsDone,
	          "",
	          "true if the viewer respond to the QUIT_APPLICATION-event  ");
	I_Method0(int, run,
	          __int__run,
	          "Execute a main frame loop. ",
	          "Equivialant to while (!viewer.done()) viewer.frame(); Also calls realize() if the viewer is not already realized, and installs trackball manipulator if one is not already assigned.");
	I_MethodWithDefaults1(void, frame, IN, double, simulationTime, USE_REFERENCE_TIME,
	                      __void__frame__double,
	                      "Render a complete new frame. ",
	                      "Calls advance(), eventTraversal(), updateTraversal(), renderingTraversals(). ");
	I_MethodWithDefaults1(void, advance, IN, double, simulationTime, USE_REFERENCE_TIME,
	                      __void__advance__double,
	                      "",
	                      "");
	I_Method0(void, eventTraversal,
	          __void__eventTraversal,
	          "",
	          "");
	I_Method0(void, updateTraversal,
	          __void__updateTraversal,
	          "",
	          "");
	I_Method0(void, renderingTraversals,
	          __void__renderingTraversals,
	          "",
	          "");
	I_Method1(void, setCameraWithFocus, IN, osg::Camera *, camera,
	          __void__setCameraWithFocus__osg_Camera_P1,
	          "",
	          "");
	I_Method0(osg::Camera *, getCameraWithFocus,
	          __osg_Camera_P1__getCameraWithFocus,
	          "",
	          "");
	I_Method0(const osg::Camera *, getCameraWithFocus,
	          __C5_osg_Camera_P1__getCameraWithFocus,
	          "",
	          "");
	I_MethodWithDefaults2(void, getContexts, IN, osgViewer::Viewer::Contexts &, contexts, , IN, bool, onlyValid, true,
	                      __void__getContexts__Contexts_R1__bool,
	                      "",
	                      "");
	I_MethodWithDefaults2(void, getWindows, IN, osgViewer::Viewer::Windows &, windows, , IN, bool, onlyValid, true,
	                      __void__getWindows__Windows_R1__bool,
	                      "",
	                      "");
	I_MethodWithDefaults2(void, getCameras, IN, osgViewer::Viewer::Cameras &, cameras, , IN, bool, onlyActive, true,
	                      __void__getCameras__Cameras_R1__bool,
	                      "",
	                      "");
	I_MethodWithDefaults2(void, getAllThreads, IN, osgViewer::Viewer::Threads &, threads, , IN, bool, onlyActive, true,
	                      __void__getAllThreads__Threads_R1__bool,
	                      "",
	                      "");
	I_MethodWithDefaults2(void, getOperationsThreads, IN, osgViewer::Viewer::OperationsThreads &, threads, , IN, bool, onlyActive, true,
	                      __void__getOperationsThreads__OperationsThreads_R1__bool,
	                      "",
	                      "");
	I_Method1(void, setRealizeOperation, IN, osg::Operation *, op,
	          __void__setRealizeOperation__osg_Operation_P1,
	          "Set the graphics operation to call on realization of the viewers graphics windows. ",
	          "");
	I_Method0(osg::Operation *, getRealizeOperation,
	          __osg_Operation_P1__getRealizeOperation,
	          "Get the graphics operation to call on realization of the viewers graphics windows. ",
	          "");
	I_Method0(void, stopThreading,
	          __void__stopThreading,
	          "Stop any threads begin run by viewer. ",
	          "");
	I_Method0(void, startThreading,
	          __void__startThreading,
	          "Start any threads required by the viewer, as per viewers ThreadingModel. ",
	          "");
	I_Method0(void, setUpRenderingSupport,
	          __void__setUpRenderingSupport,
	          "Set up the Operations to render the various viewer cameras on the viewers graphics windows. ",
	          "");
	I_SimpleProperty(osg::Camera *, CameraWithFocus,
	                 __osg_Camera_P1__getCameraWithFocus,
	                 __void__setCameraWithFocus__osg_Camera_P1);
	I_SimpleProperty(bool, Done,
	                 0,
	                 __void__setDone__bool);
	I_SimpleProperty(osgViewer::Viewer::BarrierPosition, EndBarrierPosition,
	                 __BarrierPosition__getEndBarrierPosition,
	                 __void__setEndBarrierPosition__BarrierPosition);
	I_SimpleProperty(osg::FrameStamp *, FrameStamp,
	                 __osg_FrameStamp_P1__getFrameStamp,
	                 __void__setFrameStamp__osg_FrameStamp_P1);
	I_SimpleProperty(int, KeyEventSetsDone,
	                 __int__getKeyEventSetsDone,
	                 __void__setKeyEventSetsDone__int);
	I_SimpleProperty(bool, QuitEventSetsDone,
	                 __bool__getQuitEventSetsDone,
	                 __void__setQuitEventSetsDone__bool);
	I_SimpleProperty(osg::Operation *, RealizeOperation,
	                 __osg_Operation_P1__getRealizeOperation,
	                 __void__setRealizeOperation__osg_Operation_P1);
	I_SimpleProperty(double, ReferenceTime,
	                 0,
	                 __void__setReferenceTime__double);
	I_SimpleProperty(osg::Node *, SceneData,
	                 0,
	                 __void__setSceneData__osg_Node_P1);
	I_SimpleProperty(osg::Timer_t, StartTick,
	                 __osg_Timer_t__getStartTick,
	                 __void__setStartTick__osg_Timer_t);
	I_SimpleProperty(osgViewer::Viewer::ThreadingModel, ThreadingModel,
	                 __ThreadingModel__getThreadingModel,
	                 __void__setThreadingModel__ThreadingModel);
	I_SimpleProperty(bool, UseMainThreadForRenderingTraversals,
	                 __bool__getUseMainThreadForRenderingTraversals,
	                 __void__setUseMainThreadForRenderingTraversals__bool);
END_REFLECTOR

STD_VECTOR_REFLECTOR(std::vector< OpenThreads::Thread * >);

STD_VECTOR_REFLECTOR(std::vector< osg::Camera * >);

STD_VECTOR_REFLECTOR(std::vector< osg::OperationsThread * >);

<|endoftext|>


<commit_before>#include "xdr++.h"

#include <sstream>

#include <cstdio>
#include <arpa/inet.h>

bool xdr(XDR* xdrs, std::string& s)
{
	char* p;
	int32_t size;
	char buf[BUFSIZ];
	std::ostringstream ss;

	switch (xdrs->x_op) {
	case XDR_ENCODE:
		p = const_cast<char*>(s.c_str());
		size = s.length();
		return	   xdrs->x_ops->x_putint32(xdrs, &size)
			&& xdrs->x_ops->x_putbytes(xdrs, s.c_str(), size);

	case XDR_DECODE:
		if (!xdrs->x_ops->x_getint32(xdrs, &size))
			return false;
		p = buf;
		while (size) {
			uint32_t sz = size > sizeof (buf) ? sizeof (buf) : size;
			if (!xdrs->x_ops->x_getbytes(xdrs, p, sz))
				return false;
			ss.write(p, sz);
			size -= sz;
		}
		s = ss.str();
		return true;

	default:
		break;
	}

	return false;
}

namespace {

	bool_t xdr_getlong_callback(XDR* xdrs, long* lp)
	{
		int32_t v;
		bool ret = static_cast<XDR_Base*>(xdrs)->get(v);
		if (ret)
			*lp = v;
		return ret;
	}

	bool_t xdr_putlong_callback(XDR* xdrs, const long* lp)
	{
		int32_t v = *lp;
		return static_cast<XDR_Base*>(xdrs)->put(v);
	}

	bool_t xdr_getbytes_callback(XDR* xdrs, caddr_t addr, u_int len)
	{
		return static_cast<XDR_Base*>(xdrs)->get(addr, len);
	}

	bool_t xdr_putbytes_callback(XDR* xdrs, const char* addr, u_int len)
	{
		return static_cast<XDR_Base*>(xdrs)->put(addr, len);
	}

	u_int xdr_getpostn_callback(const XDR* xdrs)
	{
		return static_cast<const XDR_Base*>(xdrs)->get_position();
	}

	bool_t xdr_setpostn_callback(XDR* xdrs, u_int pos)
	{
		return static_cast<XDR_Base*>(xdrs)->set_position(pos);
	}

	int32_t* xdr_inline_callback(XDR* xdrs, u_int len)
	{
		return reinterpret_cast<int32_t*>(static_cast<XDR_Base*>(xdrs)->get_inline(len));
	}

	void xdr_destroy_callback(XDR* xdrs)
	{
	}

	bool_t xdr_getint32_callback(XDR* xdrs, int32_t* ip)
	{
		return static_cast<XDR_Base*>(xdrs)->get(*ip);
	}

	bool_t xdr_putint32_callback(XDR* xdrs, const int32_t* ip)
	{
		return static_cast<XDR_Base*>(xdrs)->put(*ip);
	}

	struct XDR::xdr_ops xdr_base_ops = {
		&xdr_getlong_callback,
		&xdr_putlong_callback,
		&xdr_getbytes_callback,
		&xdr_putbytes_callback,
		&xdr_getpostn_callback,
		&xdr_setpostn_callback,
		&xdr_inline_callback,
		&xdr_destroy_callback,
		&xdr_getint32_callback,
		&xdr_putint32_callback
	};

}

XDR_Base::
XDR_Base(xdr_op op)
{
	x_op = op;
	x_ops = &xdr_base_ops;
	x_public = 0;
	x_private = 0;
	x_base = 0;
	x_handy = 0;
}

bool XDR_Base::
get(int32_t& v)
{
	int32_t tmp;
	bool ret = get(reinterpret_cast<char*>(&tmp), sizeof (tmp));
	if (ret)
		v = htonl(tmp);
	return ret;
}

bool XDR_Base::
put(int32_t v)
{
	v = htonl(v);
	return put(reinterpret_cast<char*>(&v), sizeof (v));
}
<commit_msg>Pad string output to word boundary.<commit_after>#include "xdr++.h"

#include <sstream>

#include <cstdio>
#include <arpa/inet.h>

bool xdr(XDR* xdrs, std::string& s)
{
	char* p;
	int32_t size, pad;
	char buf[BUFSIZ], zeros[] = { 0, 0, 0, 0 };
	std::ostringstream ss;

	switch (xdrs->x_op) {
	case XDR_ENCODE:
		p = const_cast<char*>(s.c_str());
		size = s.length();
		pad = (size | 0x03) - size + 1;
		return	   xdrs->x_ops->x_putint32(xdrs, &size)
			&& xdrs->x_ops->x_putbytes(xdrs, s.c_str(), size)
			&& xdrs->x_ops->x_putbytes(xdrs, zeros, pad);

	case XDR_DECODE:
		if (!xdrs->x_ops->x_getint32(xdrs, &size))
			return false;
		pad = (size | 0x03) - size + 1;
		p = buf;
		while (size) {
			uint32_t sz = size > sizeof (buf) ? sizeof (buf) : size;
			if (!xdrs->x_ops->x_getbytes(xdrs, p, sz))
				return false;
			ss.write(p, sz);
			size -= sz;
		}
		if (!xdrs->x_ops->x_getbytes(xdrs, p, pad))
			return false;
		s = ss.str();
		return true;

	default:
		break;
	}

	return false;
}

namespace {

	bool_t xdr_getlong_callback(XDR* xdrs, long* lp)
	{
		int32_t v;
		bool ret = static_cast<XDR_Base*>(xdrs)->get(v);
		if (ret)
			*lp = v;
		return ret;
	}

	bool_t xdr_putlong_callback(XDR* xdrs, const long* lp)
	{
		int32_t v = *lp;
		return static_cast<XDR_Base*>(xdrs)->put(v);
	}

	bool_t xdr_getbytes_callback(XDR* xdrs, caddr_t addr, u_int len)
	{
		return static_cast<XDR_Base*>(xdrs)->get(addr, len);
	}

	bool_t xdr_putbytes_callback(XDR* xdrs, const char* addr, u_int len)
	{
		return static_cast<XDR_Base*>(xdrs)->put(addr, len);
	}

	u_int xdr_getpostn_callback(const XDR* xdrs)
	{
		return static_cast<const XDR_Base*>(xdrs)->get_position();
	}

	bool_t xdr_setpostn_callback(XDR* xdrs, u_int pos)
	{
		return static_cast<XDR_Base*>(xdrs)->set_position(pos);
	}

	int32_t* xdr_inline_callback(XDR* xdrs, u_int len)
	{
		return reinterpret_cast<int32_t*>(static_cast<XDR_Base*>(xdrs)->get_inline(len));
	}

	void xdr_destroy_callback(XDR* xdrs)
	{
	}

	bool_t xdr_getint32_callback(XDR* xdrs, int32_t* ip)
	{
		return static_cast<XDR_Base*>(xdrs)->get(*ip);
	}

	bool_t xdr_putint32_callback(XDR* xdrs, const int32_t* ip)
	{
		return static_cast<XDR_Base*>(xdrs)->put(*ip);
	}

	struct XDR::xdr_ops xdr_base_ops = {
		&xdr_getlong_callback,
		&xdr_putlong_callback,
		&xdr_getbytes_callback,
		&xdr_putbytes_callback,
		&xdr_getpostn_callback,
		&xdr_setpostn_callback,
		&xdr_inline_callback,
		&xdr_destroy_callback,
		&xdr_getint32_callback,
		&xdr_putint32_callback
	};

}

XDR_Base::
XDR_Base(xdr_op op)
{
	x_op = op;
	x_ops = &xdr_base_ops;
	x_public = 0;
	x_private = 0;
	x_base = 0;
	x_handy = 0;
}

bool XDR_Base::
get(int32_t& v)
{
	int32_t tmp;
	bool ret = get(reinterpret_cast<char*>(&tmp), sizeof (tmp));
	if (ret)
		v = htonl(tmp);
	return ret;
}

bool XDR_Base::
put(int32_t v)
{
	v = htonl(v);
	return put(reinterpret_cast<char*>(&v), sizeof (v));
}
<|endoftext|>


<commit_before>#pragma once

#include <cstdint>
#include <string>
#include <type_traits>
#include <vector>
#include <zmq.h>
#include "helpers.hpp"

namespace boost {
namespace asio {
namespace zmq {
namespace socket_option {

std::size_t const max_buff_size = 255;

template <int option, typename T> struct socket_option_impl {
    static int const id = option;
    typedef T option_value_type;

    socket_option_impl(option_value_type value) : value_(value) {}

    option_value_type value() const { return value_; }

    option_value_type& value() { return value_; }

private:
    option_value_type value_;
};

template <int option> struct socket_option_impl<option, void*> {
    static int const id = option;
    typedef void* option_value_type;

    socket_option_impl() {}

    socket_option_impl(void const* value, std::size_t size)
        : value_(static_cast<std::uint8_t const*>(value),
                 static_cast<std::uint8_t const*>(value) + size)
    {
    }

    void const* value() const { return static_cast<void const*>(value_.data()); }

    void* value() { return static_cast<void*>(value_.data()); }

    std::size_t size() const { return value_.size(); }

private:
    std::vector<std::uint8_t> value_;
};

struct events : public socket_option_impl<ZMQ_EVENTS, int> {
    static int const default_value = -1;
    explicit events(int v = default_value) : socket_option_impl<ZMQ_EVENTS, int>(v) {}
};

struct send_buff_hwm : public socket_option_impl<ZMQ_SNDHWM, int> {
    static int const default_value = 1000;
    explicit send_buff_hwm(int v = default_value) : socket_option_impl<ZMQ_SNDHWM, int>(v) {}
};

struct recv_more : public socket_option_impl<ZMQ_RCVMORE, bool> {
    static bool const default_value = false;
    explicit recv_more(int v = default_value) : socket_option_impl<ZMQ_RCVMORE, bool>(v) {}
};

struct identity : public socket_option_impl<ZMQ_IDENTITY, void*> {
    identity() {}
    identity(void const* value, std::size_t size)
        : socket_option_impl<ZMQ_IDENTITY, void*>(value, size)
    {
    }
    identity(const std::string& value)
        : socket_option_impl<ZMQ_IDENTITY, void*>(value.c_str(),value.size())
    {
    }
};

struct subscribe : public socket_option_impl<ZMQ_SUBSCRIBE, void*> {
    subscribe() {}
    subscribe(void const* value, std::size_t size)
        : socket_option_impl<ZMQ_SUBSCRIBE, void*>(value, size)
    {
    }
};

struct fd : public socket_option_impl<ZMQ_FD, native_handle_type> {
    static native_handle_type const default_value = -1;
    explicit fd(native_handle_type v = default_value)
        : socket_option_impl<ZMQ_FD, native_handle_type>(v)
    {
    }
};

struct linger : public socket_option_impl<ZMQ_LINGER, int> {
    static int const default_value = -1;
    explicit linger(int v = default_value) : socket_option_impl<ZMQ_LINGER, int>(v) {}
};

template <typename OptionType>
struct is_binary_option
    : public std::is_base_of<socket_option_impl<OptionType::id, void*>, OptionType> {
};

template <typename OptionType>
struct enable_if_binary : public std::enable_if<is_binary_option<OptionType>::value> {
};

template <typename OptionType>
struct is_bool_option
    : public std::is_base_of<socket_option_impl<OptionType::id, bool>, OptionType> {
};

template <typename OptionType>
struct enable_if_bool : public std::enable_if<is_bool_option<OptionType>::value> {
};

template <typename OptionType>
struct is_raw_option
    : public std::integral_constant<
          bool, std::is_base_of<
                    socket_option_impl<OptionType::id, typename OptionType::option_value_type>,
                    OptionType>::value &&
                    !is_bool_option<OptionType>::value && !is_binary_option<OptionType>::value> {
};

template <typename OptionType>
struct enable_if_raw : public std::enable_if<is_raw_option<OptionType>::value> {
};

}  // namespace socket_option
}  // namespace zmq
}  // namespace asio
}  // namespace boost
<commit_msg>Added additional constructor for class boost::asio::zmq::socket_option::subscribe accepting a std::string.<commit_after>#pragma once

#include <cstdint>
#include <string>
#include <type_traits>
#include <vector>
#include <zmq.h>
#include "helpers.hpp"

namespace boost {
namespace asio {
namespace zmq {
namespace socket_option {

std::size_t const max_buff_size = 255;

template <int option, typename T> struct socket_option_impl {
    static int const id = option;
    typedef T option_value_type;

    socket_option_impl(option_value_type value) : value_(value) {}

    option_value_type value() const { return value_; }

    option_value_type& value() { return value_; }

private:
    option_value_type value_;
};

template <int option> struct socket_option_impl<option, void*> {
    static int const id = option;
    typedef void* option_value_type;

    socket_option_impl() {}

    socket_option_impl(void const* value, std::size_t size)
        : value_(static_cast<std::uint8_t const*>(value),
                 static_cast<std::uint8_t const*>(value) + size)
    {
    }

    void const* value() const { return static_cast<void const*>(value_.data()); }

    void* value() { return static_cast<void*>(value_.data()); }

    std::size_t size() const { return value_.size(); }

private:
    std::vector<std::uint8_t> value_;
};

struct events : public socket_option_impl<ZMQ_EVENTS, int> {
    static int const default_value = -1;
    explicit events(int v = default_value) : socket_option_impl<ZMQ_EVENTS, int>(v) {}
};

struct send_buff_hwm : public socket_option_impl<ZMQ_SNDHWM, int> {
    static int const default_value = 1000;
    explicit send_buff_hwm(int v = default_value) : socket_option_impl<ZMQ_SNDHWM, int>(v) {}
};

struct recv_more : public socket_option_impl<ZMQ_RCVMORE, bool> {
    static bool const default_value = false;
    explicit recv_more(int v = default_value) : socket_option_impl<ZMQ_RCVMORE, bool>(v) {}
};

struct identity : public socket_option_impl<ZMQ_IDENTITY, void*> {
    identity() {}
    identity(void const* value, std::size_t size)
        : socket_option_impl<ZMQ_IDENTITY, void*>(value, size)
    {
    }
    identity(const std::string& value)
        : socket_option_impl<ZMQ_IDENTITY, void*>(value.c_str(),value.size())
    {
    }
};

struct subscribe : public socket_option_impl<ZMQ_SUBSCRIBE, void*> {
    subscribe() {}
    subscribe(void const* value, std::size_t size)
        : socket_option_impl<ZMQ_SUBSCRIBE, void*>(value, size)
    {
    }
    subscribe(const std::string& value)
        : socket_option_impl<ZMQ_SUBSCRIBE, void*>(value.c_str(), value.size())
    {
    }
};

struct fd : public socket_option_impl<ZMQ_FD, native_handle_type> {
    static native_handle_type const default_value = -1;
    explicit fd(native_handle_type v = default_value)
        : socket_option_impl<ZMQ_FD, native_handle_type>(v)
    {
    }
};

struct linger : public socket_option_impl<ZMQ_LINGER, int> {
    static int const default_value = -1;
    explicit linger(int v = default_value) : socket_option_impl<ZMQ_LINGER, int>(v) {}
};

template <typename OptionType>
struct is_binary_option
    : public std::is_base_of<socket_option_impl<OptionType::id, void*>, OptionType> {
};

template <typename OptionType>
struct enable_if_binary : public std::enable_if<is_binary_option<OptionType>::value> {
};

template <typename OptionType>
struct is_bool_option
    : public std::is_base_of<socket_option_impl<OptionType::id, bool>, OptionType> {
};

template <typename OptionType>
struct enable_if_bool : public std::enable_if<is_bool_option<OptionType>::value> {
};

template <typename OptionType>
struct is_raw_option
    : public std::integral_constant<
          bool, std::is_base_of<
                    socket_option_impl<OptionType::id, typename OptionType::option_value_type>,
                    OptionType>::value &&
                    !is_bool_option<OptionType>::value && !is_binary_option<OptionType>::value> {
};

template <typename OptionType>
struct enable_if_raw : public std::enable_if<is_raw_option<OptionType>::value> {
};

}  // namespace socket_option
}  // namespace zmq
}  // namespace asio
}  // namespace boost
<|endoftext|>


<commit_before><commit_msg>Hopefully fixed build error under linux<commit_after><|endoftext|>


<commit_before>/*! \file binary.hpp
    \brief Binary input and output archives */
/*
  Copyright (c) 2014, Randolph Voorhies, Shane Grant
  All rights reserved.

  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions are met:
      * Redistributions of source code must retain the above copyright
        notice, this list of conditions and the following disclaimer.
      * Redistributions in binary form must reproduce the above copyright
        notice, this list of conditions and the following disclaimer in the
        documentation and/or other materials provided with the distribution.
      * Neither the name of cereal nor the
        names of its contributors may be used to endorse or promote products
        derived from this software without specific prior written permission.

  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY
  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CEREAL_ARCHIVES_BINARY_HPP_
#define CEREAL_ARCHIVES_BINARY_HPP_

#include "cereal/cereal.hpp"
#include <sstream>

namespace cereal
{
  // ######################################################################
  //! An output archive designed to save data in a compact binary representation
  /*! This archive outputs data to a stream in an extremely compact binary
      representation with as little extra metadata as possible.

      This archive does nothing to ensure that the endianness of the saved
      and loaded data is the same.  If you need to have portability over
      architectures with different endianness, use PortableBinaryOutputArchive.

      When using a binary archive and a file stream, you must use the
      std::ios::binary format flag to avoid having your data altered
      inadvertently.

      \ingroup Archives */
  class BinaryOutputArchive : public OutputArchive<BinaryOutputArchive, AllowEmptyClassElision>
  {
    public:
      //! Construct, outputting to the provided stream
      /*! @param stream The stream to output to.  Can be a stringstream, a file stream, or
                        even cout! */
      BinaryOutputArchive(std::ostream & stream) :
        OutputArchive<BinaryOutputArchive, AllowEmptyClassElision>(this),
        itsStream(stream)
      { }

      ~BinaryOutputArchive() CEREAL_NOEXCEPT = default;

      //! Writes size bytes of data to the output stream
      void saveBinary( const void * data, std::size_t size )
      {
        auto const writtenSize = static_cast<std::size_t>( itsStream.rdbuf()->sputn( reinterpret_cast<const char*>( data ), size ) );

        if(writtenSize != size)
          throw Exception("Failed to write " + std::to_string(size) + " bytes to output stream! Wrote " + std::to_string(writtenSize));
      }

    private:
      std::ostream & itsStream;
  };

  // ######################################################################
  //! An input archive designed to load data saved using BinaryOutputArchive
  /*  This archive does nothing to ensure that the endianness of the saved
      and loaded data is the same.  If you need to have portability over
      architectures with different endianness, use PortableBinaryOutputArchive.

      When using a binary archive and a file stream, you must use the
      std::ios::binary format flag to avoid having your data altered
      inadvertently.

      \ingroup Archives */
  class BinaryInputArchive : public InputArchive<BinaryInputArchive, AllowEmptyClassElision>
  {
    public:
      //! Construct, loading from the provided stream
      BinaryInputArchive(std::istream & stream) :
        InputArchive<BinaryInputArchive, AllowEmptyClassElision>(this),
        itsStream(stream)
      { }

      ~BinaryInputArchive() CEREAL_NOEXCEPT = default;

      //! Reads size bytes of data from the input stream
      void loadBinary( void * const data, std::size_t size )
      {
        auto const readSize = static_cast<std::size_t>( itsStream.rdbuf()->sgetn( reinterpret_cast<char*>( data ), size ) );

        if(readSize != size)
          throw Exception("Failed to read " + std::to_string(size) + " bytes from input stream! Read " + std::to_string(readSize));
      }

    private:
      std::istream & itsStream;
  };

  // ######################################################################
  // Common BinaryArchive serialization functions

  //! Saving for POD types to binary
  template<class T> inline
  typename std::enable_if<std::is_arithmetic<T>::value, void>::type
  CEREAL_SAVE_FUNCTION_NAME(BinaryOutputArchive & ar, T const & t)
  {
    ar.saveBinary(std::addressof(t), sizeof(t));
  }

  //! Loading for POD types from binary
  template<class T> inline
  typename std::enable_if<std::is_arithmetic<T>::value, void>::type
  CEREAL_LOAD_FUNCTION_NAME(BinaryInputArchive & ar, T & t)
  {
    ar.loadBinary(std::addressof(t), sizeof(t));
  }

  //! Serializing NVP types to binary
  template <class Archive, class T> inline
  CEREAL_ARCHIVE_RESTRICT(BinaryInputArchive, BinaryOutputArchive)
  CEREAL_SERIALIZE_FUNCTION_NAME( Archive & ar, NameValuePair<T> & t )
  {
    ar( t.value );
  }

  //! Serializing SizeTags to binary
  template <class Archive, class T> inline
  CEREAL_ARCHIVE_RESTRICT(BinaryInputArchive, BinaryOutputArchive)
  CEREAL_SERIALIZE_FUNCTION_NAME( Archive & ar, SizeTag<T> & t )
  {
    ar( t.size );
  }

  //! Saving binary data
  template <class T> inline
  void CEREAL_SAVE_FUNCTION_NAME(BinaryOutputArchive & ar, BinaryData<T> const & bd)
  {
    ar.saveBinary( bd.data, static_cast<std::size_t>( bd.size ) );
  }

  //! Loading binary data
  template <class T> inline
  void CEREAL_LOAD_FUNCTION_NAME(BinaryInputArchive & ar, BinaryData<T> & bd)
  {
    ar.loadBinary(bd.data, static_cast<std::size_t>(bd.size));
  }
} // namespace cereal

// register archives for polymorphic support
CEREAL_REGISTER_ARCHIVE(cereal::BinaryOutputArchive)
CEREAL_REGISTER_ARCHIVE(cereal::BinaryInputArchive)

// tie input and output archives together
CEREAL_SETUP_ARCHIVE_TRAITS(cereal::BinaryInputArchive, cereal::BinaryOutputArchive)

#endif // CEREAL_ARCHIVES_BINARY_HPP_
<commit_msg>correct std::size_t to std::streamsize to avoid clang warning<commit_after>/*! \file binary.hpp
    \brief Binary input and output archives */
/*
  Copyright (c) 2014, Randolph Voorhies, Shane Grant
  All rights reserved.

  Redistribution and use in source and binary forms, with or without
  modification, are permitted provided that the following conditions are met:
      * Redistributions of source code must retain the above copyright
        notice, this list of conditions and the following disclaimer.
      * Redistributions in binary form must reproduce the above copyright
        notice, this list of conditions and the following disclaimer in the
        documentation and/or other materials provided with the distribution.
      * Neither the name of cereal nor the
        names of its contributors may be used to endorse or promote products
        derived from this software without specific prior written permission.

  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  DISCLAIMED. IN NO EVENT SHALL RANDOLPH VOORHIES OR SHANE GRANT BE LIABLE FOR ANY
  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CEREAL_ARCHIVES_BINARY_HPP_
#define CEREAL_ARCHIVES_BINARY_HPP_

#include "cereal/cereal.hpp"
#include <sstream>

namespace cereal
{
  // ######################################################################
  //! An output archive designed to save data in a compact binary representation
  /*! This archive outputs data to a stream in an extremely compact binary
      representation with as little extra metadata as possible.

      This archive does nothing to ensure that the endianness of the saved
      and loaded data is the same.  If you need to have portability over
      architectures with different endianness, use PortableBinaryOutputArchive.

      When using a binary archive and a file stream, you must use the
      std::ios::binary format flag to avoid having your data altered
      inadvertently.

      \ingroup Archives */
  class BinaryOutputArchive : public OutputArchive<BinaryOutputArchive, AllowEmptyClassElision>
  {
    public:
      //! Construct, outputting to the provided stream
      /*! @param stream The stream to output to.  Can be a stringstream, a file stream, or
                        even cout! */
      BinaryOutputArchive(std::ostream & stream) :
        OutputArchive<BinaryOutputArchive, AllowEmptyClassElision>(this),
        itsStream(stream)
      { }

      ~BinaryOutputArchive() CEREAL_NOEXCEPT = default;

      //! Writes size bytes of data to the output stream
      void saveBinary( const void * data, std::streamsize size )
      {
        auto const writtenSize = itsStream.rdbuf()->sputn( reinterpret_cast<const char*>( data ), size );

        if(writtenSize != size)
          throw Exception("Failed to write " + std::to_string(size) + " bytes to output stream! Wrote " + std::to_string(writtenSize));
      }

    private:
      std::ostream & itsStream;
  };

  // ######################################################################
  //! An input archive designed to load data saved using BinaryOutputArchive
  /*  This archive does nothing to ensure that the endianness of the saved
      and loaded data is the same.  If you need to have portability over
      architectures with different endianness, use PortableBinaryOutputArchive.

      When using a binary archive and a file stream, you must use the
      std::ios::binary format flag to avoid having your data altered
      inadvertently.

      \ingroup Archives */
  class BinaryInputArchive : public InputArchive<BinaryInputArchive, AllowEmptyClassElision>
  {
    public:
      //! Construct, loading from the provided stream
      BinaryInputArchive(std::istream & stream) :
        InputArchive<BinaryInputArchive, AllowEmptyClassElision>(this),
        itsStream(stream)
      { }

      ~BinaryInputArchive() CEREAL_NOEXCEPT = default;

      //! Reads size bytes of data from the input stream
      void loadBinary( void * const data, std::streamsize size )
      {
        auto const readSize = itsStream.rdbuf()->sgetn( reinterpret_cast<char*>( data ), size );

        if(readSize != size)
          throw Exception("Failed to read " + std::to_string(size) + " bytes from input stream! Read " + std::to_string(readSize));
      }

    private:
      std::istream & itsStream;
  };

  // ######################################################################
  // Common BinaryArchive serialization functions

  //! Saving for POD types to binary
  template<class T> inline
  typename std::enable_if<std::is_arithmetic<T>::value, void>::type
  CEREAL_SAVE_FUNCTION_NAME(BinaryOutputArchive & ar, T const & t)
  {
    ar.saveBinary(std::addressof(t), sizeof(t));
  }

  //! Loading for POD types from binary
  template<class T> inline
  typename std::enable_if<std::is_arithmetic<T>::value, void>::type
  CEREAL_LOAD_FUNCTION_NAME(BinaryInputArchive & ar, T & t)
  {
    ar.loadBinary(std::addressof(t), sizeof(t));
  }

  //! Serializing NVP types to binary
  template <class Archive, class T> inline
  CEREAL_ARCHIVE_RESTRICT(BinaryInputArchive, BinaryOutputArchive)
  CEREAL_SERIALIZE_FUNCTION_NAME( Archive & ar, NameValuePair<T> & t )
  {
    ar( t.value );
  }

  //! Serializing SizeTags to binary
  template <class Archive, class T> inline
  CEREAL_ARCHIVE_RESTRICT(BinaryInputArchive, BinaryOutputArchive)
  CEREAL_SERIALIZE_FUNCTION_NAME( Archive & ar, SizeTag<T> & t )
  {
    ar( t.size );
  }

  //! Saving binary data
  template <class T> inline
  void CEREAL_SAVE_FUNCTION_NAME(BinaryOutputArchive & ar, BinaryData<T> const & bd)
  {
    ar.saveBinary( bd.data, static_cast<std::streamsize>( bd.size ) );
  }

  //! Loading binary data
  template <class T> inline
  void CEREAL_LOAD_FUNCTION_NAME(BinaryInputArchive & ar, BinaryData<T> & bd)
  {
    ar.loadBinary(bd.data, static_cast<std::streamsize>( bd.size ) );
  }
} // namespace cereal

// register archives for polymorphic support
CEREAL_REGISTER_ARCHIVE(cereal::BinaryOutputArchive)
CEREAL_REGISTER_ARCHIVE(cereal::BinaryInputArchive)

// tie input and output archives together
CEREAL_SETUP_ARCHIVE_TRAITS(cereal::BinaryInputArchive, cereal::BinaryOutputArchive)

#endif // CEREAL_ARCHIVES_BINARY_HPP_
<|endoftext|>


<commit_before><commit_msg>I18N<commit_after><|endoftext|>


<commit_before><commit_msg>* Process: setgid before setuid<commit_after><|endoftext|>


<commit_before>#pragma once

#include "CLog.h"

#include "CMySQLHandle.h"
#include "CMySQLResult.h"
#include "CMySQLQuery.h"

unordered_map<int, CMySQLHandle *> CMySQLHandle::SQLHandle;

CMySQLHandle::CMySQLHandle(int id) :
	m_QueryThreadRunning(true),
	m_QueryCounter(0),
	m_QueryThread(NULL),

	m_MyID(id),

	m_ActiveResult(NULL),
	m_ActiveResultID(0),

	m_MainConnection(NULL),
	m_QueryConnection(NULL)
{
	m_QueryThread = new boost::thread(&CMySQLHandle::ProcessQueries, this);
	CLog::Get()->LogFunction(LOG_DEBUG, "CMySQLHandle::CMySQLHandle", "constructor called");
}

CMySQLHandle::~CMySQLHandle()
{
	m_QueryThreadRunning = false;
	m_QueryThread->join();
	delete m_QueryThread;

	for (unordered_map<int, CMySQLResult*>::iterator it = m_SavedResults.begin(), end = m_SavedResults.end(); it != end; it++)
		delete it->second;

	delete m_MainConnection;
	delete m_QueryConnection;

	CLog::Get()->LogFunction(LOG_DEBUG, "CMySQLHandle::~CMySQLHandle", "deconstructor called");
}

void CMySQLHandle::WaitForQueryExec()
{
	while(!m_QueryQueue.empty())
		boost::this_thread::sleep(boost::posix_time::milliseconds(5));
}

CMySQLHandle *CMySQLHandle::Create(string host, string user, string pass, string db, size_t port, bool reconnect)
{
	CMySQLHandle *Handle = NULL;
	if (SQLHandle.size() > 0)
	{
		//code used for checking duplicate connections
		for(unordered_map<int, CMySQLHandle*>::iterator i = SQLHandle.begin(), end = SQLHandle.end(); i != end; ++i) {
			CMySQLConnection *Connection = i->second->m_MainConnection;
			if (Connection->m_Host.compare(host) == 0 && Connection->m_User.compare(user) == 0 && Connection->m_Database.compare(db) == 0 && Connection->m_Passw.compare(pass) == 0)
			{
				CLog::Get()->LogFunction(LOG_WARNING, "CMySQLHandle::Create", "connection already exists");
				Handle = i->second;
				break;
			}
		}
	}
	if(Handle == NULL)
	{
		CLog::Get()->LogFunction(LOG_DEBUG, "CMySQLHandle::Create", "creating new connection..");

		int ID = 1;
		if(SQLHandle.size() > 0)
		{
			unordered_map<int, CMySQLHandle*>::iterator itHandle = SQLHandle.begin();
			do
			{
				ID = itHandle->first+1;
				++itHandle;
			} while(SQLHandle.find(ID) != SQLHandle.end());
		}

		Handle = new CMySQLHandle(ID);

		//init connections
		Handle->m_MainConnection = new CMySQLConnection(host, user, pass, db, port, reconnect);
		Handle->m_QueryConnection = new CMySQLConnection(host, user, pass, db, port, reconnect);

		SQLHandle.insert( unordered_map<int, CMySQLHandle*>::value_type(ID, Handle) );
		CLog::Get()->LogFunction(LOG_DEBUG, "CMySQLHandle::Create", "connection created with ID = %d", ID);

	}
	return Handle;
}

void CMySQLHandle::Destroy()
{
	SQLHandle.erase(m_MyID);
	delete this;
}

void CMySQLHandle::ProcessQueries()
{
	mysql_thread_init();
	while(m_QueryThreadRunning)
	{
		CMySQLQuery *query = NULL;
		while(m_QueryQueue.pop(query))
		{
			query->Execute();
			m_QueryCounter--;
		}
		boost::this_thread::sleep(boost::posix_time::milliseconds(10));
	}
	mysql_thread_end();
}

int CMySQLHandle::SaveActiveResult()
{
	if(m_ActiveResult != NULL)
	{
		if(m_ActiveResultID != 0) //if active cache was already saved
		{
			CLog::Get()->LogFunction(LOG_WARNING, "CMySQLHandle::SaveActiveResult", "active cache was already saved");
			return m_ActiveResultID; //return the ID of already saved cache
		}
		else
		{
			int ID = 1;
			if(!m_SavedResults.empty())
			{
				unordered_map<int, CMySQLResult*>::iterator itHandle = m_SavedResults.begin();
				do
				{
					ID = itHandle->first+1;
					++itHandle;
				} while(m_SavedResults.find(ID) != m_SavedResults.end());
			}

			m_ActiveResultID = ID;
			m_SavedResults.insert( std::map<int, CMySQLResult*>::value_type(ID, m_ActiveResult) );

			CLog::Get()->LogFunction(LOG_DEBUG, "CMySQLHandle::SaveActiveResult", "cache saved with ID = %d", ID);
			return ID;
		}
	}

	return 0;
}

bool CMySQLHandle::DeleteSavedResult(int resultid)
{
	if(resultid > 0)
	{
		if(m_SavedResults.find(resultid) != m_SavedResults.end())
		{
			CMySQLResult *ResultHandle = m_SavedResults.at(resultid);
			if(m_ActiveResult == ResultHandle)
			{
				m_ActiveResult = NULL;
				m_ActiveResultID = 0;
			}
			delete ResultHandle;
			m_SavedResults.erase(resultid);
			CLog::Get()->LogFunction(LOG_DEBUG, "CMySQLHandle::DeleteSavedResult", "result deleted");
			return true;
		}
	}

	CLog::Get()->LogFunction(LOG_WARNING, "CMySQLHandle::DeleteSavedResult", "invalid result ID ('%d')", resultid);
	return false;
}

bool CMySQLHandle::SetActiveResult(int resultid)
{
	if(resultid > 0)
	{
		if(m_SavedResults.find(resultid) != m_SavedResults.end())
		{
			CMySQLResult *cResult = m_SavedResults.at(resultid);
			if(cResult != NULL)
			{
				if(m_ActiveResult != NULL)
					if(m_ActiveResultID == 0) //if cache not saved
						delete m_ActiveResult; //delete unsaved cache

				m_ActiveResult = cResult; //set new active cache
				m_ActiveResultID = resultid; //new active cache was stored previously
				CLog::Get()->LogFunction(LOG_DEBUG, "CMySQLHandle::SetActiveResult", "result is now active");
			}
		}
		else
			CLog::Get()->LogFunction(LOG_ERROR, "CMySQLHandle::SetActiveResult", "result not found");
	}
	else
	{
		if(m_ActiveResultID == 0) //if cache not saved
			delete m_ActiveResult; //delete unsaved cache
		m_ActiveResult = NULL;
		m_ActiveResultID = 0;
		CLog::Get()->LogFunction(LOG_DEBUG, "CMySQLHandle::SetActiveResult", "invalid result ID specified, setting active result to zero");
	}
	return true;
}

void CMySQLHandle::ClearAll()
{
	for(unordered_map<int, CMySQLHandle *>::iterator i = SQLHandle.begin(); i != SQLHandle.end(); ++i)
		i->second->Destroy();

	SQLHandle.clear();
}

void CMySQLHandle::SetActiveResult(CMySQLResult *result)
{
	m_ActiveResult = result;
	m_ActiveResultID = 0;
}

void CMySQLConnection::Connect()
{
	if(m_Connection == NULL)
	{
		m_Connection = mysql_init(NULL);
		if (m_Connection == NULL)
			CLog::Get()->LogFunction(LOG_ERROR, "CMySQLConnection::Connect", "MySQL initialization failed");
	}

	if (!m_IsConnected && !mysql_real_connect(m_Connection, m_Host.c_str(), m_User.c_str(), m_Passw.c_str(), m_Database.c_str(), m_Port, NULL, NULL))
	{
		CLog::Get()->LogFunction(LOG_ERROR, "CMySQLConnection::Connect", "(error #%d) %s", mysql_errno(m_Connection), mysql_error(m_Connection));

		m_IsConnected = false;
	}
	else
	{
		CLog::Get()->LogFunction(LOG_DEBUG, "CMySQLConnection::Connect", "connection was successful");

		my_bool reconnect = m_AutoReconnect;
		mysql_options(m_Connection, MYSQL_OPT_RECONNECT, &reconnect);
		CLog::Get()->LogFunction(LOG_DEBUG, "CMySQLConnection::Connect", "auto-reconnect has been %s", m_AutoReconnect == true ? "enabled" : "disabled");

		m_IsConnected = true;
	}
}

void CMySQLConnection::Disconnect()
{
	if (m_Connection == NULL)
		CLog::Get()->LogFunction(LOG_WARNING, "CMySQLConnection::Disconnect", "no connection available");
	else
	{
		mysql_close(m_Connection);
		m_Connection = NULL;
		m_IsConnected = false;
		CLog::Get()->LogFunction(LOG_DEBUG, "CMySQLConnection::Disconnect", "connection was closed");
	}
}

void CMySQLConnection::EscapeString(const char *src, string &dest)
{
	if(src != NULL && m_IsConnected)
	{
		size_t SrcLen = strlen(src);
		char *tmpEscapedStr = (char *)malloc((SrcLen*2 + 1) * sizeof(char));

		size_t EscapedLen = mysql_real_escape_string(m_Connection, tmpEscapedStr, src, SrcLen);
		dest.assign(tmpEscapedStr);

		free(tmpEscapedStr);
	}
}
<commit_msg>removed duplicate connection check<commit_after>#pragma once

#include "CLog.h"

#include "CMySQLHandle.h"
#include "CMySQLResult.h"
#include "CMySQLQuery.h"

unordered_map<int, CMySQLHandle *> CMySQLHandle::SQLHandle;

CMySQLHandle::CMySQLHandle(int id) :
	m_QueryThreadRunning(true),
	m_QueryCounter(0),
	m_QueryThread(NULL),

	m_MyID(id),

	m_ActiveResult(NULL),
	m_ActiveResultID(0),

	m_MainConnection(NULL),
	m_QueryConnection(NULL)
{
	m_QueryThread = new boost::thread(&CMySQLHandle::ProcessQueries, this);
	CLog::Get()->LogFunction(LOG_DEBUG, "CMySQLHandle::CMySQLHandle", "constructor called");
}

CMySQLHandle::~CMySQLHandle()
{
	m_QueryThreadRunning = false;
	m_QueryThread->join();
	delete m_QueryThread;

	for (unordered_map<int, CMySQLResult*>::iterator it = m_SavedResults.begin(), end = m_SavedResults.end(); it != end; it++)
		delete it->second;

	delete m_MainConnection;
	delete m_QueryConnection;

	CLog::Get()->LogFunction(LOG_DEBUG, "CMySQLHandle::~CMySQLHandle", "deconstructor called");
}

void CMySQLHandle::WaitForQueryExec()
{
	while(!m_QueryQueue.empty())
		boost::this_thread::sleep(boost::posix_time::milliseconds(5));
}

CMySQLHandle *CMySQLHandle::Create(string host, string user, string pass, string db, size_t port, bool reconnect)
{
	CLog::Get()->LogFunction(LOG_DEBUG, "CMySQLHandle::Create", "creating new connection..");

	int ID = 1;
	if(SQLHandle.size() > 0)
	{
		unordered_map<int, CMySQLHandle*>::iterator itHandle = SQLHandle.begin();
		do
		{
			ID = itHandle->first+1;
			++itHandle;
		} while(SQLHandle.find(ID) != SQLHandle.end());
	}

	CMySQLHandle *Handle = new CMySQLHandle(ID);

	//init connections
	Handle->m_MainConnection = new CMySQLConnection(host, user, pass, db, port, reconnect);
	Handle->m_QueryConnection = new CMySQLConnection(host, user, pass, db, port, reconnect);

	SQLHandle.insert( unordered_map<int, CMySQLHandle*>::value_type(ID, Handle) );
	CLog::Get()->LogFunction(LOG_DEBUG, "CMySQLHandle::Create", "connection created with ID = %d", ID);

	return Handle;
}

void CMySQLHandle::Destroy()
{
	SQLHandle.erase(m_MyID);
	delete this;
}

void CMySQLHandle::ProcessQueries()
{
	mysql_thread_init();
	while(m_QueryThreadRunning)
	{
		CMySQLQuery *query = NULL;
		while(m_QueryQueue.pop(query))
		{
			query->Execute();
			m_QueryCounter--;
		}
		boost::this_thread::sleep(boost::posix_time::milliseconds(10));
	}
	mysql_thread_end();
}

int CMySQLHandle::SaveActiveResult()
{
	if(m_ActiveResult != NULL)
	{
		if(m_ActiveResultID != 0) //if active cache was already saved
		{
			CLog::Get()->LogFunction(LOG_WARNING, "CMySQLHandle::SaveActiveResult", "active cache was already saved");
			return m_ActiveResultID; //return the ID of already saved cache
		}
		else
		{
			int ID = 1;
			if(!m_SavedResults.empty())
			{
				unordered_map<int, CMySQLResult*>::iterator itHandle = m_SavedResults.begin();
				do
				{
					ID = itHandle->first+1;
					++itHandle;
				} while(m_SavedResults.find(ID) != m_SavedResults.end());
			}

			m_ActiveResultID = ID;
			m_SavedResults.insert( std::map<int, CMySQLResult*>::value_type(ID, m_ActiveResult) );

			CLog::Get()->LogFunction(LOG_DEBUG, "CMySQLHandle::SaveActiveResult", "cache saved with ID = %d", ID);
			return ID;
		}
	}

	return 0;
}

bool CMySQLHandle::DeleteSavedResult(int resultid)
{
	if(resultid > 0)
	{
		if(m_SavedResults.find(resultid) != m_SavedResults.end())
		{
			CMySQLResult *ResultHandle = m_SavedResults.at(resultid);
			if(m_ActiveResult == ResultHandle)
			{
				m_ActiveResult = NULL;
				m_ActiveResultID = 0;
			}
			delete ResultHandle;
			m_SavedResults.erase(resultid);
			CLog::Get()->LogFunction(LOG_DEBUG, "CMySQLHandle::DeleteSavedResult", "result deleted");
			return true;
		}
	}

	CLog::Get()->LogFunction(LOG_WARNING, "CMySQLHandle::DeleteSavedResult", "invalid result ID ('%d')", resultid);
	return false;
}

bool CMySQLHandle::SetActiveResult(int resultid)
{
	if(resultid > 0)
	{
		if(m_SavedResults.find(resultid) != m_SavedResults.end())
		{
			CMySQLResult *cResult = m_SavedResults.at(resultid);
			if(cResult != NULL)
			{
				if(m_ActiveResult != NULL)
					if(m_ActiveResultID == 0) //if cache not saved
						delete m_ActiveResult; //delete unsaved cache

				m_ActiveResult = cResult; //set new active cache
				m_ActiveResultID = resultid; //new active cache was stored previously
				CLog::Get()->LogFunction(LOG_DEBUG, "CMySQLHandle::SetActiveResult", "result is now active");
			}
		}
		else
			CLog::Get()->LogFunction(LOG_ERROR, "CMySQLHandle::SetActiveResult", "result not found");
	}
	else
	{
		if(m_ActiveResultID == 0) //if cache not saved
			delete m_ActiveResult; //delete unsaved cache
		m_ActiveResult = NULL;
		m_ActiveResultID = 0;
		CLog::Get()->LogFunction(LOG_DEBUG, "CMySQLHandle::SetActiveResult", "invalid result ID specified, setting active result to zero");
	}
	return true;
}

void CMySQLHandle::ClearAll()
{
	for(unordered_map<int, CMySQLHandle *>::iterator i = SQLHandle.begin(); i != SQLHandle.end(); ++i)
		i->second->Destroy();

	SQLHandle.clear();
}

void CMySQLHandle::SetActiveResult(CMySQLResult *result)
{
	m_ActiveResult = result;
	m_ActiveResultID = 0;
}

void CMySQLConnection::Connect()
{
	if(m_Connection == NULL)
	{
		m_Connection = mysql_init(NULL);
		if (m_Connection == NULL)
			CLog::Get()->LogFunction(LOG_ERROR, "CMySQLConnection::Connect", "MySQL initialization failed");
	}

	if (!m_IsConnected && !mysql_real_connect(m_Connection, m_Host.c_str(), m_User.c_str(), m_Passw.c_str(), m_Database.c_str(), m_Port, NULL, NULL))
	{
		CLog::Get()->LogFunction(LOG_ERROR, "CMySQLConnection::Connect", "(error #%d) %s", mysql_errno(m_Connection), mysql_error(m_Connection));

		m_IsConnected = false;
	}
	else
	{
		CLog::Get()->LogFunction(LOG_DEBUG, "CMySQLConnection::Connect", "connection was successful");

		my_bool reconnect = m_AutoReconnect;
		mysql_options(m_Connection, MYSQL_OPT_RECONNECT, &reconnect);
		CLog::Get()->LogFunction(LOG_DEBUG, "CMySQLConnection::Connect", "auto-reconnect has been %s", m_AutoReconnect == true ? "enabled" : "disabled");

		m_IsConnected = true;
	}
}

void CMySQLConnection::Disconnect()
{
	if (m_Connection == NULL)
		CLog::Get()->LogFunction(LOG_WARNING, "CMySQLConnection::Disconnect", "no connection available");
	else
	{
		mysql_close(m_Connection);
		m_Connection = NULL;
		m_IsConnected = false;
		CLog::Get()->LogFunction(LOG_DEBUG, "CMySQLConnection::Disconnect", "connection was closed");
	}
}

void CMySQLConnection::EscapeString(const char *src, string &dest)
{
	if(src != NULL && m_IsConnected)
	{
		size_t SrcLen = strlen(src);
		char *tmpEscapedStr = (char *)malloc((SrcLen*2 + 1) * sizeof(char));

		size_t EscapedLen = mysql_real_escape_string(m_Connection, tmpEscapedStr, src, SrcLen);
		dest.assign(tmpEscapedStr);

		free(tmpEscapedStr);
	}
}
<|endoftext|>


<commit_before>/*
 * This File is part of Davix, The IO library for HTTP based protocols
 * Copyright (C) 2013  Adrien Devresse <adrien.devresse@cern.ch>, CERN
 *
 * 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
 *
*/

#ifndef DAVIX_FILE_TYPES_HPP
#define DAVIX_FILE_TYPES_HPP

#include <utils/davix_types.hpp>
#include <utils/davix_uri.hpp>

/**
  @file davix_file_types.hpp
  @author Devresse Adrien

  @brief davix file related type declarations
*/

// file descriptor declaration
struct Davix_dir_handle;
struct Davix_fd;

namespace Davix{

typedef struct Davix_dir_handle DAVIX_DIR;
typedef struct Davix_fd DAVIX_FD;

/// @struct DavIOVecInput
/// @brief input parameters for vector operations in Davix
struct DAVIX_EXPORT DavIOVecInput{
    void* diov_buffer;                    /**< buffer, in case of read : destination buffer, in case of write : source buffer */
    dav_off_t diov_offset;                /**< initial offset taken from the source */
    dav_size_t diov_size;                 /**< size of the data requested */
};

/// @struct DavIOVecOuput
/// @brief result of vector operations in Davix
struct DAVIX_EXPORT DavIOVecOuput{
    void* diov_buffer;                    /**< pointer to the buffer used for this fragment */
    dav_ssize_t diov_size;                /**< size of the data returned, -1 if error */
};

/// @enum advise_t
/// Information about the next type of operation executed
/// AdviseAuto : default operation, no optimization
/// AdviseSequentialRead : optimize next operation for sequential read/write
/// AdviseRandomRead: optimize next operation for random position read/write
enum DAVIX_EXPORT advise_t{
    AdviseAuto=0x00,
    AdviseSequential,
    AdviseRandom,

};

} // Davix

#endif // DAVIX_FILE_TYPES_HPP
<commit_msg>- fix the DAVIX_FD scope problem<commit_after>/*
 * This File is part of Davix, The IO library for HTTP based protocols
 * Copyright (C) 2013  Adrien Devresse <adrien.devresse@cern.ch>, CERN
 *
 * 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
 *
*/

#ifndef DAVIX_FILE_TYPES_HPP
#define DAVIX_FILE_TYPES_HPP

#include <utils/davix_types.hpp>
#include <utils/davix_uri.hpp>

/**
  @file davix_file_types.hpp
  @author Devresse Adrien

  @brief davix file related type declarations
*/

// file descriptor declaration
struct Davix_dir_handle;
struct Davix_fd;

typedef struct Davix_dir_handle DAVIX_DIR;
typedef struct Davix_fd DAVIX_FD;

namespace Davix{

/// @struct DavIOVecInput
/// @brief input parameters for vector operations in Davix
struct DAVIX_EXPORT DavIOVecInput{
    void* diov_buffer;                    /**< buffer, in case of read : destination buffer, in case of write : source buffer */
    dav_off_t diov_offset;                /**< initial offset taken from the source */
    dav_size_t diov_size;                 /**< size of the data requested */
};

/// @struct DavIOVecOuput
/// @brief result of vector operations in Davix
struct DAVIX_EXPORT DavIOVecOuput{
    void* diov_buffer;                    /**< pointer to the buffer used for this fragment */
    dav_ssize_t diov_size;                /**< size of the data returned, -1 if error */
};

/// @enum advise_t
/// Information about the next type of operation executed
/// AdviseAuto : default operation, no optimization
/// AdviseSequentialRead : optimize next operation for sequential read/write
/// AdviseRandomRead: optimize next operation for random position read/write
enum DAVIX_EXPORT advise_t{
    AdviseAuto=0x00,
    AdviseSequential,
    AdviseRandom,

};

} // Davix

#endif // DAVIX_FILE_TYPES_HPP
<|endoftext|>


<commit_before>// Copyright (c) Facebook Inc. and Microsoft Corporation.
// Licensed under the MIT license.

#include "onnx/defs/schema.h"

using AttrType = onnx::OpSchema::AttrType;

namespace onnx {
    std::function<void(OpSchema&)> AveragePoolOpSchemaGenerator(const char* name) {
        return [=](OpSchema& schema) {
            std::string doc = R"DOC(
 {name} consumes an input tensor X and applies average pooling across the
 the tensor according to kernel sizes, stride sizes, and pad lengths.
 Average pooling consisting of averaging all values of a subset of the
 input tensor according to the kernel size and downsampling the
 data into the output tensor Y for further processing.)DOC";
            ReplaceAll(doc, "{name}", name);
            schema.SetDoc(doc);
            schema.NumInputs(1);
            schema.NumOutputs(1);
            schema.Attr("kernel_shape",
                        "The size of the kernel along each axis.",
                        AttrType::INTS);
            schema.Attr("strides",
                        "Stride along each axis.",
                        AttrType::INTS);
            schema.Attr("pads",
                        "Padding along each axis, can take the value 0 (False) or non 0 (True)",
                        AttrType::INTS);
            schema.Input(0,
                         "X",
                         "Input data tensor from the previous operator; dimensions for image case "
                         "are (N x C x H x W), where N is the batch size, C is the number of channels, "
                         "and H and W are the height and the width of the data. For non image case, the "
                         "dimension are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size.");
            schema.Output(0,
                          "Y",
                          "Output data tensor from average pooling across the input "
                          "tensor. Dimensions will vary based on various kernel, stride, and pad "
                          "sizes.");
        };
    }

    OPERATOR_SCHEMA(AveragePool)
        .FillUsing(AveragePoolOpSchemaGenerator("AveragePool"));

} // namespace onnx

namespace onnx {
    std::function<void(OpSchema&)> MaxPoolOpSchemaGenerator(const char* name) {
        return [=](OpSchema& schema) {
            std::string doc = R"DOC(
 {name} consumes an input tensor X and applies max pooling across the
 the tensor according to kernel sizes, stride sizes, and pad lengths.
 Average pooling consisting of averaging all values of a subset of the
 input tensor according to the kernel size and downsampling the
 data into the output tensor Y for further processing.)DOC";
            ReplaceAll(doc, "{name}", name);
            schema.SetDoc(doc);
            schema.NumInputs(1);
            schema.NumOutputs(1);
            schema.Attr("kernel_shape",
                        "The size of the kernel along each axis.",
                        AttrType::INTS);
            schema.Attr("strides",
                        "Stride along each axis.",
                        AttrType::INTS);
            schema.Attr("pads",
                        "Padding along each axis, can take the value 0 (False) or non 0 (True)",
                        AttrType::INTS);
            schema.Attr("dilations",
                        "Dilaton along each axis, 1 mean no dilation.",
                        AttrType::INTS);
            schema.Input(0,
                         "X",
                         "Input data tensor from the previous operator; dimensions for image case "
                         "are (N x C x H x W), where N is the batch size, C is the number of channels, "
                         "and H and W are the height and the width of the data. For non image case, the "
                         "dimension are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size.");
            schema.Output(0,
                          "Y",
                          "Output data tensor from max pooling across the input "
                          "tensor. Dimensions will vary based on various kernel, stride, and pad "
                          "sizes.");
        };
    }

    OPERATOR_SCHEMA(MaxPool)
        .FillUsing(MaxPoolOpSchemaGenerator("MaxPool"));

} // namespace onnx

namespace onnx {
    std::function<void(OpSchema&)> ConvOpSchemaGenerator(const char* filter_desc) {
        return [=](OpSchema& schema) {
            std::string doc = R"DOC(
The convolution operator consumes an input tensor and {filter_desc}, and
computes the output.)DOC";
            ReplaceAll(doc, "{filter_desc}", filter_desc);
            schema.SetDoc(doc);
            schema.NumInputs(2, 3);
            schema.NumOutputs(1);
            schema.Input(0,
                         "X",
                         "Input data tensor from previous layer; has size (N x C x H x W)"
                         ", where N is the batch size, C is the number of channels, and"
                         " H and W are the height and width. Note that this is for the 2D image."
                         "Otherwise the size is (N x D1 x D2 ... x Dn)");
            schema.Input(1,
                         "weights",
                         "The weight tensor that will be used in the convolutions; "
                         "has size (M x C x kH x kW), where C is the number of channels, "
                         "and kH and kW are the height and width of the kernel, and M is the number "
                         "of feature maps. For more than 2 dimensions, the kernel shape will be "
                         "(M x C x k1 x k2 x ... x kn), where is the dimension of the kernel");
            schema.Output(0,
                          "Y",
                          "Output data tensor that contains the result of the convolution. The "
                          "output dimensions are functions of the kernel size, stride size, "
                          "and pad lengths.");
            schema.Attr("kernel_shape",
                        "The shape of the convolution kernel.",
                         AttrType::INTS);
            schema.Attr("dilations",
                        "dilation value along each axis of the filter.",
                        AttrType::INTS);
            schema.Attr("strides",
                        "stride along each axis.",
                        AttrType::INTS);
            schema.Attr("pads",
                        "Padding along each axis, can take the value 0 (False) or non 0 (True)",
                        AttrType::INTS);
            schema.Attr("group",
                        "number of groups input channels and output channels are divided into",
                        AttrType::INT);
        };
    }

    OPERATOR_SCHEMA(Conv)
        .FillUsing(ConvOpSchemaGenerator("a filter"));

} // namespace onnx

namespace onnx {
    std::function<void(OpSchema&)> ConvTransposeOpSchemaGenerator(const char* filter_desc) {
        return [=](OpSchema& schema) {
            std::string doc = R"DOC(
The convolution transpose operator consumes an input tensor and {filter_desc},
and computes the output.)DOC";
            ReplaceAll(doc, "{filter_desc}", filter_desc);
            schema.SetDoc(doc);
            schema.NumInputs(2);
            schema.NumOutputs(1);
            schema.Input(0,
                         "X",
                         "Input data tensor from previous layer; has size (N x C x H x W)"
                         ", where N is the batch size, C is the number of channels, and"
                         " H and W are the height and width. Note that this is for the 2D image."
                         "Otherwise the size is (N x D1 x D2 ... x Dn)");
            schema.Input(1,
                         "weights",
                         "The weight tensor that will be used in the convolutions; "
                         "has size (C x M x kH x kW), where C is the number of channels, "
                         "and kH and kW are the height and width of the kernel, and M is the number "
                         "of feature maps. For more than 2 dimensions, the kernel shape will be "
                         "(C x M x k1 x k2 x ... x kn), where is the dimension of the kernel");
            schema.Output(0,
                          "Y",
                          "Output data tensor that contains the result of the convolution. The "
                          "output dimensions are functions of the kernel size, stride size, "
                          "and pad lengths.");
            schema.Attr("kernel_shape",
                        "The shape of the convolution kernel.",
                         AttrType::INTS);
            schema.Attr("output_shape",
                        "The shape of the output.",
                        AttrType::INTS);
            schema.Attr("dilations",
                        "dilation value along each axis of the filter.",
                        AttrType::INTS);
            schema.Attr("strides",
                        "stride along each axis.",
                        AttrType::INTS);
            schema.Attr("pads",
                        "Padding along each axis, can take the value 0 (False) or non 0 (True)",
                        AttrType::INTS);
        };
    }

    OPERATOR_SCHEMA(ConvTranspose)
        .FillUsing(ConvTransposeOpSchemaGenerator("a filter"));

} // namespace onnx

namespace onnx {
  std::function<void(OpSchema&)> GlobalPoolingOpSchemaGenerator(const char* op_type, const char* op) {
        return [=](OpSchema& schema) {
            std::string doc = R"DOC(
 Global{op_type} consumes an input tensor X and applies {op} pooling across the
 the values in the same channel. This is equivalent to {op_type} with kernel size
 equal to the spatial dimension of input tensor.)DOC";
            ReplaceAll(doc, "{op_type}", op_type);
            ReplaceAll(doc, "{op}", op);
            schema.SetDoc(doc);
            schema.NumInputs(1);
            schema.NumOutputs(1);
            schema.Input(0,
                         "X",
                         "Input data tensor from the previous operator; dimensions for image case "
                         "are (N x C x H x W), where N is the batch size, C is the number of channels, "
                         "and H and W are the height and the width of the data. For non image case, the "
                         "dimension are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size.");
            schema.Output(0,
                          "Y",
                          "Output data tensor from pooling across the input "
                          "tensor. Dimensions will be N x C x 1 x 1");
            schema.SetDoc(doc);
        };
    }
  OPERATOR_SCHEMA(GlobalAveragePool)
  .FillUsing(GlobalPoolingOpSchemaGenerator("AveragePool", "average"));
  OPERATOR_SCHEMA(GlobalMaxPool)
  .FillUsing(GlobalPoolingOpSchemaGenerator("MaxPool", "max"));
} // namespace onnx

OPERATOR_SCHEMA(BatchNormalization)
    .NumInputs(5)
    .NumOutputs({1, 5})
    .EnforceConsumed({{3, 1}, {4, 2}})
    .SetDoc(R"DOC(
Carries out batch normalization as described in the paper
https://arxiv.org/abs/1502.03167. Depending on the mode it is being run,
there are multiple cases for the number of outputs, which we list below:

Output case #1: Y, mean, var, saved_mean, saved_var (training mode)
Output case #2: Y (test mode)
)DOC")
    .Attr("spatial",
          "Compute the mean and variance across all spatial elements or per feature.",
          AttrType::INT)
    .Attr("is_test",
          "If set to nonzero, run spatial batch normalization in test mode.",
          AttrType::INT)
    .Attr("epsilon",
          "The epsilon value to use to avoid division by zero.",
          AttrType::FLOAT)
    .Attr("momentum",
          "Factor used in computing the running mean and variance."
          "e.g., running_mean = running_mean * momentum + mean * (1 - momentum)",
          AttrType::FLOAT)
    .Input(0,
           "X",
           "The input 4-dimensional tensor of shape NCHW or NHWC depending "
           "on the order parameter.")
    .Input(1,
           "scale",
           "The scale as a 1-dimensional tensor of size C to be applied to the "
           "output.")
    .Input(2,
           "bias",
           "The bias as a 1-dimensional tensor of size C to be applied to the "
           "output.")
    .Input(3,
           "mean",
           "The running mean (training) or the estimated mean (testing) "
           "as a 1-dimensional tensor of size C.")
    .Input(4,
           "var",
           "The running variance (training) or the estimated "
           "variance (testing) as a 1-dimensional tensor of size C.")
    .Output(0, "Y", "The output 4-dimensional tensor of the same shape as X.")
    .Output(1,
            "mean",
            "The running mean after the BatchNormalization operator. Must be in-place "
            "with the input mean. Should not be used for testing.")
    .Output(2,
            "var",
            "The running variance after the BatchNormalization operator. Must be "
            "in-place with the input var. Should not be used for testing.")
    .Output(3,
            "saved_mean",
            "Saved mean used during training to speed up gradient "
            "computation. Should not be used for testing.")
    .Output(4,
            "saved_var",
            "Saved variance used during training to speed up "
            "gradient computation. Should not be used for testing.");

OPERATOR_SCHEMA(Dropout)
    .NumInputs(1)
    .NumOutputs(2)
    .AllowConsumed({{0, 0}})
    .SetDoc(R"DOC(
Dropout takes one input data (Tensor<float>) and produces two Tensor outputs,
output (Tensor<float>) and mask (Tensor<bool>). Depending on whether it is in
test mode or not, the output Y will either be a random dropout, or a simple
copy of the input. Note that our implementation of Dropout does scaling in
the training phase, so during testing nothing needs to be done.
)DOC")
    .Attr("ratio",
          "(float, default 0.5) the ratio of random dropout",
          AttrType::FLOAT)
    .Attr("is_test",
          "(int, default 0) if nonzero, run dropout in test mode where "
          "the output is simply Y = X.",
          AttrType::INT)
    .Input(0, "data", "The input data as Tensor.")
    .Output(0, "output", "The output.")
    .Output(1, "mask",
               "The output mask. If is_test is nonzero, this output is not filled.");

OPERATOR_SCHEMA(Flatten)
    .NumInputs(1)
    .NumOutputs(1)
    .SetDoc(R"DOC(
Flattens the input tensor into a 2D matrix, keeping the first dimension
unchanged.
)DOC")
    .Input(0, "input", "A tensor of rank >= 2.")
    .Output(
        0,
        "output",
        "A tensor of rank 2 with the contents of the input tensor, "
        "with first dimension equal first dimension of input, and remaining "
        "input dimensions flattened into the inner dimension of the output.");
<commit_msg>changed NumOutputs of Dropout to be 1 or 2<commit_after>// Copyright (c) Facebook Inc. and Microsoft Corporation.
// Licensed under the MIT license.

#include "onnx/defs/schema.h"

using AttrType = onnx::OpSchema::AttrType;

namespace onnx {
    std::function<void(OpSchema&)> AveragePoolOpSchemaGenerator(const char* name) {
        return [=](OpSchema& schema) {
            std::string doc = R"DOC(
 {name} consumes an input tensor X and applies average pooling across the
 the tensor according to kernel sizes, stride sizes, and pad lengths.
 Average pooling consisting of averaging all values of a subset of the
 input tensor according to the kernel size and downsampling the
 data into the output tensor Y for further processing.)DOC";
            ReplaceAll(doc, "{name}", name);
            schema.SetDoc(doc);
            schema.NumInputs(1);
            schema.NumOutputs(1);
            schema.Attr("kernel_shape",
                        "The size of the kernel along each axis.",
                        AttrType::INTS);
            schema.Attr("strides",
                        "Stride along each axis.",
                        AttrType::INTS);
            schema.Attr("pads",
                        "Padding along each axis, can take the value 0 (False) or non 0 (True)",
                        AttrType::INTS);
            schema.Input(0,
                         "X",
                         "Input data tensor from the previous operator; dimensions for image case "
                         "are (N x C x H x W), where N is the batch size, C is the number of channels, "
                         "and H and W are the height and the width of the data. For non image case, the "
                         "dimension are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size.");
            schema.Output(0,
                          "Y",
                          "Output data tensor from average pooling across the input "
                          "tensor. Dimensions will vary based on various kernel, stride, and pad "
                          "sizes.");
        };
    }

    OPERATOR_SCHEMA(AveragePool)
        .FillUsing(AveragePoolOpSchemaGenerator("AveragePool"));

} // namespace onnx

namespace onnx {
    std::function<void(OpSchema&)> MaxPoolOpSchemaGenerator(const char* name) {
        return [=](OpSchema& schema) {
            std::string doc = R"DOC(
 {name} consumes an input tensor X and applies max pooling across the
 the tensor according to kernel sizes, stride sizes, and pad lengths.
 Average pooling consisting of averaging all values of a subset of the
 input tensor according to the kernel size and downsampling the
 data into the output tensor Y for further processing.)DOC";
            ReplaceAll(doc, "{name}", name);
            schema.SetDoc(doc);
            schema.NumInputs(1);
            schema.NumOutputs(1);
            schema.Attr("kernel_shape",
                        "The size of the kernel along each axis.",
                        AttrType::INTS);
            schema.Attr("strides",
                        "Stride along each axis.",
                        AttrType::INTS);
            schema.Attr("pads",
                        "Padding along each axis, can take the value 0 (False) or non 0 (True)",
                        AttrType::INTS);
            schema.Attr("dilations",
                        "Dilaton along each axis, 1 mean no dilation.",
                        AttrType::INTS);
            schema.Input(0,
                         "X",
                         "Input data tensor from the previous operator; dimensions for image case "
                         "are (N x C x H x W), where N is the batch size, C is the number of channels, "
                         "and H and W are the height and the width of the data. For non image case, the "
                         "dimension are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size.");
            schema.Output(0,
                          "Y",
                          "Output data tensor from max pooling across the input "
                          "tensor. Dimensions will vary based on various kernel, stride, and pad "
                          "sizes.");
        };
    }

    OPERATOR_SCHEMA(MaxPool)
        .FillUsing(MaxPoolOpSchemaGenerator("MaxPool"));

} // namespace onnx

namespace onnx {
    std::function<void(OpSchema&)> ConvOpSchemaGenerator(const char* filter_desc) {
        return [=](OpSchema& schema) {
            std::string doc = R"DOC(
The convolution operator consumes an input tensor and {filter_desc}, and
computes the output.)DOC";
            ReplaceAll(doc, "{filter_desc}", filter_desc);
            schema.SetDoc(doc);
            schema.NumInputs(2, 3);
            schema.NumOutputs(1);
            schema.Input(0,
                         "X",
                         "Input data tensor from previous layer; has size (N x C x H x W)"
                         ", where N is the batch size, C is the number of channels, and"
                         " H and W are the height and width. Note that this is for the 2D image."
                         "Otherwise the size is (N x D1 x D2 ... x Dn)");
            schema.Input(1,
                         "weights",
                         "The weight tensor that will be used in the convolutions; "
                         "has size (M x C x kH x kW), where C is the number of channels, "
                         "and kH and kW are the height and width of the kernel, and M is the number "
                         "of feature maps. For more than 2 dimensions, the kernel shape will be "
                         "(M x C x k1 x k2 x ... x kn), where is the dimension of the kernel");
            schema.Output(0,
                          "Y",
                          "Output data tensor that contains the result of the convolution. The "
                          "output dimensions are functions of the kernel size, stride size, "
                          "and pad lengths.");
            schema.Attr("kernel_shape",
                        "The shape of the convolution kernel.",
                         AttrType::INTS);
            schema.Attr("dilations",
                        "dilation value along each axis of the filter.",
                        AttrType::INTS);
            schema.Attr("strides",
                        "stride along each axis.",
                        AttrType::INTS);
            schema.Attr("pads",
                        "Padding along each axis, can take the value 0 (False) or non 0 (True)",
                        AttrType::INTS);
            schema.Attr("group",
                        "number of groups input channels and output channels are divided into",
                        AttrType::INT);
        };
    }

    OPERATOR_SCHEMA(Conv)
        .FillUsing(ConvOpSchemaGenerator("a filter"));

} // namespace onnx

namespace onnx {
    std::function<void(OpSchema&)> ConvTransposeOpSchemaGenerator(const char* filter_desc) {
        return [=](OpSchema& schema) {
            std::string doc = R"DOC(
The convolution transpose operator consumes an input tensor and {filter_desc},
and computes the output.)DOC";
            ReplaceAll(doc, "{filter_desc}", filter_desc);
            schema.SetDoc(doc);
            schema.NumInputs(2);
            schema.NumOutputs(1);
            schema.Input(0,
                         "X",
                         "Input data tensor from previous layer; has size (N x C x H x W)"
                         ", where N is the batch size, C is the number of channels, and"
                         " H and W are the height and width. Note that this is for the 2D image."
                         "Otherwise the size is (N x D1 x D2 ... x Dn)");
            schema.Input(1,
                         "weights",
                         "The weight tensor that will be used in the convolutions; "
                         "has size (C x M x kH x kW), where C is the number of channels, "
                         "and kH and kW are the height and width of the kernel, and M is the number "
                         "of feature maps. For more than 2 dimensions, the kernel shape will be "
                         "(C x M x k1 x k2 x ... x kn), where is the dimension of the kernel");
            schema.Output(0,
                          "Y",
                          "Output data tensor that contains the result of the convolution. The "
                          "output dimensions are functions of the kernel size, stride size, "
                          "and pad lengths.");
            schema.Attr("kernel_shape",
                        "The shape of the convolution kernel.",
                         AttrType::INTS);
            schema.Attr("output_shape",
                        "The shape of the output.",
                        AttrType::INTS);
            schema.Attr("dilations",
                        "dilation value along each axis of the filter.",
                        AttrType::INTS);
            schema.Attr("strides",
                        "stride along each axis.",
                        AttrType::INTS);
            schema.Attr("pads",
                        "Padding along each axis, can take the value 0 (False) or non 0 (True)",
                        AttrType::INTS);
        };
    }

    OPERATOR_SCHEMA(ConvTranspose)
        .FillUsing(ConvTransposeOpSchemaGenerator("a filter"));

} // namespace onnx

namespace onnx {
  std::function<void(OpSchema&)> GlobalPoolingOpSchemaGenerator(const char* op_type, const char* op) {
        return [=](OpSchema& schema) {
            std::string doc = R"DOC(
 Global{op_type} consumes an input tensor X and applies {op} pooling across the
 the values in the same channel. This is equivalent to {op_type} with kernel size
 equal to the spatial dimension of input tensor.)DOC";
            ReplaceAll(doc, "{op_type}", op_type);
            ReplaceAll(doc, "{op}", op);
            schema.SetDoc(doc);
            schema.NumInputs(1);
            schema.NumOutputs(1);
            schema.Input(0,
                         "X",
                         "Input data tensor from the previous operator; dimensions for image case "
                         "are (N x C x H x W), where N is the batch size, C is the number of channels, "
                         "and H and W are the height and the width of the data. For non image case, the "
                         "dimension are in the form of (N x C x D1 x D2 ... Dn), where N is the batch size.");
            schema.Output(0,
                          "Y",
                          "Output data tensor from pooling across the input "
                          "tensor. Dimensions will be N x C x 1 x 1");
            schema.SetDoc(doc);
        };
    }
  OPERATOR_SCHEMA(GlobalAveragePool)
  .FillUsing(GlobalPoolingOpSchemaGenerator("AveragePool", "average"));
  OPERATOR_SCHEMA(GlobalMaxPool)
  .FillUsing(GlobalPoolingOpSchemaGenerator("MaxPool", "max"));
} // namespace onnx

OPERATOR_SCHEMA(BatchNormalization)
    .NumInputs(5)
    .NumOutputs({1, 5})
    .EnforceConsumed({{3, 1}, {4, 2}})
    .SetDoc(R"DOC(
Carries out batch normalization as described in the paper
https://arxiv.org/abs/1502.03167. Depending on the mode it is being run,
there are multiple cases for the number of outputs, which we list below:

Output case #1: Y, mean, var, saved_mean, saved_var (training mode)
Output case #2: Y (test mode)
)DOC")
    .Attr("spatial",
          "Compute the mean and variance across all spatial elements or per feature.",
          AttrType::INT)
    .Attr("is_test",
          "If set to nonzero, run spatial batch normalization in test mode.",
          AttrType::INT)
    .Attr("epsilon",
          "The epsilon value to use to avoid division by zero.",
          AttrType::FLOAT)
    .Attr("momentum",
          "Factor used in computing the running mean and variance."
          "e.g., running_mean = running_mean * momentum + mean * (1 - momentum)",
          AttrType::FLOAT)
    .Input(0,
           "X",
           "The input 4-dimensional tensor of shape NCHW or NHWC depending "
           "on the order parameter.")
    .Input(1,
           "scale",
           "The scale as a 1-dimensional tensor of size C to be applied to the "
           "output.")
    .Input(2,
           "bias",
           "The bias as a 1-dimensional tensor of size C to be applied to the "
           "output.")
    .Input(3,
           "mean",
           "The running mean (training) or the estimated mean (testing) "
           "as a 1-dimensional tensor of size C.")
    .Input(4,
           "var",
           "The running variance (training) or the estimated "
           "variance (testing) as a 1-dimensional tensor of size C.")
    .Output(0, "Y", "The output 4-dimensional tensor of the same shape as X.")
    .Output(1,
            "mean",
            "The running mean after the BatchNormalization operator. Must be in-place "
            "with the input mean. Should not be used for testing.")
    .Output(2,
            "var",
            "The running variance after the BatchNormalization operator. Must be "
            "in-place with the input var. Should not be used for testing.")
    .Output(3,
            "saved_mean",
            "Saved mean used during training to speed up gradient "
            "computation. Should not be used for testing.")
    .Output(4,
            "saved_var",
            "Saved variance used during training to speed up "
            "gradient computation. Should not be used for testing.");

OPERATOR_SCHEMA(Dropout)
    .NumInputs(1)
    .NumOutputs(1,2)
    .AllowConsumed({{0, 0}})
    .SetDoc(R"DOC(
Dropout takes one input data (Tensor<float>) and produces two Tensor outputs,
output (Tensor<float>) and mask (Tensor<bool>). Depending on whether it is in
test mode or not, the output Y will either be a random dropout, or a simple
copy of the input. Note that our implementation of Dropout does scaling in
the training phase, so during testing nothing needs to be done.
)DOC")
    .Attr("ratio",
          "(float, default 0.5) the ratio of random dropout",
          AttrType::FLOAT)
    .Attr("is_test",
          "(int, default 0) if nonzero, run dropout in test mode where "
          "the output is simply Y = X.",
          AttrType::INT)
    .Input(0, "data", "The input data as Tensor.")
    .Output(0, "output", "The output.")
    .Output(1, "mask",
               "The output mask. If is_test is nonzero, this output is not filled.");

OPERATOR_SCHEMA(Flatten)
    .NumInputs(1)
    .NumOutputs(1)
    .SetDoc(R"DOC(
Flattens the input tensor into a 2D matrix, keeping the first dimension
unchanged.
)DOC")
    .Input(0, "input", "A tensor of rank >= 2.")
    .Output(
        0,
        "output",
        "A tensor of rank 2 with the contents of the input tensor, "
        "with first dimension equal first dimension of input, and remaining "
        "input dimensions flattened into the inner dimension of the output.");
<|endoftext|>