w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
C++ inheritance design
You could wrap your two data providers in a third one that will redirect depending on the exchange. This way from the point of view of the folio all is abstract, it does not know the data source, and if later you decide to change the way you fetch data you won't have to update the Portfolio class. Here is the idea: class DAO { private: YahooDAO* yahoo, RetirementDAO* retirement; public: DAO() { yahoo = new YahooDAO(); retirement = new RetirementDAO(); } public: std::List<Data> getData(EquityHistory* equity) { std::List<Data> data; if (equity->exchange = "some exchange") { data = yahoo->getData(equity); } else if (equity->exchange = "another exchange") {

Categories : C++

Entity design and inheritance
How about Decorator design pattern: http://en.wikipedia.org/wiki/Decorator_pattern It allows to extend class hierarchy with some new behaviour without duplicating this whole hierarchy every time. Also it adds benefit of extending behaviour in runtime (not only at compile time).

Categories : C#

need design help using private inheritance
not sure what you are trying to achieve but if you want to expose the interface and use the library implementation, can you do something like this: class ADMessageResATR : public IADMessageRes, private iso7816::APDUResponse { public: int sw1() const {return iso7816::APDUResponse::sw1();} ... };

Categories : C++

Javascript way to design inheritance + privacy
I personally disagree with most things in that book and find them very poorly argumented. If not that, most of them are utterly irrelevant due to strict mode and modern tools like jshint. But I guess that is just a problem with how outdated the book is, since these were not available at the time. The language's object model was extended in 2009 with plenty of new features and methods which made the difference between variables and properties even larger. If it was possible 10 years ago to pretend variables are properties, it certainly is not now. The communicate that something is not part of published API, an underscore prefix is used like: this._age = 5; this._method(); This might have a special meaning to modern IDEs but it doesn't have any special meaning to reflective methods in t

Categories : Javascript

