Can file name, module name, class name and variable name be the same?

2016-01-17 Thread WhatMeWorry via Digitalmars-d-learn


file 1: camera.d
---
module camera;
class Camera
{
public:
// Camera Attributes
vec3 position = vec3(0.0f, 0.0f, 0.0f);
. . .
};
---


file 2: main.d
---
module main;
import camera;
Camera camera;  // Compile error (1)
---

(1) variable main.camera conflicts with import main.camera at 
main.d(30)


Renaming "Camera camera;" to "Camera cam;" gets rid of the error
but now I've got tons of new undefined references with camera.

Have I broken some rule by having file name, module name, class 
name and object name
being all cameras?   Is there some technique I can use to get 
Camera camera; to compile?


I can workaround the problem but it seems like a kludge; I'm 
curious about the subtleties of this problems.




Re: core.time Duration how to get units in double/float format?

2016-01-17 Thread Borislav Kosharov via Digitalmars-d-learn

On Sunday, 17 January 2016 at 18:57:13 UTC, biozic wrote:
On Sunday, 17 January 2016 at 14:43:26 UTC, Borislav Kosharov 
wrote:
Seeing that TickDuration is being deprecated and that I should 
use Duration instead, I faced a problem. I need to get total 
seconds like a float. Using .total!"seconds" returns a long 
and if the duration is less than 1 second I get 0. My question 
is whats the right way to do it. Because I saw that 
TickDuration has a to!("seconds", float) method, but Duration 
doesn't have one. I can convert Duration to TickDuration and 
call to but seeing that its deprecated makes me think there is 
a better way.


Why not just use a smaller granularity for Duration.total and 
convert the result?


duration.total!"nsecs" / cast(float) 1e9


Yea I could do that, but its not intuitive to get a total of one 
magnitude to just convert it to another. My question is why 
doesn't `to!` accept Duration.




Re: DUB - link error on Windows 10 64-bit

2016-01-17 Thread Dibyendu Majumdar via Digitalmars-d-learn

On Sunday, 17 January 2016 at 03:07:39 UTC, Mike Parker wrote:



Have you verified that this is the only DMD installation on 
your path?


Looks like the problem is not in dub - but the fact that a shared 
library in D requires a DllMain - as described in:


http://forum.dlang.org/post/eokrmosskwelrcyfk...@forum.dlang.org

So the DMD compiler is basically failing as I do not have a 
DllMain.


Regards


Re: Functions that return type

2016-01-17 Thread data pulverizer via Digitalmars-d-learn

On Sunday, 17 January 2016 at 02:08:06 UTC, Timon Gehr wrote:

On 01/16/2016 11:50 PM, data pulverizer wrote:

I guess the constraints are that of a static language.


(This is not true.)


Could you please explain?


Re: core.time Duration how to get units in double/float format?

2016-01-17 Thread biozic via Digitalmars-d-learn
On Sunday, 17 January 2016 at 14:43:26 UTC, Borislav Kosharov 
wrote:
Seeing that TickDuration is being deprecated and that I should 
use Duration instead, I faced a problem. I need to get total 
seconds like a float. Using .total!"seconds" returns a long and 
if the duration is less than 1 second I get 0. My question is 
whats the right way to do it. Because I saw that TickDuration 
has a to!("seconds", float) method, but Duration doesn't have 
one. I can convert Duration to TickDuration and call to but 
seeing that its deprecated makes me think there is a better way.


Why not just use a smaller granularity for Duration.total and 
convert the result?


duration.total!"nsecs" / cast(float) 1e9




copying directories recursively

2016-01-17 Thread anonymous via Digitalmars-d-learn

TL;DR: Is there a simple way to copy directories recursively?

My goal is to copy the directories ./src/dlang.org/{css,images,js} and 
their contents to ./ddo/{css,images,js}.


Naively I tried this:


void main()
{
import file = std.file;
auto outputPath = "./ddo/";
foreach (dir; ["css", "images", "js"])
{
file.copy("./src/dlang.org/" ~ dir, outputPath ~ dir);
}
}


