2009-01-04 12:45:06 +01:00
|
|
|
// Copyright (c) 2005-2009, Rodrigo Braz Monteiro, Niels Martin Hansen
|
2006-01-16 22:02:54 +01:00
|
|
|
// 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 the Aegisub Group 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 THE COPYRIGHT OWNER OR CONTRIBUTORS 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.
|
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
2006-01-16 22:02:54 +01:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/// @file utils.h
|
|
|
|
/// @see utils.cpp
|
|
|
|
/// @ingroup utility
|
|
|
|
///
|
2006-01-16 22:02:54 +01:00
|
|
|
|
|
|
|
|
2007-01-24 03:11:26 +01:00
|
|
|
#pragma once
|
2007-01-21 07:30:19 +01:00
|
|
|
|
2009-09-11 04:36:34 +02:00
|
|
|
#ifndef AGI_PRE
|
2007-08-31 16:11:35 +02:00
|
|
|
#include <stdint.h>
|
2007-04-14 17:26:46 +02:00
|
|
|
|
2010-08-03 00:14:11 +02:00
|
|
|
#include <algorithm>
|
2009-09-11 04:36:34 +02:00
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <wx/icon.h>
|
|
|
|
#include <wx/menuitem.h>
|
|
|
|
#endif
|
2007-04-14 17:26:46 +02:00
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
/// DOCME
|
2007-04-14 17:26:46 +02:00
|
|
|
typedef std::vector<std::pair<int,int> > IntPairVector;
|
|
|
|
|
2006-04-13 08:35:55 +02:00
|
|
|
#ifndef __LINUX__
|
2007-08-31 16:11:35 +02:00
|
|
|
int64_t abs64(int64_t input);
|
2006-02-26 03:53:45 +01:00
|
|
|
#endif
|
2006-01-16 22:02:54 +01:00
|
|
|
int CountMatches(wxString parent,wxString child);
|
|
|
|
wxString MakeRelativePath(wxString path,wxString reference);
|
|
|
|
wxString DecodeRelativePath(wxString path,wxString reference);
|
2009-04-06 22:01:42 +02:00
|
|
|
wxString AegiFloatToString(double value);
|
|
|
|
wxString AegiIntegerToString(int value);
|
2006-07-01 04:27:37 +02:00
|
|
|
wxString PrettySize(int bytes);
|
2007-04-08 04:41:40 +02:00
|
|
|
wxMenuItem *AppendBitmapMenuItem (wxMenu* parentMenu,int id,wxString text,wxString help,wxBitmap bmp,int pos=-1);
|
2007-01-21 07:30:19 +01:00
|
|
|
int SmallestPowerOf2(int x);
|
2007-04-14 17:26:46 +02:00
|
|
|
void GetWordBoundaries(const wxString text,IntPairVector &results,int start=0,int end=-1);
|
2009-06-25 00:22:45 +02:00
|
|
|
bool IsWhitespace(wchar_t c);
|
|
|
|
bool StringEmptyOrWhitespace(const wxString &str);
|
2009-04-06 22:01:42 +02:00
|
|
|
int AegiStringToInt(const wxString &str,int start=0,int end=-1);
|
|
|
|
int AegiStringToFix(const wxString &str,size_t decimalPlaces,int start=0,int end=-1);
|
2007-07-05 01:09:40 +02:00
|
|
|
wxIcon BitmapToIcon(wxBitmap bmp);
|
2009-01-04 12:45:06 +01:00
|
|
|
void RestartAegisub();
|
2007-01-21 07:30:19 +01:00
|
|
|
|
2010-12-08 04:36:10 +01:00
|
|
|
|
|
|
|
/// @brief Templated abs() function
|
|
|
|
template <typename T> T tabs(T x) { return x < 0 ? -x : x; }
|
|
|
|
|
2010-12-31 22:03:03 +01:00
|
|
|
template<typename T> inline T mid(T a, T b, T c) { return std::max(a, std::min(b, c)); }
|
2007-04-03 23:05:33 +02:00
|
|
|
|
|
|
|
#ifndef FORCEINLINE
|
|
|
|
#ifdef __VISUALC__
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// DOCME
|
2007-04-03 23:05:33 +02:00
|
|
|
#define FORCEINLINE __forceinline
|
|
|
|
#else
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
|
|
|
/// DOCME
|
2007-04-21 00:17:42 +02:00
|
|
|
#define FORCEINLINE inline
|
|
|
|
// __attribute__((always_inline)) gives me errors on g++ ~amz
|
2007-04-03 23:05:33 +02:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2010-06-24 03:24:43 +02:00
|
|
|
struct delete_ptr {
|
|
|
|
template<class T>
|
|
|
|
void operator()(T* ptr) const {
|
|
|
|
delete ptr;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
template<class T>
|
|
|
|
void delete_clear(T& container) {
|
|
|
|
std::for_each(container.begin(), container.end(), delete_ptr());
|
|
|
|
container.clear();
|
|
|
|
}
|
2010-07-12 09:10:40 +02:00
|
|
|
|
|
|
|
template<class Out>
|
|
|
|
struct cast {
|
|
|
|
template<class In>
|
|
|
|
Out operator()(In in) const {
|
|
|
|
return dynamic_cast<Out>(in);
|
|
|
|
}
|
|
|
|
};
|