Using a class function to find a file, and include it so the class in that file can be used - class

So far this one seems to go against the grain of Php OOP. Let me explain further with an example.
class main has a function called get($name), what I would like get to do is based on the value of $name, (e.g. 'path/file') would find the corresponding file and include it, so the class in path/file can be used.
My goal with this and the reason I want to do this, is when I call $main->get('path/file'), I'd like an object returned of the class within the file, so far the only solution I can figure out is to use
include($main->get('path/file'));
And within said file would be an object defined outside the class body within path/file.php, but that doesn't really solve the issue as it limits me to using the object defined in that file, and I can only use this include call outside a class body. Does anyone have any ideas on how this can be approached?

Related

In C++, how can I create an instance of zoned_time as a class member?

I'm new to C++ and am exploring the use of timezones in chrono, specifically zoned_time.
I have only one issue with it: I want to use an instance of zoned_time as a member in a class, but no matter how I alter the syntax, the compiler doesn't like it.
#include <chrono>
#pragma once
class Event
{
private:
std::chrono::zoned_time tz;
public:
Event();
};
I've created a header file containing the code above, but it says the argument list for the class template is missing. I assume that means it wants me to initialize it, but I don't want to because it's a header file. As I said, I messed around quite a bit with the syntax of tz, combined with a good bit of research. Unfortunately, since I'm new to the language I really don't know what to look for online.
So my goal here is to be able to create a typed container within Event which will store the zoned_time information. I'm not picky on how I achieve that goal (I suspect some black-magic pointer trickery will be the solution). Thank you for the input.
Your error message mentions the word "template", indicating it's not about constructor arguments (initializer), but about generic type arguments (template parameters).
According to https://en.cppreference.com/w/cpp/chrono/zoned_time this class is declared as:
template <
class Duration,
class TimeZonePtr = const std::chrono::time_zone*
> class zoned_time;
So it seems like you need a duration type to use (there is a default for the time zone pointer type). So your line should probably say something like
std::chrono::zoned_time<std::chrono::seconds> tz;

Collect all annotated class name in some scala object

We have various class annotated with a scala macro annotation that add a method to that class. At compile time, We want to add a list of these annotated class in some other object . So that we can access that list at run time. Is there any way to achieve this?
I didn't find a straight way to do this but what I did was pretty simple. Whenever my macro finds my annotated class, It writes the name of the class to a file in resources. At runtime, I made that file content available as a list through a new class method.

How can I load a matlab object of which the class definition file was placed in separate package

Is it possible in matlab to load an object of which the class definition file was placed in separate package?
For example:
T = myTestClass;
save('T');
Now I want to place my class in a package, so I create the directory structure as follows:
+myTestPack/#myTestClass/myTestClass.m
Next I try to recover the saved object:
import myTestPack.*
load('T.mat');
The outcome is always:
Warning: Variable 'T' originally saved as a myTestClass cannot be instantiated as an object and will be read in as a uint32.
Is there any way to solve this problem? I would like to restructure my code but a lot of old data was saved as objects.
Maybe I need to add loadobj/saveobj methods to the definition file or maybe there is a way to rename the class from myTestClass to myTestPack.myTestClass?
Thank you for your suggestions!
You need to add loadobj method to your new class. You also need a simple class myTestClass in the old location with just a loadobj method which calls loadobj method of the moved class. MATLAB does not know that you have moved the class. When loading all it knows is that it is of class type myTestClass and tries to create one by looking up myTestClass.

Intersystems caché - programmatically create new class

Is it possible to write ObjectScript method, which will create new class in namespace and compile it? I mean programmatically create new class and store it. If so, can I edit this class using ObjectScript later(and recompile)?
Reason: I have class structure defined in string variable and I need to add new class to namespace according this string.
Nothing is impossible. Everything in Caché can be created programmatically. And, Classes is not a execution. There are at least two ways to do it:
simple SQL Query CREATE TABLE, will create a class.
and as you already mentioned ObjectScript Code, which can do this.
All of definition of any classes defined in other classes. Which you can find in package %Dictionary.
The class itself defined in %Dictionary.ClassDefinition. Which have some properties, for defining any parts of classes. So, this is a simple code which create some class, with one property.
set clsDef=##class(%Dictionary.ClassDefinition).%New()
set clsDef.Name="package.classname"
set clsDef.Super="%Persistent"
set propDef=##class(%Dictionary.PropertyDefinition).%New()
set propDef.Name="SomeProperty"
set propDef.Type="%String"
do clsDef.Properties.Insert(propDef)
do clsDef.%Save()
And in latest versions, there is one more way for create/change class. If you have text of class as you can see it in Studio. Then, you can load it in Caché, with class %Compiler.UDL.TextServices
Yes, it is. You likely want to make use of %Dictionary.ClassDefinition and the related %Dictionary.*Definition classes (especially %Dictionary.PropertyDefinition, %Dictionary.MethodDefinition and %Dictionary.IndexDefinition) to create and/or modify your class. Provided your string contains some reasonable representation of the data, you should be able to create the class this way.
The actual class documentation is available at http://docs.intersystems.com/cache20141/csp/documatic/%25CSP.Documatic.cls?CLASSNAME=%25Dictionary.ClassDefinition
You can then compile the class by calling $system.OBJ.Compile("YourPackage.YourClass","ck").
(Note: If your string contains the exported XML definition of the class, you could also write the XML representation to a stream and then call $system.OBJ.LoadStream() to import the XML definition. I would only recommend this if you have an exported class definition to start with.)

Adding a method to a class that is from a referenced library (JUNG)

I want to add a method to the Graph class of the JUNG library using Eclipse. How would I do this?
I have the JUNG working correctly as a reference library by following this answer: https://stackoverflow.com/a/5618076/1949665
1) You have access to the source:
Simply add your method
2) You could extend the class and add the method in our extending class
3) Write a Util class with a static method implementing your method than simply uses the original class.
Your comment above implies that you want to be able to find cliques in a graph. (I didn't see the original question before you edited it.)
If so, it doesn't need to be a method on Graph itself, it just needs to accept a Graph as an argument. Graph is a type like List or Map, it should not have a method for every kind of algorithm you might want to use on a graph.