But that fails with "std.file.FileException@std/file.d(3154): 
src/dlang.org/css: Is a directory".


`copy` doesn't have a parameter to enable copying directories, and I 
can't find any `copyDir` or `copyRecurse` or some such.


As it looks I'll end up implementing my own `copyRecurse`:


void copyRecurse(string from, string to)
{
import std.file: copy, dirEntries, isDir, isFile, mkdirRecurse, 
SpanMode;

import std.path: buildNormalizedPath, buildPath;

from = buildNormalizedPath(from);
to = buildNormalizedPath(to);

if (isDir(from))
{
mkdirRecurse(to);

auto entries = dirEntries(from, SpanMode.breadth);
foreach (entry; entries)
{
auto dst = buildPath(to, entry.name[from.length + 1 .. $]);
// + 1 for the directory separator
if (isFile(entry.name)) copy(entry.name, dst);
else mkdirRecurse(dst);
}
}
else copy(from, to);
}


Is there a simpler way to do this?


Re: DUB - link error on Windows 10 64-bit

2016-01-17 Thread bachmeier via Digitalmars-d-learn

On Sunday, 17 January 2016 at 02:48:47 UTC, Mike Parker wrote:
On Saturday, 16 January 2016 at 20:28:02 UTC, Dibyendu Majumdar 
wrote:




I have installed DMD by unzipping the DMD archive (The 
installer does not work correctly on Windows 10). DUB 
installed as normal.


What problem did you have with the installer? Which version? 
I've installed DMD more than once on Windows 10 and it worked 
flawlessly.


I also installed on Windows 10 (a few days ago) and it worked. I 
could not get the installer to work, though, so I unzipped the 
archive like OP. Is it the case that Windows 10 is an uncommon 
target for DMD?


std.zip for Binary example

2016-01-17 Thread locco via Digitalmars-d-learn

Hi :)
I found this example:
==
import std.file: write;
import std.string: representation;
void main()
{
   char[] data = "Test data.\n".dup;
   // Create an ArchiveMember for the test file.
   ArchiveMember am = new ArchiveMember();
   am.name = "test.txt";
   am.expandedData(data.representation);
   // Create an archive and add the member.
   ZipArchive zip = new ZipArchive();
   zip.addMember(am);
   // Build the archive
   void[] compressed_data = zip.build();
   // Write to a file
   write("test.zip", compressed_data);
}
==
But i cound't find example code for binary file.
How can i make ArciveMember for binary file?


Re: std.zip for Binary example

2016-01-17 Thread Sean Campbell via Digitalmars-d-learn

On Sunday, 17 January 2016 at 10:34:19 UTC, locco wrote:

Hi :)
I found this example:
==
import std.file: write;
import std.string: representation;
void main()
{
   char[] data = "Test data.\n".dup;
   // Create an ArchiveMember for the test file.
   ArchiveMember am = new ArchiveMember();
   am.name = "test.txt";
   am.expandedData(data.representation);
   // Create an archive and add the member.
   ZipArchive zip = new ZipArchive();
   zip.addMember(am);
   // Build the archive
   void[] compressed_data = zip.build();
   // Write to a file
   write("test.zip", compressed_data);
}
==
But i cound't find example code for binary file.
How can i make ArciveMember for binary file?



std.zip dosen't discriminate against text and binary files files.
p.s. remember to import std.zip



core.time Duration how to get units in double/float format?

2016-01-17 Thread Borislav Kosharov via Digitalmars-d-learn
Seeing that TickDuration is being deprecated and that I should 
use Duration instead, I faced a problem. I need to get total 
seconds like a float. Using .total!"seconds" returns a long and 
if the duration is less than 1 second I get 0. My question is 
whats the right way to do it. Because I saw that TickDuration has 
a to!("seconds", float) method, but Duration doesn't have one. I 
can convert Duration to TickDuration and call to but seeing that 
its deprecated makes me think there is a better way.