mirror of
https://github.com/genodelabs/genode.git
synced 2025-06-18 15:18:20 +00:00
Imported Genode release 11.11
This commit is contained in:
committed by
Christian Helmuth
parent
6bcc9aef0e
commit
da4e1feaa5
77
base/include/util/avl_string.h
Normal file
77
base/include/util/avl_string.h
Normal file
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* \brief Utility for handling strings as AVL-node keys
|
||||
* \author Norman Feske
|
||||
* \date 2006-07-12
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006-2011 Genode Labs GmbH
|
||||
*
|
||||
* This file is part of the Genode OS framework, which is distributed
|
||||
* under the terms of the GNU General Public License version 2.
|
||||
*/
|
||||
|
||||
#ifndef _INCLUDE__UTIL__AVL_STRING_H_
|
||||
#define _INCLUDE__UTIL__AVL_STRING_H_
|
||||
|
||||
#include <util/avl_tree.h>
|
||||
#include <util/string.h>
|
||||
|
||||
namespace Genode {
|
||||
|
||||
class Avl_string_base : public Avl_node<Avl_string_base>
|
||||
{
|
||||
private:
|
||||
|
||||
const char *_str;
|
||||
|
||||
protected:
|
||||
|
||||
Avl_string_base(const char *str) : _str(str) { }
|
||||
|
||||
public:
|
||||
|
||||
const char *name() const { return _str; }
|
||||
|
||||
|
||||
/************************
|
||||
** Avl node interface **
|
||||
************************/
|
||||
|
||||
bool higher(Avl_string_base *c) { return (strcmp(c->_str, _str) > 0); }
|
||||
|
||||
/**
|
||||
* Find by name
|
||||
*/
|
||||
Avl_string_base *find_by_name(const char *name)
|
||||
{
|
||||
if (strcmp(name, _str) == 0) return this;
|
||||
|
||||
Avl_string_base *c = Avl_node<Avl_string_base>::child(strcmp(name, _str) > 0);
|
||||
return c ? c->find_by_name(name) : 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* The template pumps up the Avl_string_base object and
|
||||
* provides the buffer for the actual string.
|
||||
*/
|
||||
template <int STR_LEN>
|
||||
class Avl_string : public Avl_string_base
|
||||
{
|
||||
private:
|
||||
|
||||
char _str_buf[STR_LEN];
|
||||
|
||||
public:
|
||||
|
||||
Avl_string(const char *str) : Avl_string_base(_str_buf)
|
||||
{
|
||||
strncpy(_str_buf, str, sizeof(_str_buf));
|
||||
_str_buf[STR_LEN - 1] = 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* _INCLUDE__UTIL__AVL_STRING_H_ */
|
Reference in New Issue
Block a user