Removed headers and sources not needed for build platform version for libbe.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34212 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2009-11-24 18:59:40 +00:00
parent a85cf9d793
commit b5a20f9d11
171 changed files with 0 additions and 22616 deletions
-148
View File
@@ -1,148 +0,0 @@
//------------------------------------------------------------------------------
// Copyright (c) 2001-2002, OpenBeOS
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: AutoDeleter.h
// Author(s): Ingo Weinhold ([email protected])
// Description: Scope-based automatic deletion of objects/arrays.
// ObjectDeleter - deletes an object
// ArrayDeleter - deletes an array
// MemoryDeleter - free()s malloc()ed memory
//------------------------------------------------------------------------------
#ifndef _AUTO_DELETER_H
#define _AUTO_DELETER_H
#include <stdlib.h>
namespace BPrivate {
// AutoDeleter
template<typename C, typename DeleteFunc>
class AutoDeleter {
public:
inline AutoDeleter()
: fObject(NULL)
{
}
inline AutoDeleter(C *object)
: fObject(object)
{
}
inline ~AutoDeleter()
{
fDelete(fObject);
}
inline void SetTo(C *object)
{
if (object != fObject) {
fDelete(fObject);
fObject = object;
}
}
inline void Unset()
{
SetTo(NULL);
}
inline void Delete()
{
SetTo(NULL);
}
inline C *Detach()
{
C *object = fObject;
fObject = NULL;
return object;
}
private:
C *fObject;
DeleteFunc fDelete;
};
// ObjectDeleter
template<typename C>
struct ObjectDelete
{
inline void operator()(C *object)
{
delete object;
}
};
template<typename C>
struct ObjectDeleter : AutoDeleter<C, ObjectDelete<C> >
{
ObjectDeleter() : AutoDeleter<C, ObjectDelete<C> >() {}
ObjectDeleter(C *object) : AutoDeleter<C, ObjectDelete<C> >(object) {}
};
// ArrayDeleter
template<typename C>
struct ArrayDelete
{
inline void operator()(C *array)
{
delete[] array;
}
};
template<typename C>
struct ArrayDeleter : AutoDeleter<C, ArrayDelete<C> >
{
ArrayDeleter() : AutoDeleter<C, ArrayDelete<C> >() {}
ArrayDeleter(C *array) : AutoDeleter<C, ArrayDelete<C> >(array) {}
};
// MemoryDeleter
struct MemoryDelete
{
inline void operator()(void *memory)
{
free(memory);
}
};
struct MemoryDeleter : AutoDeleter<void, MemoryDelete >
{
MemoryDeleter() : AutoDeleter<void, MemoryDelete >() {}
MemoryDeleter(void *memory) : AutoDeleter<void, MemoryDelete >(memory) {}
};
} // namespace BPrivate
using BPrivate::ObjectDeleter;
using BPrivate::ArrayDeleter;
using BPrivate::MemoryDeleter;
#endif // _AUTO_DELETER_H
-77
View File
@@ -1,77 +0,0 @@
//------------------------------------------------------------------------------
// DataBuffer.h
//
//------------------------------------------------------------------------------
#ifndef DATABUFFER_H
#define DATABUFFER_H
// Standard Includes -----------------------------------------------------------
// System Includes -------------------------------------------------------------
#include <SupportDefs.h>
// Project Includes ------------------------------------------------------------
// Local Includes --------------------------------------------------------------
// Local Defines ---------------------------------------------------------------
// Globals ---------------------------------------------------------------------
namespace BPrivate {
class BDataBuffer
{
public:
BDataBuffer(size_t len);
BDataBuffer(const void* data, size_t len, bool copy = false);
BDataBuffer(const BDataBuffer& rhs, bool copy = false);
~BDataBuffer();
BDataBuffer& operator=(const BDataBuffer& rhs);
size_t BufferSize() const;
const void* Buffer() const;
private:
class BDataReference
{
public:
void Acquire(BDataReference*& ref);
void Release(BDataReference*& ref);
char* Data() { return fData; }
size_t Size() const { return fSize; }
int32 Count() { return fCount; }
static void Create(const void* data, size_t len,
BDataReference*& ref, bool copy = false);
static void Create(size_t len, BDataReference*& ref);
private:
BDataReference(const void* data, size_t len, bool copy = false);
BDataReference(size_t len);
~BDataReference();
char* fData;
size_t fSize;
int32 fCount;
};
BDataBuffer(); // No default construction allowed!
BDataReference* fDataRef;
};
} // namespace BPrivate
#endif // DATABUFFER_H
/*
* $Log $
*
* $Id $
*
*/
-800
View File
@@ -1,800 +0,0 @@
/*
Open Tracker License
Terms and Conditions
Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice applies to all licensees
and shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of Be Incorporated shall not be
used in advertising or otherwise to promote the sale, use or other dealings in
this Software without prior written authorization from Be Incorporated.
Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
of Be Incorporated in the United States and other countries. Other brand product
names are registered trademarks or trademarks of their respective holders.
All rights reserved.
*/
/****************************************************************************
** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING **
** **
** DANGER, WILL ROBINSON! **
** **
** The interfaces contained here are part of BeOS's **
** **
** >> PRIVATE NOT FOR PUBLIC USE << **
** **
** implementation. **
** **
** These interfaces WILL CHANGE in future releases. **
** If you use them, your app WILL BREAK at some future time. **
** **
** (And yes, this does mean that binaries built from OpenTracker will not **
** be compatible with some future releases of the OS. When that happens, **
** we will provide an updated version of this file to keep compatibility.) **
** **
** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING **
****************************************************************************/
//
// ObjectList is a wrapper around BList that adds type safety,
// optional object ownership, search, insert operations, etc.
//
#ifndef __OBJECT_LIST__
#define __OBJECT_LIST__
#ifndef _BE_H
#include <List.h>
#endif
#include <Debug.h>
template<class T> class BObjectList;
template<class T>
struct UnaryPredicate {
virtual int operator()(const T *) const
// virtual could be avoided here if FindBinaryInsertionIndex,
// etc. were member template functions
{ return 0; }
private:
static int _unary_predicate_glue(const void *item, void *context);
friend class BObjectList<T>;
};
template<class T>
int
UnaryPredicate<T>::_unary_predicate_glue(const void *item, void *context)
{
return ((UnaryPredicate<T> *)context)->operator()((const T *)item);
}
class _PointerList_ : public BList {
public:
_PointerList_(const _PointerList_ &list);
_PointerList_(int32 itemsPerBlock = 20, bool owning = false);
virtual ~_PointerList_();
typedef void *(* GenericEachFunction)(void *, void *);
typedef int (* GenericCompareFunction)(const void *, const void *);
typedef int (* GenericCompareFunctionWithState)(const void *, const void *,
void *);
typedef int (* UnaryPredicateGlue)(const void *, void *);
void *EachElement(GenericEachFunction, void *);
void SortItems(GenericCompareFunction);
void SortItems(GenericCompareFunctionWithState, void *state);
void HSortItems(GenericCompareFunction);
void HSortItems(GenericCompareFunctionWithState, void *state);
void *BinarySearch(const void *, GenericCompareFunction) const;
void *BinarySearch(const void *, GenericCompareFunctionWithState, void *state) const;
int32 BinarySearchIndex(const void *, GenericCompareFunction) const;
int32 BinarySearchIndex(const void *, GenericCompareFunctionWithState, void *state) const;
int32 BinarySearchIndexByPredicate(const void *, UnaryPredicateGlue) const;
bool Owning() const;
bool ReplaceItem(int32, void *);
protected:
bool owning;
};
template<class T>
class BObjectList : private _PointerList_ {
public:
// iteration and sorting
typedef T *(* EachFunction)(T *, void *);
typedef const T *(* ConstEachFunction)(const T *, void *);
typedef int (* CompareFunction)(const T *, const T *);
typedef int (* CompareFunctionWithState)(const T *, const T *, void *state);
BObjectList(int32 itemsPerBlock = 20, bool owning = false);
BObjectList(const BObjectList &list);
// clones list; if list is owning, makes copies of all
// the items
virtual ~BObjectList();
BObjectList &operator=(const BObjectList &list);
// clones list; if list is owning, makes copies of all
// the items
// adding and removing
// ToDo:
// change Add calls to return const item
bool AddItem(T *);
bool AddItem(T *, int32);
bool AddList(BObjectList *);
bool AddList(BObjectList *, int32);
bool RemoveItem(T *, bool deleteIfOwning = true);
// if owning, deletes the removed item
T *RemoveItemAt(int32);
// returns the removed item
void MakeEmpty();
// item access
T *ItemAt(int32) const;
bool ReplaceItem(int32 index, T *);
// if list is owning, deletes the item at <index> first
T *SwapWithItem(int32 index, T *newItem);
// same as ReplaceItem, except does not delete old item at <index>,
// returns it instead
T *FirstItem() const;
T *LastItem() const;
// misc. getters
int32 IndexOf(const T *) const;
bool HasItem(const T *) const;
bool IsEmpty() const;
int32 CountItems() const;
T *EachElement(EachFunction, void *);
const T *EachElement(ConstEachFunction, void *) const;
void SortItems(CompareFunction);
void SortItems(CompareFunctionWithState, void *state);
void HSortItems(CompareFunction);
void HSortItems(CompareFunctionWithState, void *state);
// linear search, returns first item that matches predicate
const T *FindIf(const UnaryPredicate<T> &) const;
T *FindIf(const UnaryPredicate<T> &);
// list must be sorted with CompareFunction for these to work
const T *BinarySearch(const T &, CompareFunction) const;
const T *BinarySearch(const T &, CompareFunctionWithState, void *state) const;
// Binary insertion - list must be sorted with CompareFunction for
// these to work
// simple insert
void BinaryInsert(T *, CompareFunction);
void BinaryInsert(T *, CompareFunctionWithState, void *state);
void BinaryInsert(T *, const UnaryPredicate<T> &);
// unique insert, returns false if item already in list
bool BinaryInsertUnique(T *, CompareFunction);
bool BinaryInsertUnique(T *, CompareFunctionWithState, void *state);
bool BinaryInsertUnique(T *, const UnaryPredicate<T> &);
// insert a copy of the item, returns new inserted item
T *BinaryInsertCopy(const T &copyThis, CompareFunction);
T *BinaryInsertCopy(const T &copyThis, CompareFunctionWithState, void *state);
// insert a copy of the item if not in list already
// returns new inserted item or existing item in case of a conflict
T *BinaryInsertCopyUnique(const T &copyThis, CompareFunction);
T *BinaryInsertCopyUnique(const T &copyThis, CompareFunctionWithState, void *state);
int32 FindBinaryInsertionIndex(const UnaryPredicate<T> &, bool *alreadyInList = 0) const;
// returns either the index into which a new item should be inserted
// or index of an existing item that matches the predicate
// deprecated API, will go away
BList *AsBList()
{ return this; }
const BList *AsBList() const
{ return this; }
private:
void SetItem(int32, T *);
};
template<class Item, class Result, class Param1>
Result
WhileEachListItem(BObjectList<Item> *list, Result (Item::*func)(Param1), Param1 p1)
{
Result result = 0;
int32 count = list->CountItems();
for (int32 index = 0; index < count; index++)
if ((result = (list->ItemAt(index)->*func)(p1)) != 0)
break;
return result;
}
template<class Item, class Result, class Param1>
Result
WhileEachListItem(BObjectList<Item> *list, Result (*func)(Item *, Param1), Param1 p1)
{
Result result = 0;
int32 count = list->CountItems();
for (int32 index = 0; index < count; index++)
if ((result = (*func)(list->ItemAt(index), p1)) != 0)
break;
return result;
}
template<class Item, class Result, class Param1, class Param2>
Result
WhileEachListItem(BObjectList<Item> *list, Result (Item::*func)(Param1, Param2),
Param1 p1, Param2 p2)
{
Result result = 0;
int32 count = list->CountItems();
for (int32 index = 0; index < count; index++)
if ((result = (list->ItemAt(index)->*func)(p1, p2)) != 0)
break;
return result;
}
template<class Item, class Result, class Param1, class Param2>
Result
WhileEachListItem(BObjectList<Item> *list, Result (*func)(Item *, Param1, Param2),
Param1 p1, Param2 p2)
{
Result result = 0;
int32 count = list->CountItems();
for (int32 index = 0; index < count; index++)
if ((result = (*func)(list->ItemAt(index), p1, p2)) != 0)
break;
return result;
}
template<class Item, class Result, class Param1, class Param2, class Param3, class Param4>
Result
WhileEachListItem(BObjectList<Item> *list, Result (*func)(Item *, Param1, Param2,
Param3, Param4), Param1 p1, Param2 p2, Param3 p3, Param4 p4)
{
Result result = 0;
int32 count = list->CountItems();
for (int32 index = 0; index < count; index++)
if ((result = (*func)(list->ItemAt(index), p1, p2, p3, p4)) != 0)
break;
return result;
}
template<class Item, class Result>
void
EachListItemIgnoreResult(BObjectList<Item> *list, Result (Item::*func)())
{
int32 count = list->CountItems();
for (int32 index = 0; index < count; index++)
(list->ItemAt(index)->*func)();
}
template<class Item, class Param1>
void
EachListItem(BObjectList<Item> *list, void (*func)(Item *, Param1), Param1 p1)
{
int32 count = list->CountItems();
for (int32 index = 0; index < count; index++)
(func)(list->ItemAt(index), p1);
}
template<class Item, class Param1, class Param2>
void
EachListItem(BObjectList<Item> *list, void (Item::*func)(Param1, Param2),
Param1 p1, Param2 p2)
{
int32 count = list->CountItems();
for (int32 index = 0; index < count; index++)
(list->ItemAt(index)->*func)(p1, p2);
}
template<class Item, class Param1, class Param2>
void
EachListItem(BObjectList<Item> *list, void (*func)(Item *,Param1, Param2),
Param1 p1, Param2 p2)
{
int32 count = list->CountItems();
for (int32 index = 0; index < count; index++)
(func)(list->ItemAt(index), p1, p2);
}
template<class Item, class Param1, class Param2, class Param3>
void
EachListItem(BObjectList<Item> *list, void (*func)(Item *,Param1, Param2,
Param3), Param1 p1, Param2 p2, Param3 p3)
{
int32 count = list->CountItems();
for (int32 index = 0; index < count; index++)
(func)(list->ItemAt(index), p1, p2, p3);
}
template<class Item, class Param1, class Param2, class Param3, class Param4>
void
EachListItem(BObjectList<Item> *list, void (*func)(Item *,Param1, Param2,
Param3, Param4), Param1 p1, Param2 p2, Param3 p3, Param4 p4)
{
int32 count = list->CountItems();
for (int32 index = 0; index < count; index++)
(func)(list->ItemAt(index), p1, p2, p3, p4);
}
// inline code
inline bool
_PointerList_::Owning() const
{
return owning;
}
template<class T>
BObjectList<T>::BObjectList(int32 itemsPerBlock, bool owning)
: _PointerList_(itemsPerBlock, owning)
{
}
template<class T>
BObjectList<T>::BObjectList(const BObjectList<T> &list)
: _PointerList_(list)
{
owning = list.owning;
if (owning) {
// make our own copies in an owning list
int32 count = list.CountItems();
for (int32 index = 0; index < count; index++) {
T *item = list.ItemAt(index);
if (item)
item = new T(*item);
SetItem(index, item);
}
}
}
template<class T>
BObjectList<T>::~BObjectList()
{
if (Owning())
// have to nuke elements first
MakeEmpty();
}
template<class T>
BObjectList<T> &
BObjectList<T>::operator=(const BObjectList<T> &list)
{
owning = list.owning;
BObjectList<T> &result = (BObjectList<T> &)_PointerList_::operator=(list);
if (owning) {
// make our own copies in an owning list
int32 count = list.CountItems();
for (int32 index = 0; index < count; index++) {
T *item = list.ItemAt(index);
if (item)
item = new T(*item);
SetItem(index, item);
}
}
return result;
}
template<class T>
bool
BObjectList<T>::AddItem(T *item)
{
// need to cast to void * to make T work for const pointers
return _PointerList_::AddItem((void *)item);
}
template<class T>
bool
BObjectList<T>::AddItem(T *item, int32 atIndex)
{
return _PointerList_::AddItem((void *)item, atIndex);
}
template<class T>
bool
BObjectList<T>::AddList(BObjectList<T> *newItems)
{
return _PointerList_::AddList(newItems);
}
template<class T>
bool
BObjectList<T>::AddList(BObjectList<T> *newItems, int32 atIndex)
{
return _PointerList_::AddList(newItems, atIndex);
}
template<class T>
bool
BObjectList<T>::RemoveItem(T *item, bool deleteIfOwning)
{
bool result = _PointerList_::RemoveItem((void *)item);
if (result && Owning() && deleteIfOwning)
delete item;
return result;
}
template<class T>
T *
BObjectList<T>::RemoveItemAt(int32 index)
{
return (T *)_PointerList_::RemoveItem(index);
}
template<class T>
inline T *
BObjectList<T>::ItemAt(int32 index) const
{
return (T *)_PointerList_::ItemAt(index);
}
template<class T>
bool
BObjectList<T>::ReplaceItem(int32 index, T *item)
{
if (owning)
delete ItemAt(index);
return _PointerList_::ReplaceItem(index, (void *)item);
}
template<class T>
T *
BObjectList<T>::SwapWithItem(int32 index, T *newItem)
{
T *result = ItemAt(index);
_PointerList_::ReplaceItem(index, (void *)newItem);
return result;
}
template<class T>
void
BObjectList<T>::SetItem(int32 index, T *newItem)
{
_PointerList_::ReplaceItem(index, (void *)newItem);
}
template<class T>
int32
BObjectList<T>::IndexOf(const T *item) const
{
return _PointerList_::IndexOf((void *)item);
}
template<class T>
T *
BObjectList<T>::FirstItem() const
{
return (T *)_PointerList_::FirstItem();
}
template<class T>
T *
BObjectList<T>::LastItem() const
{
return (T *)_PointerList_::LastItem();
}
template<class T>
bool
BObjectList<T>::HasItem(const T *item) const
{
return _PointerList_::HasItem((void *)item);
}
template<class T>
bool
BObjectList<T>::IsEmpty() const
{
return _PointerList_::IsEmpty();
}
template<class T>
int32
BObjectList<T>::CountItems() const
{
return _PointerList_::CountItems();
}
template<class T>
void
BObjectList<T>::MakeEmpty()
{
if (owning) {
int32 count = CountItems();
for (int32 index = 0; index < count; index++)
delete ItemAt(index);
}
_PointerList_::MakeEmpty();
}
template<class T>
T *
BObjectList<T>::EachElement(EachFunction func, void *params)
{
return (T *)_PointerList_::EachElement((GenericEachFunction)func, params);
}
template<class T>
const T *
BObjectList<T>::EachElement(ConstEachFunction func, void *params) const
{
return (const T *)
const_cast<BObjectList<T> *>(this)->_PointerList_::EachElement(
(GenericEachFunction)func, params);
}
template<class T>
const T *
BObjectList<T>::FindIf(const UnaryPredicate<T> &predicate) const
{
int32 count = CountItems();
for (int32 index = 0; index < count; index++)
if (predicate.operator()(ItemAt(index)) == 0)
return ItemAt(index);
return 0;
}
template<class T>
T *
BObjectList<T>::FindIf(const UnaryPredicate<T> &predicate)
{
int32 count = CountItems();
for (int32 index = 0; index < count; index++)
if (predicate.operator()(ItemAt(index)) == 0)
return ItemAt(index);
return 0;
}
template<class T>
void
BObjectList<T>::SortItems(CompareFunction function)
{
_PointerList_::SortItems((GenericCompareFunction)function);
}
template<class T>
void
BObjectList<T>::SortItems(CompareFunctionWithState function, void *state)
{
_PointerList_::SortItems((GenericCompareFunctionWithState)function, state);
}
template<class T>
void
BObjectList<T>::HSortItems(CompareFunction function)
{
_PointerList_::HSortItems((GenericCompareFunction)function);
}
template<class T>
void
BObjectList<T>::HSortItems(CompareFunctionWithState function, void *state)
{
_PointerList_::HSortItems((GenericCompareFunctionWithState)function, state);
}
template<class T>
const T *
BObjectList<T>::BinarySearch(const T &key, CompareFunction func) const
{
return (const T *)_PointerList_::BinarySearch(&key,
(GenericCompareFunction)func);
}
template<class T>
const T *
BObjectList<T>::BinarySearch(const T &key, CompareFunctionWithState func, void *state) const
{
return (const T *)_PointerList_::BinarySearch(&key,
(GenericCompareFunctionWithState)func, state);
}
template<class T>
void
BObjectList<T>::BinaryInsert(T *item, CompareFunction func)
{
int32 index = _PointerList_::BinarySearchIndex(item,
(GenericCompareFunction)func);
if (index >= 0)
// already in list, add after existing
AddItem(item, index + 1);
else
AddItem(item, -index - 1);
}
template<class T>
void
BObjectList<T>::BinaryInsert(T *item, CompareFunctionWithState func, void *state)
{
int32 index = _PointerList_::BinarySearchIndex(item,
(GenericCompareFunctionWithState)func, state);
if (index >= 0)
// already in list, add after existing
AddItem(item, index + 1);
else
AddItem(item, -index - 1);
}
template<class T>
bool
BObjectList<T>::BinaryInsertUnique(T *, CompareFunction func)
{
int32 index = _PointerList_::BinarySearchIndex(item,
(GenericCompareFunction)func);
if (index >= 0)
return false;
AddItem(item, -index - 1);
return true;
}
template<class T>
bool
BObjectList<T>::BinaryInsertUnique(T *, CompareFunctionWithState func, void *state)
{
int32 index = _PointerList_::BinarySearchIndex(item,
(GenericCompareFunctionWithState)func, state);
if (index >= 0)
return false;
AddItem(item, -index - 1);
return true;
}
template<class T>
T *
BObjectList<T>::BinaryInsertCopy(const T &copyThis, CompareFunction func)
{
int32 index = _PointerList_::BinarySearchIndex(&copyThis,
(GenericCompareFunction)func);
if (index >= 0)
index++;
else
index = -index - 1;
T *newItem = new T(copyThis);
AddItem(newItem, index);
return newItem;
}
template<class T>
T *
BObjectList<T>::BinaryInsertCopy(const T &copyThis, CompareFunctionWithState func, void *state)
{
int32 index = _PointerList_::BinarySearchIndex(&copyThis,
(GenericCompareFunctionWithState)func, state);
if (index >= 0)
index++;
else
index = -index - 1;
T *newItem = new T(copyThis);
AddItem(newItem, index);
return newItem;
}
template<class T>
T *
BObjectList<T>::BinaryInsertCopyUnique(const T &copyThis, CompareFunction func)
{
int32 index = _PointerList_::BinarySearchIndex(&copyThis,
(GenericCompareFunction)func);
if (index >= 0)
return ItemAt(index);
index = -index - 1;
T *newItem = new T(copyThis);
AddItem(newItem, index);
return newItem;
}
template<class T>
T *
BObjectList<T>::BinaryInsertCopyUnique(const T &copyThis, CompareFunctionWithState func,
void *state)
{
int32 index = _PointerList_::BinarySearchIndex(&copyThis,
(GenericCompareFunctionWithState)func, state);
if (index >= 0)
return ItemAt(index);
index = -index - 1;
T *newItem = new T(copyThis);
AddItem(newItem, index);
return newItem;
}
template<class T>
int32
BObjectList<T>::FindBinaryInsertionIndex(const UnaryPredicate<T> &pred, bool *alreadyInList)
const
{
int32 index = _PointerList_::BinarySearchIndexByPredicate(&pred,
(UnaryPredicateGlue)&UnaryPredicate<T>::_unary_predicate_glue);
if (alreadyInList)
*alreadyInList = index >= 0;
if (index < 0)
index = -index - 1;
return index;
}
template<class T>
void
BObjectList<T>::BinaryInsert(T *item, const UnaryPredicate<T> &pred)
{
int32 index = FindBinaryInsertionIndex(pred);
AddItem(item, index);
}
template<class T>
bool
BObjectList<T>::BinaryInsertUnique(T *item, const UnaryPredicate<T> &pred)
{
bool alreadyInList;
int32 index = FindBinaryInsertionIndex(pred, &alreadyInList);
if (alreadyInList)
return false;
AddItem(item, index);
return true;
}
#endif
-231
View File
@@ -1,231 +0,0 @@
/*
* Copyright 2004-2005, Axel Dörfler, [email protected]. All rights reserved.
* Distributed under the terms of the MIT License.
*/
/* Taken from the Pulse application, and extended.
* It's used by Pulse, AboutHaiku, and sysinfo.
*/
#include <OS.h>
#ifdef __cplusplus
extern "C" {
#endif
const char *get_cpu_vendor_string(enum cpu_types type);
const char *get_cpu_model_string(enum cpu_types type);
void get_cpu_type(char *vendorBuffer, size_t vendorSize, char *modelBuffer, size_t modelSize);
int32 get_rounded_cpu_speed(void);
#ifdef __cplusplus
}
#endif
const char *
get_cpu_vendor_string(enum cpu_types type)
{
#if __POWERPC__
// We're not that nice here
return "IBM/Motorola";
#endif
#if __INTEL__
// Determine x86 vendor name
switch (type & B_CPU_x86_VENDOR_MASK) {
case B_CPU_INTEL_x86:
return "Intel";
case B_CPU_AMD_x86:
return "AMD";
case B_CPU_CYRIX_x86:
return "Cyrix";
case B_CPU_IDT_x86:
// IDT was bought by VIA
if (((type >> 8) & 0xf) >= 6)
return "VIA";
return "IDT";
case B_CPU_RISE_x86:
return "Rise";
case B_CPU_TRANSMETA_x86:
return "Transmeta";
default:
return NULL;
}
#endif
}
const char *
get_cpu_model_string(enum cpu_types type)
{
// Determine CPU type
switch (type) {
#if __POWERPC__
case B_CPU_PPC_603:
return "603";
case B_CPU_PPC_603e:
return "603e";
case B_CPU_PPC_750:
return "750";
case B_CPU_PPC_604:
return "604";
case B_CPU_PPC_604e:
return "604e";
#endif // __POWERPC__
#if __INTEL__
case B_CPU_x86:
return "Unknown x86";
/* Intel */
case B_CPU_INTEL_PENTIUM:
case B_CPU_INTEL_PENTIUM75:
return "Pentium";
case B_CPU_INTEL_PENTIUM_486_OVERDRIVE:
case B_CPU_INTEL_PENTIUM75_486_OVERDRIVE:
return "Pentium OD";
case B_CPU_INTEL_PENTIUM_MMX:
case B_CPU_INTEL_PENTIUM_MMX_MODEL_8:
return "Pentium MMX";
case B_CPU_INTEL_PENTIUM_PRO:
return "Pentium Pro";
case B_CPU_INTEL_PENTIUM_II_MODEL_3:
case B_CPU_INTEL_PENTIUM_II_MODEL_5:
return "Pentium II";
case B_CPU_INTEL_CELERON:
return "Celeron";
case B_CPU_INTEL_PENTIUM_III:
case B_CPU_INTEL_PENTIUM_III_MODEL_8:
case B_CPU_INTEL_PENTIUM_III_MODEL_11:
case B_CPU_INTEL_PENTIUM_III_XEON:
return "Pentium III";
case B_CPU_INTEL_PENTIUM_M:
case B_CPU_INTEL_PENTIUM_M_MODEL_13:
return "Pentium M";
case B_CPU_INTEL_PENTIUM_IV:
case B_CPU_INTEL_PENTIUM_IV_MODEL_1:
case B_CPU_INTEL_PENTIUM_IV_MODEL_2:
case B_CPU_INTEL_PENTIUM_IV_MODEL_3:
case B_CPU_INTEL_PENTIUM_IV_MODEL_4:
return "Pentium 4";
/* AMD */
case B_CPU_AMD_K5_MODEL_0:
case B_CPU_AMD_K5_MODEL_1:
case B_CPU_AMD_K5_MODEL_2:
case B_CPU_AMD_K5_MODEL_3:
return "K5";
case B_CPU_AMD_K6_MODEL_6:
case B_CPU_AMD_K6_MODEL_7:
return "K6";
case B_CPU_AMD_K6_2:
return "K6-2";
case B_CPU_AMD_K6_III:
case B_CPU_AMD_K6_III_MODEL_13:
return "K6-III";
case B_CPU_AMD_ATHLON_MODEL_1:
case B_CPU_AMD_ATHLON_MODEL_2:
case B_CPU_AMD_ATHLON_THUNDERBIRD:
return "Athlon";
case B_CPU_AMD_ATHLON_XP:
case B_CPU_AMD_ATHLON_XP_MODEL_7:
case B_CPU_AMD_ATHLON_XP_MODEL_8:
case B_CPU_AMD_ATHLON_XP_MODEL_10:
return "Athlon XP";
case B_CPU_AMD_DURON:
return "Duron";
case B_CPU_AMD_ATHLON_64_MODEL_4:
case B_CPU_AMD_ATHLON_64_MODEL_7:
case B_CPU_AMD_ATHLON_64_MODEL_8:
case B_CPU_AMD_ATHLON_64_MODEL_11:
case B_CPU_AMD_ATHLON_64_MODEL_12:
case B_CPU_AMD_ATHLON_64_MODEL_14:
case B_CPU_AMD_ATHLON_64_MODEL_15:
return "Athlon 64";
case B_CPU_AMD_OPTERON:
return "Opteron";
/* Transmeta */
case B_CPU_TRANSMETA_CRUSOE:
return "Crusoe";
/* IDT/VIA */
case B_CPU_IDT_WINCHIP_C6:
return "WinChip C6";
case B_CPU_IDT_WINCHIP_2:
return "WinChip 2";
case B_CPU_VIA_EDEN:
case B_CPU_VIA_EDEN_EZRA_T:
return "Eden";
/* Cyrix/VIA */
case B_CPU_CYRIX_GXm:
return "GXm";
case B_CPU_CYRIX_6x86MX:
return "6x86MX";
/* Rise */
case B_CPU_RISE_mP6:
return "mP6";
/* National Semiconductor */
case B_CPU_NATIONAL_GEODE_GX1:
return "Geode GX1";
#endif // __INTEL__
default:
return NULL;
}
}
void
get_cpu_type(char *vendorBuffer, size_t vendorSize, char *modelBuffer, size_t modelSize)
{
const char *vendor, *model;
system_info info;
get_system_info(&info);
vendor = get_cpu_vendor_string(info.cpu_type);
if (vendor == NULL)
vendor = "Unknown";
model = get_cpu_model_string(info.cpu_type);
if (model == NULL)
model = "Unknown";
#ifdef R5_COMPATIBLE
strncpy(vendorBuffer, vendor, vendorSize - 1);
vendorBuffer[vendorSize - 1] = '\0';
strncpy(modelBuffer, model, modelSize - 1);
modelBuffer[modelSize - 1] = '\0';
#else
strlcpy(vendorBuffer, vendor, vendorSize);
strlcpy(modelBuffer, model, modelSize);
#endif
}
int32
get_rounded_cpu_speed(void)
{
system_info sys_info;
int target, frac, delta;
int freqs[] = { 100, 50, 25, 75, 33, 67, 20, 40, 60, 80, 10, 30, 70, 90 };
uint x;
get_system_info(&sys_info);
target = sys_info.cpu_clock_speed / 1000000;
frac = target % 100;
delta = -frac;
for (x = 0; x < sizeof(freqs) / sizeof(freqs[0]); x++) {
int ndelta = freqs[x] - frac;
if (abs(ndelta) < abs(delta))
delta = ndelta;
}
return target + delta;
}