C++ Multiple Inheritance Design Issue
I am afraid you are mixing things here. As you noted there are many different kinds of behaviors 1: walking behavior talking behavior fighting behavior ... And of course it makes no sense to have a WalkingBehavior compare to a FightingBehavior so it makes no sense to have them share a base class either. As such, I think that you should just use Actors and provide methods to retrieve the behaviors on those: class Actor { public: virtual WalkingBehavior const& walkingBehavior() const { return DefaultWalkingBehavior; } virtual FightingBehavior const& fightingBehavior() const { return DefaultFightingBehavior; } // ... }; // class Actor Where the default behavior is defined in such a way that it can interact with a more regular behavior of i

Categories : C++

C++ Inheritance/Class Design Issue
Thanks to the excellent discussion in the comments, here's a proposed solution that I am considering implementing that just hit me while I was in the shower (as an aside, anyone else find that the best thinking is done in the shower?): namespace packets { ParseHeader(...); ParseData(...); ParseCheckSum(...); class GenericPacket { // same stuff as before, except the scope of the "protected" functions... }; class HighlySpecificPacket { // same stuff as before... // new stuff: public: // will probably have to add wrappers here to expose // some GenericPacket member variables... private: GenericPacket packet; // composition for all the necessary member variables I think this is a good way to expose only the things I want to the client, except for the fact that I now have

Categories : C++

Inheritance and special types in Database design
If you're building a relational database, you should have an Item table; "sub-classes" of items would have their own table, with their primary key also a foreign key to Item, thus creating 1:(0/1) relationships: Item ---- ItemId (PK) Price Title LawnMower --------- ItemId (PK, FK to Item) Manufacturer Warranty etc.

Categories : Database

a class inheritance hierarchy design issue
Maybe this ? typedef vector<int> ArrayI; typedef vector<Array<long>> Mat2DB; typedef vector<ArrayI> adjList; class baseGraph { int nodes; ArrayI degree; virtual void sssp(int node); //some member functions. } class labeledGraph: public virtual baseGraph { ArrayI labels; virtual void setLabel(const ArratI &); //member functions. } class matGraph: public virtual baseGraph { Mat2DB matrix; //member functions. } class lMatGraph: public virtual matGraph, public virtual labeledGraph { //member functions. } class listGraph: public virtual baseGraph { adjList list; //member functions. } class lListGraph: public virtual listGraph, public virtual labeledGraph { //member functions. } I'm assuming here that you in

Categories : C++

Language design: default method parameters inheritance
The issue is actually the use of magic numbers. If you remove the magic numbers, the problem is resolved nicely. enum DefaultA { DefaultA_v2 = 0, DefaultA_v3 = 1 }; void a(int v1, int v2=DefaultA_v2, int v3=DefaultA_v3); void b(int m1, int m2, int v1, int v2=DefaultA_v2, int v3=DefaultA_v3) { // ... a(v1, v2, v3); // ... }

Categories : C++

design pattern / multiple inheritance workaround java
Do you really need to subclass or do you just want code re-use? Sounds like you use the Composite and possibly Strategy Patterns: Your Class C will have fields of type A and possibly B and delegate calls to them where appropriate. This gives you all the advantages of code re-use without the messiness of inheritance (single or multi)

Categories : Java

Memory managing container design issue - items require inheritance
First thing to say: I'm not very fond of C++11, so there could be some syntax error in the code I wrote, but it's the logic that matters. If I understood your question, you just want to be able to asynchronously add and delete items from a container, without those knowing of their state. In this scenario you can use a std::map< std::unique_ptr< Elem >, bool > to handle the state of items: true = alive, false = dead. MemoryManager class fields: std::vector< T * > m_toAdd, a vector with not yet added items; std::map< std::unique_ptr< T >, bool > m_items, a map with every item managed and a bool flag methods: add(), which adds a new item in the m_toAdd vector; del(), which marks an item to be removed in m_items using its flag; refresh(), which removes de

Categories : C++

TCP server written in Java client written in C receive error (encoding)
TCP socket streams are byte based. This is why an encoding is used to convert chars to bytes when you read/write. It appears the main method readString() is missing, but I assume you have specified the enocding the C program is using or assumed the default encoding is ok.

Categories : Java

how to link program written in two separate files with the main written in another file
I don't see how codeblocks fails to associate them. Anyway you can always do it manually ... g++ -g -o main.exe main.cpp linkedlist.cpp Make sure: main.cpp linkedlist.cpp and linkedlist.h exist in your project. If not select your project and then click Add existing file. Check if linkedlist.h is in the same folder as main.cpp if not you'll need to include it like this #include "subfolder/main.cpp"

Categories : C++

How are files written? Why do I not see my data written immediately?
Research buffering and caching. There are a number of layers of optimisation performed by: your application, your OS, and your disk driver, in order to extend the life of your disk and increase performance. With the careful use of flushing commands, you can generally make things happen "quite quickly" when you really need them to, though you should generally do so sparingly. Flushing can be particularly useful when debugging. The GNU C Library documentation has a good page on the subject of file flushing, listing functions such as fflush which may do what you want.

Categories : C

Expression Tokenizer
This statements overwrites the lexeme on each execution lexeme = Character.toString(expression.charAt(i)); it should be lexeme += Character.toString(expression.charAt(i)); i.e. after identifying a single digit, add it to the lexeme. Besides of that, your getToken method is not correct then by passing i to it you assume that a lexeme is only one character long, in fact it can be 1 or more, for example 66 or 2.5. so you need to redesign your Tokenizer class. You should init the Tokenizer object with the expression then have it have a parameter-less method getNextToken() which makes as many iterations as needed to identify a token and then returns it. It also should have a method to check whether is there any input left, something like hasMoreTokens(). Here is something you can buil

Categories : Java

elasticsearch tokenizer setting
Your startObject() / endObject() don't seem to correspond to the JSON version you posted. I think a endObject() is missing before the .startObject("tokenizer"). I would do something like : client.admin().indices().prepareCreate("test") .setSettings(ImmutableSettings.settingsBuilder().loadFromSource(jsonBuilder() .startObject() .startObject("analysis") .startObject("analyzer") .startObject("my_ngram_analyzer") .field("tokenizer", "my_ngram_tokenizer") .endObject() .endObject() .startObject("tokenizer") .field("type", "nGram") .field("min_gram", "2") .field("max_gram","3")

Categories : Java

How to have ngram tokenizer in lucene 4.0?
Probably the simplest way to use NGramTokenizer is with this constructor the just takes a reader, and min and max gram size. You can incorporate it into an analyzer, similar to the example on the Analyzer docs. Something like: Analyzer analyzer = new Analyzer() { @Override protected TokenStreamComponents createComponents(String fieldName, Reader reader) { Tokenizer source = new NGramTokenizer(reader, 12, 12); TokenStream filter = new LowercaseFilter(source); return new TokenStreamComponents(source, filter); } };

Categories : Java

A custom tokenizer for Java
A few comments up front: From StringTokenizer javadoc: StringTokenizer is a legacy class that is retained for compatibility reasons although its use is discouraged in new code. It is recommended that anyone seeking this functionality use the split method of String or the java.util.regex package instead. Always use Google first - the first result as of now is JTopas. I did not use it, but it looks it could work for this As for regex, it really depends on your requirements. Given the above, this might work: import java.util.regex.Matcher; import java.util.regex.Pattern; public class Mkt { public static void main(String[] args) { Pattern p = Pattern.compile("([$\d.,]+)|([\w\d!$]+)"); String str = "--- FREE!! $50 192.168.1.1 $24,500"; System.out.println("input

Categories : Java

I need to get a substring from a java string Tokenizer
You could use String.split() as String[] products = "Pizza-1*Nutella-20*Chicken-65*".split("\*"); for (String product : products) { String[] prodNameCount = product.split("\-"); System.out.println(prodNameCount[0] + " " + prodNameCount[1]); } Output Pizza 1 Nutella 20 Chicken 65

Categories : Java

Get return values of code with tokenizer
Perhaps this might help. Though I curious to know what you are ultimately trying to do. $tokens = token_get_all($str); $returnCode = ''; $returnCodes = array(); foreach ($tokens as $token) { // If return statement start collecting code. if (is_array($tokens) && $token['0'] == T_RETURN) { $returnCode .= $token[1]; continue; } // if we started collecting code keep collecting. if (!empty($returnCode)) { // if we get to a semi-colon stop collecting code if ($token === ';') { $returnCodes[] = substr($returnCode, 6); $returnCode = ''; } else { $returnCode .= isset($token[1]) ? $token[1] : $token; } } }

Categories : PHP

String Tokenizer.nextElement for JComboBox
You seem to have left out the relevant portions of your code, i.e. how you are handling setting/getting items in the JComboBox. Whether you read these values from a database, a file or have them hardcoded is irrelevant to the question. Since you do ask whether it is the same as with a JTextField, I can at least answer this; it is not the same. The question indicates that you're quite new to Swing. You would probably benefit from working through a basic Swing tutorial, just to get a grip on how to work with these basic GUI elements. For JComboBox, check out Oracles own How to Use Combo Boxes. Anyways, when working with JComboBox, you will need to first populate it with the values that users can choose from and set the currently selected value. Retrieving the currently selected value is ju

Categories : Java

where is Chinese tokenizer in SQLite FTS3?
In Android, it is not possible to add user-defined tokenizers. So you have to live with the restrictions of the built-in tokenizer (any sequence of glyphs without space characters is treated as a single term).

Categories : Sqlite

Postgresql full text search tokenizer
Problem solved. The reason is database was initiated with default ("C") CType and Collate. We used initdb --locale=UTF-8 --lc-collate=UTF-8 --encoding=UTF-8 -U pgsql *PGSQL DATA DIR* to recreate instance and CREATE DATABASE "scratch" WITH OWNER "postgres" ENCODING 'UTF8' LC_COLLATE = 'ru_RU.UTF-8' LC_CTYPE = 'ru_RU.UTF-8'; to recreate db and simple dictionary now works.

Categories : Postgresql

Is there a c++ library that implements a streamy kind of tokenizer?
Yes, it's called "the standard library." What you're asking for seems to fall within the range that streams can handle pretty easily. std::stringstream d; d << "tok"; d << "1 t"; d << "ok2 tok3"; std::vector<std::string> tokens((std::istream_iterator<std::string>(d)), std::istream_iterator<std::string>()); for (std::string s : tokens) std::cout << s << " "; Result: tok1 tok2 tok3 I haven't shown a "get the rest" function here. I suppose istream::read would probably be the obvious choice. I suppose I should add: by default, strings will be broken at anything the stream interprets as white-space, not just the space character. You can change what it interprets as white-space by writing a custom cty

Categories : C++

Point Cloud Library's multiple-inheritance with single inheritance restriction
Going the external executable route. I can save the point cloud to the pcd format from the application, run the executable to load and process the file to output the results in obj format for the application to use. It is still a horrid solution but at least it works.

Categories : C++

SOLR tokenizer to store whole word as Lower case
You can use the KeywordTokenizerFactory tokenizer along with the LowerCaseFilterFactory field descriptor. For more details have a look here

Categories : Solr

EF 5 Mixed Inheritance Types with Multi Layer Inheritance
Something like this public abstract class Root { [Key] public int RootId { get; set; } public string RootProperty { get; set; } } public class ChildA : Root { [Required] int RootId ForeignKey["RootId"] public Root Root {get;set;} public string ChildAProperty { get; set; } } public class ChildB : Root { [Required] int RootId ForeignKey["RootId"] public Root Root {get;set;} public string ChildBProperty { get; set; } } public class SubChildAa : ChildA { public string SubChildAaProperty { get; set; } } public class SubChildAb : ChildA { public string SubChildAbProperty { get; set; } } In your context you want TPT for ChildA and ChildB So public DbSet<ChildA> ChildAas { get; set; } public DbSet<ChildB> ChildBs { get; set;

Categories : C#

Difference in VTBL in single inheritance and multiple inheritance
If you have to base class A and B of your multiply inherited object D, these have their own vtable layout and D needs to provide vtables which match the vtables of both A and B. Further, if another class derives from D and possibly from another similarly multiple inherited class, the same thing happens again, i.e., there are multiple vtables needed. They can't just simply be merged. As a result, multiply inherited objects typically have multiple vtables around and the compiler inserts code to first determine the function's correct vtable and then call it. I think the code determining the correct vtable based on a pointer to an object with multiple bases is just a simple addition or subtraction if the virtual function is not in a virtual base class and a look-up of the location of the virtu

Categories : C++

How Add and delete the Contact Bubbles properly in multiautocompletetextview with space tokenizer like gmail to field in android
I open-sourced our solution TokenAutoComplete on github. Mine has been tested back to 2.2. I designed my code to allow pretty simple implementations and customizations. I'm not sure if this quite answers your question, but it might be a better starting point than the chips source code. Here's an example implementation using my library: Subclass TokenCompleteTextView public class ContactsCompletionView extends TokenCompleteTextView { public ContactsCompletionView(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected View getViewForObject(Object object) { Person p = (Person)object; LayoutInflater l = (LayoutInflater)getContext().getSystemService(Activity.LAYOUT_INFLATER_SERVICE); LinearLayout view = (LinearLay

Categories : Android

while using Ngram Tokenizer and Ngram Filters index Size will increase in ElasticSearch?
Yes, using (edge) ngram tokenizers or filters will increase the index size - you're storing more tokens, after all. As a couple of side notes, min_gram set to 1 may allow you to perform autocomplete operations on the first keystroke, but unless your dataset is small you're unlikely to provide a narrow enough resultset to the user to be useful. min_gram set to 2 or 3 is a better balance for larger datasets and performance. max_gram set to 50 has a similar problem but at the other extreme; a user is unlikely to type in that many characters in order to autocomplete anything, so you're indexing ngrams unnecessarily in that case. Of course, these comments are specific to the autocomplete use-case; I'm sure there are many workable scenarios needing 1, 50 for min_gram and max_gram. The ES refe

Categories : Elasticsearch

reading data file into string using string tokenizer
strtok() has unexpected side-effect for OP. After stuPtr->name = strtok(tempString, ";");, the buffer location formerly occupied by the ';' is replaced by a ''. So when sscanf(buffer, "%15s ... is called, unexpected results occur. Recommendation: consider alternatives other than mixing strtok() and 'sscanf()`. One could continue on using sccanf() with sscanf(&buffer[strlen(stuPtr->name)+1], "%15s ... But recommend a sscanf() only solution or a strtok(), strtof().

Categories : Misc

Is it possible to modify a firefox addon written using XUL with an addon written using the Addon SDK
Yes, it is possible to extend other add-ons. There are actually quite a few add-ons that either extend or interact with other add-ons, for example Element Hiding Helper extending Adblock Plus and lots of Firebug add-ons. How to do it depends on the implementation of actual add-on you're trying to extend. Hence, I can only give you some general pointers/notes: You can have XUL overlays to add-on XUL windows/overlays, just like you may have some for browser.xul or other core code. You can, of course, use the DOM APIs as well to manipulate any third party XUL DOM. You can monkey-patch global functions and objects in Javascript and/or replace/wrap most XPCOM components. The Add-on SDK cannot use overlays. Hence you have to use window/utils or similar means to get to the XUL windows and can

Categories : Firefox

Does a Normalized Class Design Lead to a Normalized Database Design
Generated database will depend on your entities mapping. If you are asking about default mapping, which will be used, then generated database could be not normalized. For example, if you have nice inheritance hierarchy by default Entity Framework will use table per hierarchy (TPH) mapping, which enables polymorphism by denormalizing SQL schema. TPH uses discriminator column to store all types from hierarchy in single table. TPH violates third normal form because discriminator column is not part of primary key, but some columns depend on discriminator value.

Categories : Database

SLF 4j Logs are not written to log
I believe you should be using a single shared log 4J configuration and instance for all your adapters if you want to use the the same log file. As is, Log 4j instances are probably competing for the control of the file.

Categories : Java

How was the first C compiler written ?
very interesting question (despite the bullying) The first C compiler wasn't written in C, usually when writing a compiler we use either assembly language, or another programming language, and it's common that after first compilation, the compiler is rewritten in it's native language. There's a lot of programming languages that have been written in C then rewritten in their native language : Java for example, Ada ... Cheers.

Categories : C

Using a DLL written in/for C++ in a C# program
But I'm not sure how to do the rest. For instance, in sio_util.h, there's a function with a return type of HANDLE, another with a return type of DWORD, and I'm not very familiar with these and don't know how to make it work in C#. DWORD is a 32 bit unsigned integer, so you'd use UInt32 (uint) to represent that. A HANDLE is a void*, or any pointer, so you'd typically use IntPtr to represent a HANDLE in C#. The Windows Data Types page lists most of the Windows standard types, which should provide a good starting point on figuring out the P/Invoke types you'd need.

Categories : C#

c# log everything being written in console
Write a method that when you call, it calls both Console.WriteLine() and whatever method you are using to log - then call that method instead of Console.WriteLine() public class Logger { public static void WriteLine(string s) { Console.WriteLine(s); myLogger.WriteLine(s); { }

Categories : C#

Create an DLL written in Ada
The easiest way to create a DLL in ada is to use GNAT project files. You can see the documentation here Your project (called proj_name.gpr or anything else you prefer) file looks like this: library project Proj_Name is for Library_Name use "math"; for Object_Dir use "obj"; for Source_Dirs use ("src"); for Library_Dir use "lib"; for Library_Interface use ("Division"); for Library_Kind use "dynamic"; end Proj_Name; assuming that your sources are in a src directory, that you want object files to be compiled in the obj directory and you want to output the dll in the lib directory. To compile the library you then have to use gnatmake : gnatmake -P ./proj_name.gpr -p (-P says what project file to use, -p says to create any needed directories). On a linux it creats lib/libmath.s

Categories : Gcc

How would it be written using REST?
REST really makes the most sense when what you're doing are resource-based CRUD interactions. You're not really doing that in this case--you can sort of conceptually force it to conform, but I think you'd end up adding unnecessary and unintuitive complexity. I'd say you just don't use REST. Just have an attack action that takes the params and does the rest.

Categories : Ruby On Rails

Inputted value not being written to arrray
The %d format specifier is for ints. For doubles use %lf with scanf and %f or %lf with printf. scanf("%lf", &q); printf("%f", q); // confirms q = "input"

Categories : C



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.