void Test(const char *path) { DDUMP(sizeof(CppItem)); Cpp cpp; cpp.WhenError = callback(AddError); cpp.path = path; cpp.filedir = GetFileFolder(path); // cpp.include_path = cpp.filedir;//"C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Vc\\Include;C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\Include;C:\\OpenSSL-Win32\\include;C:\\u\\pgsql\\include;C:\\u\\OpenSSL-Win32\\include"; // cpp.include_path = "C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Vc\\Include;C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\Include;C:\\OpenSSL-Win32\\include;C:\\u\\pgsql\\include;C:\\u\\OpenSSL-Win32\\include"; cpp.include_path = "C:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\Vc\\Include;C:\\Program Files\\Microsoft SDKs\\Windows\\v7.0\\Include;C:\\u\\OpenSSL-Win32\\include;C:\\u\\pgsql\\include;C:\\Program Files (x86)\\MySQL\\MySQL Connector C 6.1\\include"; cpp.include_path << ";c:/u/upp.src/uppsrc"; FileIn in(path); Index<String> inc; cpp.DoCpp(in, inc); // StringStream ss(pp); // Parse(ss, Vector<String>() << "__cdecl", base, path, callback(AddError)); DLOG("======================="); DUMPC(inc); DLOG("======================="); DUMPC(errs); DLOG("======================="); Qualify(cpp.base); String out; for(int i = 0; i < cpp.base.GetCount(); i++) { out << Nvl(cpp.base.GetKey(i), "<globals>") << " {\n"; const Array<CppItem>& ma = cpp.base[i]; for(int j = 0; j < ma.GetCount(); j++) { const CppItem& m = ma[j]; out << '\t' << CppItemKindAsString(m.kind) << ' ' << m.qitem << ' ' << m.line << "\n"; // DDUMP(StoreAsString(const_cast<CppItem&>(m)).GetCount()); } out << "}\n"; } LOG(out); }
void ContainerClientTypes() { /// .Client types in U++ containers /// So far we were using int as type of elements. In order to store client defined types /// into the `Vector` (and the Vector ^topic://Core/src/Overview$en-us:flavor^) the type /// must satisfy ^topic://Core/src/Moveable$en-us:moveable^ requirement - in short, it must /// not contain back-pointers nor virtual methods. Type must be marked as %moveable% in /// order to define interface contract using `Moveable` /// ^https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern:CRTP idiom^: struct Distribution : Moveable<Distribution> { String text; Vector<int> data; String ToString() const { return text + ": " + AsString(data); } }; /// Now to add `Distribution` elements you cannot use `Vector::Add(const T&)`, because it requires /// elements to have default deep-copy constructor - and `Distribution does not have one, as /// `Vector<int>` has default pick-constructor, so Distribution itself has pick-constructor. /// It would no be a good idea either, because deep-copy would involve expensive copying of /// inner Vector. /// Instead, Add without parameters has to be used - it default constructs (that is cheap) /// element in Vector and returns reference to it: Vector<Distribution> dist; for(int n = 5; n <= 10; n++) { Distribution& d = dist.Add(); d.text << "Test " << n; for(int i = 0; i < 10000; i++) d.data.At(Random(n), 0)++; } DUMPC(dist); /// Another possibility is to use `Vector::Add(T&&)` method, which uses pick-constructor /// instead of deep-copy constructor. E.g. `Distribution` elements might be generated by /// some function: #if 0 Distribution CreateDist(int n); /// and code for adding such elements to Vector then looks like: for(n = 5; n <= 10; n++) dist.Add(CreateDist(n)); /// alternatively, you can use default-constructed variant too dist.Add() = CreateDist(); #endif /// }
static bool check_dump(void) { DCHECK; DUMPC('a'); DUMPP(&check_dump); DUMPS(__FUNCTION__); DUMPD((uint64_t)(-1)); DUMPZ((uint64_t)(-1)); DUMP8((uint64_t)(-1)); DUMP16((uint64_t)(-1)); DUMP32((uint64_t)(-1)); DUMP64((uint64_t)(-1)); return true; }
void PPFile::Dump() const { for(int i = 0; i < item.GetCount(); i++) { const PPItem& m = item[i]; String ll; ll << decode(m.type, PP_DEFINES, "#defines ", PP_INCLUDE, "#include ", PP_USING, "using namespace ", PP_NAMESPACE, "namespace ", PP_NAMESPACE_END, "}", ""); if(m.type == PP_DEFINES) ll << m.segment_id; else ll << m.text; if(m.type == PP_NAMESPACE) ll << " {"; LOG(ll); } LOG("----- includes:"); DUMPC(includes); }
void class_stats() { printf("InUse\n"); class_printList(class_inuse); printf("NoUse\n"); class_printList(class_nouse); printf("Counters:\n"); #define DUMPC(x) printf(" %10s : %d\n",#x,class_counters.x) DUMPC(malloc); DUMPC(calloc); DUMPC(realloc); DUMPC(free); DUMPC(gc); DUMPC(nomem); #undef DUMPC }
KissFFTTest::KissFFTTest() { CtrlLayout(*this, "Window title"); #if _DIRECT_KISSFFT_MEANS kiss_fft_cpx sin[N]; kiss_fft_cpx sout[N]; for(int i=0; i<N; i++) { sin[i].r = (kiss_fft_scalar)0; sin[i].i = (kiss_fft_scalar)0; } sin[0].r = (kiss_fft_scalar)1; kiss_fft_cfg st = kiss_fft_alloc(N,0,0,0); kiss_fft(st,sin,sout); kiss_fft_free(st); print_buffs(sin, sout, N); RLOG(""); st = kiss_fft_alloc(N,1,0,0); kiss_fft(st,sout,sin); kiss_fft_free(st); //apply scale double sc = 1./N; for(int i = 0; i < N; i++) { sin[i].r *= sc, sin[i].i *= sc; } print_buffs(sout, sin, N); #else //USING UPP STRUCTURES #ifdef CD Vector<Complex> vt, vf; #else Vector<kiss_fft_cpx> vt, vf; #endif vt.SetCount(N); //in vf.SetCount(N); //out #ifdef CD vt[0] = Complex(1.); #else for(int i=0; i<N; i++) { vt[i].r = (kiss_fft_scalar)0, vt[i].i = (kiss_fft_scalar)0; } vt[0].r = (kiss_fft_scalar)1; #endif RLOG("fw fft"); { KissFFT fft(N); fft(vf, vt); } #ifdef CD DUMPC(vt); DUMPC(vf); #else print_buffs((const kiss_fft_cpx*)vt, (const kiss_fft_cpx*)vf, N); #endif RLOG("bw fft"); { KissFFT fft(N,true); fft(vt, vf); } double sc = 1./N; #ifdef CD for(int i = 0; i < vt.GetCount(); i++) vt[i] *= sc; DUMPC(vf); DUMPC(vt); #else for(int i = 0; i < vt.GetCount(); i++) { vt[i].r *= sc, vt[i].i *= sc; } print_buffs((const kiss_fft_cpx*)vf, (const kiss_fft_cpx*)vt, N); #endif #endif }
void Logging() { ///. Logging /// Logging is a useful technique to trace the flow of the code and examine results. In /// this tutorial we will be using logging extensively, so let us start tutorial with the /// explanation of logging. /// In debug mode and with default settings, macro `LOG` puts string into output log file. /// Log file is placed into 'config-directory', which by default is .exe directory in Win32 /// and ~/.upp/appname in POSIX. /// In TheIDE, you can access the log using 'Debug'/'View the log file Alt+L'. LOG("Hello world"); /// You can log values of various types, as long as they have `AsString` function defined /// You can chain values in single `LOG` using `operator<<`: int x = 123; LOG("Value of x is " << x); /// As it is very common to log a value of single variable, `DUMP` macro provides a useful /// shortcut, creating a log line with the variable name and value: DUMP(x); /// To get the value in hexadecimal code, you can use `LOGHEX` / `DUMPHEX` DUMPHEX(x); String h = "foo"; DUMPHEX(h); /// To log the value of a container (or generic Range), you can either use normal /// `LOG` / `DUMP`: Vector<int> v = { 1, 2, 3 }; DUMP(v); /// or you can use DUMPC for multi-line output: DUMPC(v); /// For maps, use DUMPM: VectorMap<int, String> map = { { 1, "one" }, { 2, "two" } }; DUMP(map); /// DUMPM(map); /// All normal `LOG`s are removed in release mode. If you need to log things in release mode, /// you need to use `LOG`/`DUMP` variant with '`R`' prefix (`RLOG`, `RDUMP`, `RDUMPHEX`...): RLOG("This will be logged in release mode too!"); /// Sort of opposite situation is when adding temporary `LOG`s to the code for debugging. In /// that case, '`D`' prefixed variants (`DLOG`, `DDUMP`, `DDUMPHEX`...) are handy - these cause /// compile error in release mode, so will not get forgotten in the code past the release: DLOG("This would not compile in release mode."); /// The last flavor of `LOG` you can encounter while reading U++ sources is the one prefixed /// with '`L`'. This one is not actually defined in U++ library and is just a convention. On /// the start of file, there is usually something like: #define LLOG(x) // DLOG(x) /// and by uncommenting the body part, you can activate the logging in that particular file. /// While logging to .log file is default, there are various ways how to affect logging, /// for example following line adjusts logging to output the log both to the console and /// .log file: #if 0 StdLogSetup(LOG_COUT|LOG_FILE); #endif /// }