• What are you working on? V5
    2,005 replies, posted
[QUOTE=high;18885097]Not going to bother arguing with you and your linux butt buddies. Pointless to when all you use is C++ so you have gotten used to its shit.[/QUOTE] Actually I don't like Linux. And I've used and still use C++, Java, C#, ChaiScript, Lua, Cg/HLSL/GLSL and J. Your argument is void.
[QUOTE=nullsquared;18885300]Actually I don't like Linux. And I've used and still use C++, Java, C#, ChaiScript, Lua, Cg/HLSL/GLSL and J. Your argument is void.[/QUOTE] Pfft, you and gparent are the same person. Also if you actually used C# correctly you would hate the std.
[QUOTE=high;18885325]Pfft, you and gparent are the same person. Also if you actually used C# correctly you would hate the std.[/QUOTE] Please make some concrete argument. Right now you're just blabbing based on opinion, not fact. No, if I used C# correctly then I'd make good use of what C# has to offer. I wouldn't magically hate the SC++L.
What do you mean by "put together the [...] classes"? You don't like their set of methods or something?
[QUOTE=ZeekyHBomb;18885448]What do you mean by "put together the [...] classes"? You don't like their set of methods or something?[/QUOTE] Making a list as I go. Here is 1 to start. A lot of my bitching comes from their lack of using exceptions. [cpp]template <class T> bool from_string(T& t, const std::string& s, std::ios_base& (*f)(std::ios_base&)) { std::istringstream iss(s); return !(iss >> f >> t).fail(); } [/cpp] Why is there a fail() function? Why not an exception? This is C++ not C.
Doesn't the last [del]but one[/del] index == NULL in a string? How can you get out of range? Today I made a simple tree control for GWEN. It's all working perfectly - could probably do with some of those dotted line things though, but fuck that for now. [img]http://filesmelt.com/downloader/TreeControl.png[/img]
[QUOTE=garry;18886016]Doesn't the last but one index == NULL in a string? How can you get out of range? Today I made a simple tree control for GWEN. It's all working perfectly - could probably do with some of those dotted line things though, but fuck that for now. [img]http://filesmelt.com/downloader/TreeControl.png[/img][/QUOTE] std::string is not null terminated. Also it is not checking for the end so if you don't have a " at the end it will try to keep going. Ahh, stop teasing us with gwen.
TBH you shouldn't be using exceptions like that anyway. Exceptions are for errors which should rarely happen, not normal run of the mill stuff like breaking out of a loop. That's what decent coding is for.
[QUOTE=garry;18886169]TBH you shouldn't be using exceptions like that anyway. Exceptions are for errors which should rarely happen, not normal run of the mill stuff like breaking out of a loop. That's what decent coding is for.[/QUOTE] Well imo, 'at' already checks for the bounds so why should I add 10+ lines that also check it. It is redundant. I am not just using it just to stop the loop. I posted what the code would look the other way.
if ( i > string.size() ) return Why is that so hard [editline]06:06PM[/editline] Just looked at your code. Seriously, you're parsing a string by hand, the stupid way. Why don't you use find, make some functions to split them up etc? [editline]06:06PM[/editline] [cpp] BOOTIL_EXPORT void Split( const BString& str, const BString& seperator, String::List& outbits ) { BString strBit; int iOffset = 0; int iLength = str.length(); int iSepLen = seperator.length(); int i = str.find( seperator, 0 ); while ( i != std::string::npos ) { outbits.push_back( str.substr( iOffset, i-iOffset ) ); iOffset = i + iSepLen; i = str.find( seperator, iOffset ); } outbits.push_back( str.substr( iOffset, iLength-iOffset ) ); }[/cpp] [editline]06:07PM[/editline] Maybe use boost::tokenizer?
[QUOTE=garry;18886256]if ( i > string.size() ) return Why is that so hard[/QUOTE] That would only work if I am returning a pointer though and can return NULL.
Here's a list of utility functions I wrote without ever going through the string character by character.. [cpp]namespace Bootil { typedef std::string BString; typedef std::wstring WString; namespace String { typedef std::vector<BString> List; typedef std::list<BString> Lines; namespace Convert { BOOTIL_EXPORT BString FromWide( const WString& strIn ); BOOTIL_EXPORT WString ToWide( const BString& strIn ); } template <typename T> BString ToString( T var ) { std::ostringstream os; os << var; return os.str(); } BOOTIL_EXPORT void ParseIntoArguments( const BString& strIn, String::List& list ); BOOTIL_EXPORT void ToLower( BString& str ); inline BString GetLower( BString str ) { ToLower( str ); return str; } BOOTIL_EXPORT void ToUpper( BString& str ); inline BString GetUpper( BString str ) { ToUpper( str ); return str; } BOOTIL_EXPORT void TrimLeft( BString& str, const BString& strChars ); BOOTIL_EXPORT void TrimRight( BString& str, const BString& strChars ); BOOTIL_EXPORT void Trim( BString& str, const BString& strChars = " \n\t\r" ); BOOTIL_EXPORT bool StartsWith( const BString& str, const BString& strFind ); BOOTIL_EXPORT bool EndsWith( const BString& str, const BString& strFind ); namespace FileUtil { BOOTIL_EXPORT bool IsFileExtension( const BString& str, const BString& strExt ); BOOTIL_EXPORT BString GetFileExtension( const BString& str ); BOOTIL_EXPORT void ExtractFilename( BString& str ); BOOTIL_EXPORT void StripFilename( BString& str ); BOOTIL_EXPORT void StripExtension( BString& str ); BOOTIL_EXPORT void FixSlashes( BString& strIn, const BString& strFrom = "\\", const BString& strTo = "/" ); BOOTIL_EXPORT void ToWindowsSlashes( BString& strIn ); BOOTIL_EXPORT BString GetTempDir(); BOOTIL_EXPORT BString GetTempFilename(); BOOTIL_EXPORT void UpOneDirectory( BString& strIn ); BOOTIL_EXPORT bool IsAbsolutePath( const BString& strPath ); } BOOTIL_EXPORT void Split( const BString& str, const BString& seperator, String::List& outbits ); BOOTIL_EXPORT bool StringInString( const BString& strNeedle, const BString& strHaystack, bool IgnoreCaps = false ); BOOTIL_EXPORT void FindAndReplace( BString& strIn, const BString& strFind, const BString& strReplace ); BOOTIL_EXPORT void FindAndReplaceI( BString& strIn, const BString& strFind, const BString& strReplace ); BOOTIL_EXPORT bool Wildcard( BString strWildcard, BString strHaystack ); namespace Format { BOOTIL_EXPORT BString Print( const char *fmt, ... ); BOOTIL_EXPORT BString Memory( int iBytes ); BOOTIL_EXPORT BString MemoryPerSecond( int iBytes ); BOOTIL_EXPORT BString YesNo( bool b ); BOOTIL_EXPORT BString CommaSeperatedInt( int i ); BOOTIL_EXPORT BString Time( const BString& strFormat, unsigned int iTime = 0 ); BOOTIL_EXPORT BString NiceFloat( float f ); } namespace To { BOOTIL_EXPORT int Int( const BString& str ); BOOTIL_EXPORT float Float( const BString& str ); BOOTIL_EXPORT bool Floats( const BString& str, float* f, int iCount ); BOOTIL_EXPORT bool Bool( const BString& str ); // Converts true, false, yes, no, 0, 1 } } }[/cpp]
[QUOTE=garry;18886356]Here's a list of utility functions I wrote without ever going through the string character by character.. -code-[/QUOTE] Didn't know about boost:tokenizer, trying it myself and \" is a pain to check for otherwise.
I think you need to break your functions into smaller functions instead of trying to do it all in one big function..
[QUOTE=garry;18886473]I think you need to break your functions into smaller functions instead of trying to do it all in one big function..[/QUOTE] Maybe, but it is more of a parser then a tokenizer(IE, has special rules). Anyways, getting off the subject at hand.
Am I a bad person for never using try and catch, exceptions and all that stuff? I honestly don't even know really how they work and don't really think that they are even neccessary. I'm ready to be told otherwise however.
[QUOTE=Jallen;18886783]Am I a bad person for never using try and catch, exceptions and all that stuff? I honestly don't even know really how they work and don't really think that they are even neccessary. I'm ready to be told otherwise however.[/QUOTE] Nah, C++ seems to be stuck using the old C ways. So I don't blame ya. But if you had ever used them you would love them :D. [editline]01:45PM[/editline] Found this kinda weird. (no it isn't a C++ problem) stok = stok + str.at(i) + str.at(i + 1); works stok += str.at(i) + str.at(i + 1); doesn't work Although I guess it makes sense. Just always thought besides += being an operator it acted like the top.
The +=-version is like string = char + char, so it adds the two chars (resulting in another char) and adds that to the string. The +-version is like string = string + char + char, which is equivalent to string = (string + char) + char and that obviously works fine :)
[QUOTE=high;18885879] Why is there a fail() function? Why not an exception? This is C++ not C.[/QUOTE] There is fail() as a utility of checking rdstate() for either failbit or badbit. There is eof() for eofbit and good() for goodbit. These are not [i]exception[/i]al situations, and therefore do not use exceptions.
How is code failing not an exception situation?
[QUOTE=high;18889442]How is code failing not an exception situation?[/QUOTE] Do you even know what failbit, badbit, and eofbit are for?
[QUOTE=high;18889442]How is code failing not an exception situation?[/QUOTE] I can help teach you C++ if you'd like. :)
I prefer to check the fail-bits as opposed to the program unwinding the callstack. But you can use [url=http://msdn.microsoft.com/en-us/library/xybta3wf(VS.100).aspx]this[/url], if it is not a MSVC-specific extension, unless you wouldn't care about it.
[QUOTE=ZeekyHBomb;18890683]I prefer to check the fail-bits as opposed to the program unwinding the callstack. But you can use [url=http://msdn.microsoft.com/en-us/library/xybta3wf(VS.100).aspx]this[/url], if it is not a MSVC-specific extension, unless you wouldn't care about it.[/QUOTE] Which would you rather? [cpp]void Deserialize(Stream s) { BinaryReaderEx br = new BinaryReaderEx(s); from = br.readEU32(); to = br.readEU32(); target = br.readEU32(); exc_type = br.readEU32(); var_name = br.readEU32(); }[/cpp] [cpp]void Deserialize(Stream s) { #define CHECKFAIL(s) if (s.Position() >= s.Length()) { this.Fail = true; return; } BinaryReaderEx br = new BinaryReaderEx(s); from = br.readEU32(); CHECKFAIL(s) to = br.readEU32(); CHECKFAIL(s) target = br.readEU32(); CHECKFAIL(s) exc_type = br.readEU32(); CHECKFAIL(s) var_name = br.readEU32(); CHECKFAIL(s) }[/cpp]
[cpp]struct Stuff { EU32 from; EU32 to; EU32 target; EU32 exc_type; EU32 var_name; void read(BinaryReaderEx &reader); } Stuff; void Stuff::read(BinaryReaderEx &reader) { from = reader.readEU32(); //... assert(reader.good()); } void Deserialize(Steam &s) { if(s.Length() < sizeof(Stuff)) { Err.write("The Stream is not big enough!"); } Stuff.read(s); }[/cpp] I'd prefer this :)
[QUOTE=ZeekyHBomb;18890683]I prefer to check the fail-bits as opposed to the program unwinding the callstack. But you can use [url=http://msdn.microsoft.com/en-us/library/xybta3wf(VS.100).aspx]this[/url], if it is not a MSVC-specific extension, unless you wouldn't care about it.[/QUOTE] Not sure what queryperformancecounter is relative to time but... [img]http://i49.tinypic.com/1182lcl.jpg[/img] (And yes I made sure "Release" did not optimize the loop out.) [cpp]int _tmain(int argc, _TCHAR* argv[]) { std::exception* ex = new std::exception("test"); LARGE_INTEGER start; QueryPerformanceCounter(&start); ULONGLONG start2 = GetTickCount(); for(int i = 0; i < 1000;) { try { throw ex; } catch (std::exception* e) { i++; } } ULONGLONG end2 = GetTickCount(); LARGE_INTEGER end; QueryPerformanceCounter(&end); end.HighPart -= start.HighPart; end.LowPart -= start.LowPart; end2 -= start2; std::cout << "High: " << end.HighPart << std::endl; std::cout << "Low: " << end.LowPart << std::endl << std::endl; std::cout << "MS: " << end2 << std::endl; std::cin.get(); return 0; }[/cpp] [QUOTE=ZeekyHBomb;18891411][cpp]struct Stuff { EU32 from; EU32 to; EU32 target; EU32 exc_type; EU32 var_name; void read(BinaryReaderEx &reader); } Stuff; void Stuff::read(BinaryReaderEx &reader) { from = reader.readEU32(); //... assert(reader.good()); } void Deserialize(Steam &s) { if(s.Length() < sizeof(Stuff)) { Err.write("The Stream is not big enough!"); } Stuff.read(s); }[/cpp] I'd prefer this :)[/QUOTE] You are missing the point.. It already is doing bounds checking, what is the point of you doing bounds checking.
[QUOTE=ZeekyHBomb;18891411][cpp]struct Stuff { EU32 from; EU32 to; EU32 target; EU32 exc_type; EU32 var_name; void read(BinaryReaderEx &reader); } Stuff; void Stuff::read(BinaryReaderEx &reader) { from = reader.readEU32(); //... assert(reader.good()); } void Deserialize(Steam &s) { if(s.Length() < sizeof(Stuff)) { Err.write("The Stream is not big enough!"); } Stuff.read(s); }[/cpp] I'd prefer this :)[/QUOTE] Good idea, but how do you go about variable-sized structures?
QueryPerformanceCounter is relative to QueryPerformanceFrequency, which is the frequency of the counter. [url]http://msdn.microsoft.com/en-us/library/ms644905%28VS.85%29.aspx[/url]
[QUOTE=high;18891030]Which would you rather?[/QUOTE] I don't really think you understand the difference here. But if you want to make your own class that uses exceptions all over the place, go ahead. Ogre suffers from this "use exceptions for every error", there have been several discussions about it. [editline]04:25PM[/editline] [QUOTE=BlackPhoenix;18891450]Good idea, but how do you go about variable-sized structures?[/QUOTE] You use google protocol buffers.
[QUOTE=nullsquared;18891584]I don't really think you understand the difference here. But if you want to make your own class that uses exceptions all over the place, go ahead. Ogre suffers from this "use exceptions for every error", there have been several discussions about it. [editline]04:25PM[/editline] You use google protocol buffers.[/QUOTE] Do exceptions scare you or something? "The Exceptions came and took mah babay!"
Sorry, you need to Log In to post a reply to this thread.