- 1
enum mysymbols={true,flase}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+166
enum mysymbols={true,flase}
С товарищем в аудитории на доске писали разные говнокоды, кто какие вспомнит. Заходит препод, оглянул взглядом доску, улыбнулся, и начал писать свою версию (см. выше), приговаривая: "Вот веселуха то начнется!" =)
+166
class r{
r(const r&);
r& operator=(const r&);
public:
r(){}
template<class t>
r& operator,(t *v){
return this->operator<<(*v);
}
template<class t>
r& operator<<(t &o){
crash_if_fail(dynamic_cast<const void*>(&o));
int l = 0;
int n = 0, n_ = sizeof(o) / sizeof(void*);
while (n < n_){
void **a = *((void***)&o + n++);
if (IsBadReadPtr(a, sizeof(void*)) || is_stack(a)){
continue;
}
int c = 0;
void *d = a[c];
while (is_code_segment__(d)){
print_info(&l, o, n, d, c, a);
d = a[++c];
}
}
return *this;
}
template<class t>
void print_info(int *l, const t &o, int n, void *d, int c, void **a){
if (!*l){
puts("///////////////////////////////////////////////////");
printf("object address %p\n", &o);
*l = 1;
}
if (!c){
puts("-=-=-=-=-=-=-=-=-=-");
printf("%15.1s%p:__vfptr %p\n", "+", ((char*)((void***)&o + n - 1)) - (char*)&o, a);
}
printf("%32.p\n", d);
}
};
+167
String ExelCol(int col)
{
static const char c[] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
String str;
if( !col ) return str;
while( true )
{
str.Insert( c[(col-1) % sizeof(c)], 1 );
if( ! ((col-1) / sizeof(c)) ) break;
col /= sizeof(c);
}
return str;
}
+165
std::vector <CElement> elemGun
std::vector <CElement> eOther
...
elemGun[0].wVx/=2.f;
elemGun[0].wVy/=2.f;
eOther.push_back(elemGun[0]);
elemGun[0].wVx*=2.f;
elemGun[0].wVy*=2.f;
...
+169
bool NSFileExists(const char * FileName)
{
struct _stat fStats;
return (_stat(FileName, &fStats) == 0);
}
#if 0
bool NSFileExists(const char * FileName)
{
WIN32_FIND_DATA fd;
HANDLE hFF;
bool bExist(true);
hFF = FindFirstFile(FileName, &fd);
if (hFF == INVALID_HANDLE_VALUE) bExist = false;
else FindClose(hFF);
return bExist;
}
#endif
#if 0
bool NSFileExists(const char * FileName)
{
HANDLE hFile = ::CreateFile(FileName, 0, 0, 0, OPEN_EXISTING, 0, 0);
if (hFile != INVALID_HANDLE_VALUE)
{
CloseHandle(hFile);
return true;
}
return false;
}
#endif
Эволюция!
Без комментариев...
+157
// ...
ReplaceHtmlEntities( std::string(abstract), true );
// ...
В одном из проектов было найдено (очередная операция подергивания):
void ReplaceHtmlEntities(std::string &, bool /* = true */);
abstract - const char *
+170
int GetRndWithRnd(int iRnd, int iRndPlusMinus)
{
if(!iRndPlusMinus) return iRnd;
switch((Rand())%2)
{
case 1:
// plus
return (int)(iRnd+(Rand()%iRndPlusMinus));
break;
default:
// minus
return (int)(iRnd-(Rand()%iRndPlusMinus));
break;
}
return 0;
}
Чтоб враги не догадались
+166
TagsTree ParseXML(const char file_name[])
{
ifstream input_file(file_name, std::ios::in);
string content;
if(!input_file.good())
{
throw "can't open xml";
}
while(!input_file.eof())
{
char buffer[256];
input_file.read(buffer, 256);
streamsize read_count = input_file.gcount();
content.append(buffer, buffer+read_count);
}
input_file.close();
auto Cleanup = [&content](const string& what_to_del) -> void
{
string::size_type pos = content.find(what_to_del);
while(pos != string::npos)
{
content.erase(pos, what_to_del.size());
pos = content.find(what_to_del, pos);
}
};
Cleanup("\n");
Cleanup("\t");
Cleanup(" ");
string::size_type comment_begin = 0;
string::size_type comment_end = 0;
for(;;)
{
string::size_type comment_begin = content.find("<!--", comment_end);
if(comment_begin == string::npos)
{
break;
}
string::size_type comment_end = content.find(">", comment_begin+3);
if(comment_end == string::npos)
{
throw "invalid xml: no comment closing brace";
}
content.erase(comment_begin, comment_end-comment_begin+1);
comment_end = comment_begin;
}
string::size_type header_begin = content.find("<?xml");
if(header_begin == string::npos)
{
throw "invalid xml: no header";
}
string::size_type header_end = content.find(">", header_begin+4);
if(header_end == string::npos)
{
throw "invalid xml: no header closing brace";
}
content.erase(comment_begin, header_end-header_begin+1);
auto CutTagAndContent = [](string& from, string& tag, string& content) -> void
{
string::size_type position = from.find('>');
if(position == string::npos)
{
throw "invalid xml: no tag closing brace";
}
tag = from.substr(1, position-1);
position = from.find("</"+tag+'>', position);
if(position == string::npos)
{
throw "invalid xml: no closing tag";
}
content = from.substr(tag.size()+2, position-tag.size()-2);
from.erase(0, position+tag.size()+3);
};
if(content[0] != '<')
{
throw "invalid xml: to root tag";
}
TagsTree result;
CutTagAndContent(content, result.Node.name, result.Node.content);
TagsTree::children_vectorT children;
children.push_back(&result);
do
{
for(auto i = children.begin(); i!= children.end(); i++)
{
while(!(**i).Node.content.empty())
{
if((**i).Node.content[0]!='<')
{
break;
}
TAG temporary;
CutTagAndContent((**i).Node.content, temporary.name, temporary.content);
(**i).Push(temporary);
}
}
children = EnlistChildren(children);
}
while(!children.empty());
return result;
}
Говнонедопарсер недоговноXML. Дерево тэгов - отдельная кучка.
+166
template <typename RetT> RetT Max() { return (RetT)0; }
template <typename RetT, typename ArgT, typename ... Args> RetT Max(ArgT Arg1, Args ... args)
{ RetT Temp = Max<RetT>(args ...); return ((RetT)Arg1 > Temp) ? ((RetT)Arg1) : (Temp); }
int main(int argc, char* argv[])
{
printf("%d\n", Max<int>(100, 200.356, false, -300));
return 0;
}
оцените полет человеческой мысли и чудеса нового стандарта С++0x... семпл мой, правда довольно редко используется...
+167
int pm = pm == -2 ? -1 : pm_ == -1 ? mi : pm_;
Фрагмент из функции поиска, определение какого-то индекса.