Re: How to translate this C++ preprocessor declaration in D?
Guys, i also did a templated version that yields the same output as the C++ program: import std.stdio; template makeId(char[4] id) { const makeId = id[0] << 24 | id[1] << 16 | id[2] << 8 | id[3]; } const kPIHostBlendModeSignature = makeId!("8BIM"); const PIPowerPCCarbonCodeProperty = makeId!("ppcb"); const PIPowerPCMachOCodeProperty = makeId!("mach"); const PICodeMacIntel32Property = makeId!("mi32"); const PICodeMacIntel64Property = makeId!("mi64"); void main() { writefln(kPIHostBlendModeSignature); writefln(PIPowerPCCarbonCodeProperty); writefln(PIPowerPCMachOCodeProperty); writefln(PICodeMacIntel32Property); writefln(PICodeMacIntel64Property); } Thanks for your help.
Re: Problem with object understanding and datatypes
On Saturday, 25 May 2013 at 01:03:53 UTC, Namal wrote: 255 - 129 is less than 128 so the result is T.max, which is 255, which is not equal to 0. I dont understand this at all 255 - 129 should be 126 in ubyte or not? I checked, and operation between two ubyte is an int. When you cast that int to ubyte, it gets its least significant byte represented as ubyte. import std.stdio; void main() { ubyte x = 128; ubyte y = 129; writeln(cast(ubyte)(x - y)); //prints 255 writeln(x - y); //prints -1 writeln(typeof(x - y).stringof); //prints 'int' } Also, I tried the code you pasted, and the reason it fails the asserts is that there's something wrong in the if conditions in opBinary (and also, that 'rhs.max - rhs._value' didn't compile). The following makes your asserts pass: ... static if (op == "-") { if(_value < rhs._value) return rhs.min; } static if (op == "+") { if(_value > max._value - rhs._value) return rhs.max; } ... --jm
Re: How to translate this C++ preprocessor declaration in D?
Ali Çehreli: If the multi-character literals are evaluated big-endian as Luís Marques and I guess, then you can use the following code: Also, D defines version(BigEndian) and version(LittleEndian). Bye, bearophile
Re: How to translate this C++ preprocessor declaration in D?
On 05/24/2013 05:49 PM, Heinz wrote: If it really has single quotes then it is a multi-character literal, value of which happens to be implementation-dependent. What is actually in place of asdf there? May be we can guess the intent better. Ali Here're some examples: #definekPIHostBlendModeSignature'8BIM' #define PIPowerPCCarbonCodeProperty'ppcb' #define PIPowerPCMachOCodeProperty'mach' #define PICodeMacIntel32Property'mi32' #define PICodeMacIntel32Property'mi64' I'm porting the Photoshop SDK (CS6) to D. I already compiled a hybrid plugin with DMC and DMD (it works) but now i want to make native D plugins. I took liberty in renaming the last one of those macros. ;) If the multi-character literals are evaluated big-endian as Luís Marques and I guess, then you can use the following code: import std.stdio; uint makeId(string s) { uint result = 0; foreach (c; s) { result <<= 8; result += c; } return result; } enum kPIHostBlendModeSignature = makeId("8BIM"); enum PIPowerPCCarbonCodeProperty = makeId("ppcb"); enum PIPowerPCMachOCodeProperty = makeId("mach"); enum PICodeMacIntel32Property = makeId("mi32"); enum PICodeMacIntel64Property = makeId("mi64"); void main() { writeln(kPIHostBlendModeSignature); writeln(PIPowerPCCarbonCodeProperty); writeln(PIPowerPCMachOCodeProperty); writeln(PICodeMacIntel32Property); writeln(PICodeMacIntel64Property); } It produces the same output as the following C++ program on my system: #include using namespace std; #definekPIHostBlendModeSignature'8BIM' #define PIPowerPCCarbonCodeProperty'ppcb' #define PIPowerPCMachOCodeProperty'mach' #define PICodeMacIntel32Property'mi32' #define PICodeMacIntel64Property'mi64' int main() { cout << kPIHostBlendModeSignature << '\n' << PIPowerPCCarbonCodeProperty << '\n' << PIPowerPCMachOCodeProperty << '\n' << PICodeMacIntel32Property << '\n' << PICodeMacIntel64Property << '\n'; } Ali
Re: Problem with object understanding and datatypes
255 - 129 is less than 128 so the result is T.max, which is 255, which is not equal to 0. I dont understand this at all 255 - 129 should be 126 in ubyte or not?
Re: How to translate this C++ preprocessor declaration in D?
If it really has single quotes then it is a multi-character literal, value of which happens to be implementation-dependent. What is actually in place of asdf there? May be we can guess the intent better. Ali Here're some examples: #define kPIHostBlendModeSignature '8BIM' #define PIPowerPCCarbonCodeProperty 'ppcb' #define PIPowerPCMachOCodeProperty 'mach' #define PICodeMacIntel32Property'mi32' #define PICodeMacIntel32Property'mi64' I'm porting the Photoshop SDK (CS6) to D. I already compiled a hybrid plugin with DMC and DMD (it works) but now i want to make native D plugins.
Re: How to translate this C++ preprocessor declaration in D?
On 05/24/2013 05:02 PM, Heinz wrote: Hi, I'm porting a C++ header (i'm not a C++ programmer) and came with the following declaration: #define my_id 'asdf' How does this translate to D? Thanks If it really has single quotes then it is a multi-character literal, value of which happens to be implementation-dependent. What is actually in place of asdf there? May be we can guess the intent better. Ali
Re: How to translate this C++ preprocessor declaration in D?
I remember that there was a smarter way to do this, but you can do it manually. Something like: immutable long my_id = 'a' << 24 + 'b' << 16 + 'c' << 8 + 'd'; Or you can create a CTFE function to do this from a string, which should be nicer, if you don't find an existing utility for this.
Re: How to translate this C++ preprocessor declaration in D?
On Saturday, 25 May 2013 at 00:07:02 UTC, Luís Marques wrote: On Saturday, 25 May 2013 at 00:02:50 UTC, Heinz wrote: #define my_id 'asdf' Ah, sorry, didn't notice the single quotes.
Re: How to translate this C++ preprocessor declaration in D?
On Saturday, 25 May 2013 at 00:02:50 UTC, Heinz wrote: #define my_id 'asdf' string my_id = "asdf";
How to translate this C++ preprocessor declaration in D?
Hi, I'm porting a C++ header (i'm not a C++ programmer) and came with the following declaration: #define my_id 'asdf' How does this translate to D? Thanks
Re: equivalent of __attribute__((constructor))
On 05/23/2013 11:39 PM, Jacob Carlborg wrote: On 2013-05-24 02:02, Ellery Newcomer wrote: posix.mak makes no reference to it Then I guess it's not used. Just compile it manually and link with it. I don't think that D has anything corresponding to __attribute__((constructor)). I also see a problem with adding such feature. It will be run before the runtime is initialized (that's how it works now). Then people will start using it and complain about there code failing in mysterious ways because the runtime isn't initialized. so don't document it :)
Re: deducing function/delegate in template method
On Friday, 24 May 2013 at 22:37:49 UTC, Luís Marques wrote: foo.addHandlers(delegate (int x) { /* if no scope access deduction fails */ }); (I meant that deduction would fail if the literal was not marked as a delegate)
deducing function/delegate in template method
In this code: // accepts a list of handlers, for the respective types void addHandlers(T...)(T handlers) { foreach(handler; handlers) { addHandler(handler); } } // accepts one handler, for type T void addHandler(T)(void delegate (T) handler) { ... } ... foo.addHandler((int x) { /* always deduced as delegate */ }); foo.addHandlers(delegate (int x) { /* if no scope access deduction fails */ }); If I call addHandler with a function/delegate literal then DMD deduces that the literal has to be a delegate, but if I call addHandlers then I have to explicitly mark my function/delegate literal as a delegate, otherwise the template match will fail if the function/delegate literal does not access something from its scope. Couldn't DMD also deduce this correctly in this case? Also, how can I change addHandler to accept delegates with heterogeneous varargs? Something like: void addHandler(T...)(void delegate (T...) handler); so that I can do: foo.addHandler((int x, float y) { });
Re: Problem with object understanding and datatypes
On 05/24/2013 01:19 PM, Namal wrote: > if(rhs.max - rhs._value < _value) I had a compilation error so I had to change that line to the following: if(T.max - rhs._value < _value){ > assert(subyte(128) - subyte(129) == subyte(0)); > } > > But the last test does not pass. 255 - 129 is less than 128 so the result is T.max, which is 255, which is not equal to 0. > Why does the minus operation is treated in signed datatype, while + is > unsigned? I don't think that is happening at all but the rules can get pretty confusing. See "Integer Promotions" and "Usual Arithmetic Conversions" should be known in general: :) http://dlang.org/type.html Ali
Problem with object understanding and datatypes
So the task is to write a struct object for the saturation arithmetic. I tried first to write it for the unsigned Types: struct Saturated(T) if (isIntegral!T) { static assert (isUnsigned!T || isSigned!T); @property { static Saturated min() { return Saturated(T.min); } static Saturated max() { return Saturated(T.max); } static Saturated init() { return Saturated(T.init); } } Saturated opBinary(string op)(const Saturated rhs) const if (op == "+" || op == "-" || op == "/") { static if (isUnsigned!T){ if(rhs.max - rhs._value < _value) return rhs.max; if(rhs._value > _value) return rhs.min; return Saturated(cast(T)(mixin("_value " ~ op ~ " rhs._value"))); } else{ return Saturated(cast(T)(mixin("_value " ~ op ~ " rhs._value"))); } } string toString() const { import std.conv; return to!string(_value); } private: T _value; } unittest { alias subyte = Saturated!ubyte; assert(subyte(254) + subyte(2) == subyte(255)); assert(subyte(100) + subyte(2) == subyte(102)); assert(subyte(10) - subyte(11) == subyte(0)); assert(subyte(128) - subyte(129) == subyte(0)); } But the last test does not pass. Why does the minus operation is treated in signed datatype, while + is unsigned? Note that I do not know much about templates or methods. So pls execuse me if I do a major mistake here.
Re: Dispatching values to handlers, as in std.concurrency
On Tuesday, 7 May 2013 at 06:19:24 UTC, Idan Arye wrote: If it's not templated - make it templated! You don't have to make the entire `TypeHanler` templated, just the method that creates it. There, you can create an anonymous function that receives `Object` and returns `bool` and all it does is check for type, and you can have a field in `TypeHandler` that keeps that function and uses it to check if it can handle a certain type. Thanks. It took me a while to understand what you meant, but it's working.
Re: equivalent of __attribute__((constructor))
Am Wed, 22 May 2013 21:27:00 -0700 schrieb Ellery Newcomer : > In the context of shared libraries, with gcc > > __attribute__((constructor)) > void myfunc() { .. } > > is used to make myfunc be called upon loading of the shared library > (you can tell I know what I am talking about here) via some field in > the ELF headers, apparently. Is there any way to get our trusty d > compilers to do the equivalent? > > Sure, Ellery, we have this awesome feature called module > constructors. Check em out. > > Ehh, I would be using this to initialize druntime... > > You could just define _init, couldn't you? > > Yes, but there is only one _init, while the above can be used with > multiple functions and thus wouldn't inadvertently cause important > code to not run. If I don't have to, I'd rather not. > > Wait, why are you initializing druntime? > > Because druntime isn't set up to do it yet for c main calling d > shared lib. You'd think it would need the same sort of functionality > when it does implement it, though. LDC has got #pragma(LDC_global_crt_[c/d]tor) for this, see http://wiki.dlang.org/LDC-specific_language_changes#Pragmas We will at some point implement something similar in gdc. I don't know about dmd though.
Re: What xml libraries are people using?
Am 02.03.2013 09:03, schrieb simendsjo: Everyone says "Don't use std.xml", and there are several other libraries. Which can you recommend? (I haven't looked closely at any of them, just some links found by googling) https://github.com/adamdruppe/misc-stuff-including-D-programming-language-web-stuff/blob/master/dom.d http://svn.dsource.org/projects/xmlp/trunk/std/ https://github.com/theredhead/red.xml https://github.com/opticron/kxml https://github.com/opticron/libdxml2 https://launchpad.net/d2-xml I'm using a port of tinyxml I did myself: https://github.com/Ingrater/thBase/blob/master/src/thBase/tinyxml.d Kind Regards Benjamin Thaut
Re: Passing large or complex data structures to threads
On 05/24/2013 06:26 AM, Joseph Rushton Wakeling wrote: > Are there any recommended strategies for passing large or complex data > structures (particularly reference types) to threads? std.concurrency works with shared data. > For the purpose of this discussion we can assume that it's read-only > data The following simple example uses mutable data but it should work with 'const' too. import std.stdio; import std.concurrency; import std.typecons; import core.thread; alias DataElement = Tuple!(size_t, size_t); alias DataRow = DataElement[]; alias Data = DataRow[]; enum size_t totalRows = 4; void func(Tid owner, shared(Data) data, size_t rowId) { foreach (ref element; data[rowId]) { element[0] *= 10; element[1] *= 10; } } shared(Data) makeData() { shared(Data) data; foreach (size_t row; 0 .. totalRows) { shared(DataRow) dataRow; foreach (size_t col; 0 .. 10) { dataRow ~= tuple(row, col); } data ~= dataRow; } return data; } void main() { shared(Data) data = makeData(); writeln("before: ", data); foreach (rowId, row; data) { // Instead of 'data' and 'rowId', the child could take // its own row (not tested) spawn(&func, thisTid, data, rowId); } thread_joinAll(); writeln("after : ", data); } Ali
Re: class MyClass(T) : Base if (ConstraintExpression) {} compilation error
On Friday, 24 May 2013 at 14:49:24 UTC, ref2401 wrote: Version D 2.062 Please explain what is causing the error class Base { } class Class(T) : Base if (is(T == int)) { } Error: unrecognized declaration Error: members expected Error: Declaration expected, not 'if' Error: { } expected following aggregate declaration because dmd acts as grammar nazi: ClassTemplateDeclaration: class Identifier ( TemplateParameterList ) Constraintopt BaseClassListopt ClassBody
Re: class MyClass(T) : Base if (ConstraintExpression) {} compilation error
On 2013-05-24, 16:49, ref2401 wrote: Version D 2.062 Please explain what is causing the error class Base { } class Class(T) : Base if (is(T == int)) { } Error: unrecognized declaration Error: members expected Error: Declaration expected, not 'if' Error: { } expected following aggregate declaration I'm confused too. This works: class Base { } class Class(T) if (is(T == int)) : Base { } void foo() { Base a = new Class!int; } -- Simen
class MyClass(T) : Base if (ConstraintExpression) {} compilation error
Version D 2.062 Please explain what is causing the error class Base { } class Class(T) : Base if (is(T == int)) { } Error: unrecognized declaration Error: members expected Error: Declaration expected, not 'if' Error: { } expected following aggregate declaration
Re: Passing large or complex data structures to threads
On 2013-05-24, 15:26, Joseph Rushton Wakeling wrote: Hello all, Are there any recommended strategies for passing large or complex data structures (particularly reference types) to threads? For the purpose of this discussion we can assume that it's read-only data, so if we're talking about just an array (albeit perhaps a large one) I guess just passing an .idup copy would be best. However, the practical situation I have is a data structure of the form, Tuple!(size_t, size_t)[][] ... which I _could_ .idup, but it's a little bit of a hassle to do so, so I'm wondering if there are alternative ways or suggestions. First, *is* it read-only? If so, store it as immutable and enjoy free sharing. If not, how and why not? -- Simen
Re: What xml libraries are people using?
On Saturday, 2 March 2013 at 18:42:13 UTC, Andrej Mitrovic wrote: On 3/2/13, simendsjo wrote: Which can you recommend? I use ae's lite xml library: https://github.com/CyberShadow/ae/blob/master/utils/xmllite.d It's not a monster but thanks to UFCS I can easily extend it to do what I want. For some trivial xml parsing which I needed it was great (OTOH std.xml is a segfaulting monster). Has anyone got any examples of using this library? Reading nodes, attributes etc.
Passing large or complex data structures to threads
Hello all, Are there any recommended strategies for passing large or complex data structures (particularly reference types) to threads? For the purpose of this discussion we can assume that it's read-only data, so if we're talking about just an array (albeit perhaps a large one) I guess just passing an .idup copy would be best. However, the practical situation I have is a data structure of the form, Tuple!(size_t, size_t)[][] ... which I _could_ .idup, but it's a little bit of a hassle to do so, so I'm wondering if there are alternative ways or suggestions. The actual way I found to "solve" this problem (for now) was that, since the data in question is loaded from a file, I just got each thread to load the file separately. However, this runs into a different problem -- the function(s) required to load and interpret the file may vary, and may require different input, which requires manual rewriting of the thread function when it needs to be changed (it's a tolerable but annoying solution). I guess I could solve this by passing the thread a delegate, or maybe employ mixins ... ? Anyway, I thought I'd throw the question open in case others can suggest better ideas! Thanks & best wishes, -- Joe
Convert 1080/60p AVCHD Videos to Mac FCP Compatible 1080/60p ProRes
Convert 1080/60p AVCHD Videos to Mac FCP Compatible 1080/60p ProRes AVCHD to 1080/60p ProRes 422 (HQ) Converter - Panasonic HS700 to FCP Do you face any problem when trying to import the 1080/60p or 180/50p AVCHD videos from Panasonic HDC-HS700 to Final Cut Studio? In the Panasonic HS700 camera manual, you may find the page 129 of the instruction manual says 1080/60p cannot be imported to a mac. Not to say to log and transfer the 1080/60p files to FCP. Apple ProRes 422 will be the intermediate codec for FCP to transcode from the supported 1080i videos. However, for the unsupported 1080/60p or 1080/50p AVCHD videos, it would be perfect to get Apple ProRes 422 (HQ) for Final Cut Pro. Aunsoft Video Converter for Mac is the recommended AVCHD to 1080/60p ProRes 422 (HQ) converter on Mac OS X to edit videos in highest quality like uncompressed and lossless videos. Below is the simple step-by-step guide for camcorder and camera users about how to keep and maintain 1080p 60fps/50fps from Panasonic HS700 to ProRes 422 (HQ) for FCP. Step 1. Download HS700 files to AVCHD MTS/M2TS to FCP Converter for Mac. Run Aunsoft Video Converter for Mac as the best Panasonic HS700 AVCHD videos to Apple ProRes 422 converter, click the "Add" button to import .mts files from the camcorder folder like AVCHD > BDMV > STREAM. Step 2. Choose ProRes 422 (HQ) codec. Click the "Format" option, and navigate to Final Cut Pro > Apple ProRes 422(HQ) (*.mov) as output format. The Mac 1080/60p video converter will transcode AVCHD .mts files to ProRes 422 (HQ) .mov. As the AVCHD 1080/60p video is with high data rate, it is recommended to use Apple ProRes 422 (HQ) as output codec, instead of Apple ProRes 422 (LT), Apple ProRes 422 (Proxy). The alternative codec is Apple ProRes 422, which includes lower data rate than the HQ codec. Step 3. Choose 1080p size with 60 or 50fps. Click the "Settings" button and choose 1920*1080 from the video size drop-down box to keep the original HD resolution. Click the drop-down box for frame rate, and choose 60fps or 50fps as output video frame rate. The frame rate option depends on your source videos in NTSC or PAL model. Click the OK button to save the changes and the Mac AVCHD video converter will convert 1080/60p AVCHD videos to Mac FCP compatible 1080/60p ProRes 422 native format. Step 4. Convert HS700 1080/60p to ProRes 422 HQ on Mac for FCP. Click the convert button under the preview window, and the Mac HS700 AVCHD to FCP native format converter will start converting HD 1080 to 1080/60p for FCP on Mac Non-linear editing. Hope you enjoy the steps above to get Panasonic HS700 1080p 60fps/50fps to ProRes 422 (HQ) for Final Cut Pro , Final Cut Pro 7, Final Cut Studio. Tips: 1. To get videos and audio in perfect sync, you shall install Final Cut Pro before choosing the Apple ProRes 422 and other profiles under the Final Cut Pro group in Aunsoft Video Converter.