aboutsummaryrefslogtreecommitdiffstats
path: root/src/util/Clamp.hxx
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/util/Clamp.hxx (renamed from src/util/growing_fifo.h)54
1 files changed, 15 insertions, 39 deletions
diff --git a/src/util/growing_fifo.h b/src/util/Clamp.hxx
index 723c3b3ff..3217ef9f7 100644
--- a/src/util/growing_fifo.h
+++ b/src/util/Clamp.hxx
@@ -1,6 +1,5 @@
/*
- * Copyright (C) 2003-2011 The Music Player Daemon Project
- * http://www.musicpd.org
+ * Copyright (C) 2012 Max Kellermann <max@duempel.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -28,46 +27,23 @@
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-/** \file
- *
- * Helper functions for our FIFO buffer library (fifo_buffer.h) that
- * allows growing the buffer on demand.
- *
- * This library is not thread safe.
- */
-
-#ifndef MPD_GROWING_FIFO_H
-#define MPD_GROWING_FIFO_H
+#ifndef CLAMP_HPP
+#define CLAMP_HPP
-#include <stddef.h>
-
-struct fifo_buffer;
-
-/**
- * Allocate a new #fifo_buffer with the default size.
- */
-struct fifo_buffer *
-growing_fifo_new(void);
-
-/**
- * Prepares writing to the buffer, see fifo_buffer_write() for
- * details. The difference is that this function will automatically
- * grow the buffer if it is too small.
- *
- * The caller is responsible for limiting the capacity of the buffer.
- *
- * @param length the number of bytes that will be written
- * @return a pointer to the end of the buffer (will not be NULL)
- */
-void *
-growing_fifo_write(struct fifo_buffer **buffer_p, size_t length);
+#include "Compiler.h"
/**
- * A helper function that combines growing_fifo_write(), memcpy(),
- * fifo_buffer_append().
+ * Clamps the specified value in a range. Returns #min or #max if the
+ * value is outside.
*/
-void
-growing_fifo_append(struct fifo_buffer **buffer_p,
- const void *data, size_t length);
+template<typename T>
+static inline constexpr const T &
+Clamp(const T &value, const T &min, const T &max)
+{
+ return gcc_unlikely(value < min)
+ ? min
+ : (gcc_unlikely(value > max)
+ ? max : value);
+}
#endif