コード例 #1
0
// return a list of dependencies with name:version string for missing/different version mods.
LinkedList<CharString> APIMod::getMissingDependencies(LinkedList<APIMod*> othermods){
    LinkedList<CharString> strs;
    LinkedListIterator<CharString> depstrs = dependencyversions.getIterator();
    
    while(depstrs.hasNext()){
        CharString depstr = depstrs.next();
        if(depstr.contains(":")){
            LinkedListIterator<APIMod*> modit = othermods.getIterator();
            bool identified = false;
            while(modit.hasNext()){
                APIMod *mod = modit.next();
                // compare direct
                if(unixname.compare(mod->unixname) && version.compareVersion(mod->versionstr)){
                    // not the same or and older version
                    identified = true; // same
                    break;
                }
            }
            
            if(!identified){
                strs.add(depstr); // "mod:version"
            }
            
        } // else invalid!
    }
    
    return strs;
}
コード例 #2
0
MSGClient* MSGServer::getMSGClient(SockClient* cli){
    MSGClient* client = 0x0;
    
    LinkedList<MSGClient*> activeClients;
    
    refreshClients();
    
    // loop through clients
    LinkedListIterator<MSGClient*> msgcit = cclients.getIterator();
    while(msgcit.hasNext()){
        MSGClient* c = msgcit.next();
        if(c->hasBroadcastClient(cli)) // has a serverclient socket?
            client = c;
    }
    
    // found client? If not, add to list if it's alive.
    if(client == 0x0 && cli != 0x0){
        if(cli->alive){
            client = new MSGClient(cli);
            activeClients.add(client);
        }
    }
    
    cclients.clear(); // clear old one
    cclients = activeClients;
    
    return client;
}
コード例 #3
0
// figure out what mods have good dependencies
bool APIMod::compareModDependencies(LinkedList<APIMod*> othermods){
    LinkedListIterator<CharString> depstrs = dependencyversions.getIterator();
    
    while(depstrs.hasNext()){
        CharString depstr = depstrs.next();
        if(depstr.contains(":")){
            LinkedListIterator<APIMod*> modit = othermods.getIterator();
            while(modit.hasNext()){
                APIMod *mod = modit.next();
                // compare direct
                if(! version.compareVersion(mod->version)){
                    // not the same or and older version
                    return false;
                }
            }
            
        } // else invalid!
    }
}
コード例 #4
0
// get channel
MSGClientChannel* MSGServer::getMSGChannel(CharString channelname){
    // loop through channels
    LinkedListIterator<MSGClientChannel*> msgcit = channels.getIterator();
    while(msgcit.hasNext()){
        MSGClientChannel* channel = msgcit.next();
        if(channel->channelname.compare(channelname)){
            return channel;
        }
    }
    
    // no channel by that name
    return 0x0;
}
コード例 #5
0
// only in-between broadcast servers
void MSGServer::shareClientIPID(MSGClient* client){
    LinkedListIterator<MSGClient*> bit = bservers.getIterator();
    SockClient* sc = client->getFirstBroadcastServer();
    CharString msgpack = "newid:";
    msgpack += sc->getAddr();
    msgpack += ":";
    msgpack += client->identity;
    
    while(bit.hasNext()){
        MSGClient* bserver = bit.next();
        if(!bserver->isbserver) continue;
        
        SockClient* bsc = bserver->getFirstBroadcastServer();
        if(bsc != 0x0){
            bsc->sendc(msgpack);
        }
    }
}
コード例 #6
0
MSGClient* MSGServer::getMSGClient(CharString identity){ // get from id
    refreshClients();
    
    // loop through clients
    LinkedListIterator<MSGClient*> msgcit = cclients.getIterator();
    while(msgcit.hasNext()){
        MSGClient* c = msgcit.next();
        
        // is an actual client?
        if(c != 0x0){
            if(c->identity.compare(identity)){
                return c;
            }
        }
    }
    
    // none!
    return 0x0;
}
コード例 #7
0
void MSGServer::refreshClients(){
    MSGClient* client = 0x0;
    
    LinkedList<MSGClient*> activeClients;
    
    // loop through clients
    LinkedListIterator<MSGClient*> msgcit = cclients.getIterator();
    while(msgcit.hasNext()){
        MSGClient* c = msgcit.next();
        
        // is an actual client?
        if(c != 0x0){
            if(c->checkBroadcastAlive()){ // quick check
                activeClients.add(c);
            }
        }
    }
    
    cclients.clear(); // clear old one
    cclients = activeClients;
}
コード例 #8
0
// LinkedList<LinkedList<CharString>> lines = SimpleParseFile(file, '\n');
void APIMod::loadProperties(){ // , CharString name, CharString language, CharString version
    if(propertiesloaded) return;

    LinkedList<LinkedList<CharString>> lines = SimpleParseString(getModFileData("mod.properties"), '=');

    CharString depvers = "";
    LinkedListIterator<LinkedList<CharString>> lineit = lines.getIterator();
    while(lineit.hasNext()){
        LinkedList<CharString> p = lineit.next();
        CharString pname = p[0];
        if(pname.compare(CharString("name")))
            this->name = p[1];
        else if(pname.compare(CharString("unixname")))
            this->unixname = p[1];
        else if(pname.compare(CharString("language"))) // c++, java, etc.
            this->language = p[1];
        else if(pname.compare(CharString("version"))){
            this->versionstr = p[1];
            this->version = APIModVersion(p[1]);
        }else if(pname.compare(CharString("dependency_versions")))
            depvers = p[1];
    }

    this->modcwdloc = unixname; // relative folder location for mod
    
    // load dependency versioning information
    //      this->dependencyversions.add("mod1:v12938");
    if(depvers.getSize() > 3){
        if(depvers.contains(", ")){
            depvers.replace(" ", "");
            LinkedList<CharString> v = depvers.split(",");
            this->dependencyversions.addAll(v);
        }else{
            this->dependencyversions.add(depvers);
        }
    }


    propertiesloaded=true;
}
コード例 #9
0
ファイル: Data.cpp プロジェクト: nbgraham/Data_Structures
void Data::changeDataFromFile(string inputFileName, char type)
{
	cout << "Loading";

	ostringstream rslt;
	ifstream inputData;
	inputData.open(inputFileName);

	if (!inputData)
	{
		throw exception("File could not be read.");
	}

	if (type != 'M' && type != 'P' && type != 'A')
	{
		throw exception("Invalid type: " + type);
	}

	string line;
	//Read the header line, but do nothing with it
	getline(inputData, line);

	//Declare necessary data
	Exosystem* currentSystem;
	Exoplanet* currentPlanet = nullptr;
	string starName;
	char planetName;
	int numberOfPlanets;
	double msini, a, per, ecc, om, t0, k;
	bool hasSingleStar;
	string message;
	bool hasAllInfo;

	//Step through each line in the data file until there are no more lines
	int lineNumber = 1;
	while (getline(inputData, line))
	{
		if (lineNumber % 25 == 0) cout << ".";
		lineNumber++;

		//Break line up into an array on commas
		int startIndex = 0;
		int endIndex = 0;
		int count = 0;
		string info[10];
		for (unsigned int i = 0; i < line.length(); i++)
		{
			if (line[i] == ',')
			{
				endIndex = i;
				info[count] = line.substr(startIndex, endIndex - startIndex);
				count++;
				//skip comma
				startIndex = i + 1;
			}
		}
		//Get the section from the last comma to the end
		info[count] = line.substr(startIndex, line.length() - startIndex);

		//Data validation
		hasAllInfo = true;
		if (count < 9)
		{
			hasAllInfo = false;
		}
		if (info[0].at(info[0].length() - 2) != ' ')
		{
			hasAllInfo = false;
		}
		for (int i = 0; i <= count; i++)
		{
			if (info[i].length() < 1)
			{
				//A field is blank
				hasAllInfo = false;
			}
		}

		starName = info[0].substr(0, info[0].length() - 2);

		//Exosystem info
		if (type == 'P')
		{
			currentSystem = new Exosystem(starName, 0, true);
		}
		else if (hasAllInfo)
		{
			hasSingleStar = info[9] == "0";
			numberOfPlanets = stoi(info[1]);
			currentSystem = new Exosystem(starName, numberOfPlanets, hasSingleStar);
		}
		else
		{
			rslt << "Line " << lineNumber << ": planet did not have all the data and was excluded.\n";
			continue;
		}

		if (starName == "Kepler-98")
		{
			int x = 4;
		}

		ExosystemP* match = exosystems->search(ExosystemP(currentSystem));
		if (match == nullptr)
		{//No match in system
			if (type == 'P')
			{
				rslt << "Line " << lineNumber << ": no such system named " + starName + " in data\n";
				continue;
			}
			else
			{
				currentSystem = (*exosystems->add(ExosystemP(currentSystem))).ptr;
			}
		}
		else
		{
			currentSystem = (*match).ptr;
		}

		//Exoplanet info
		if (hasAllInfo)
		{
			msini = stod(info[2]);
			a = stod(info[3]);
			per = stod(info[4]);
			ecc = stod(info[5]);
			om = stod(info[6]);
			t0 = stod(info[7]);
			k = stod(info[8]);
		}

		planetName = info[0].at(info[0].length() - 1);

		currentPlanet = new Exoplanet(planetName, msini, a, per, ecc, om, t0, k, currentSystem, starName);

		if (type == 'P')
		{
			numberOfReadPlanets -= currentSystem->getPlanets().size();
			exosystems->remove(ExosystemP(currentSystem));
		}
		else
		{
			dbg "Adding planet "; dbg currentPlanet->getName(); dbg " to system "; dbg currentSystem->getStarName(); dbg "\n";
			try
			{
				merge(currentSystem, currentPlanet);
				numberOfReadPlanets++;
			}
			catch (ExosystemPlanetNameNotUniqueException e)
			{
				rslt << "Planet name " << currentPlanet->getName() << " not unique within " << currentSystem->getStarName() << "\n";
			}
			catch (ExosystemTooManyPlanetsException e)
			{
				rslt << "Too many planets in exosystem " << currentSystem->getStarName() << "\n";
			}
		}
	}
	
	inputData.close();

	//output any information messages
	cout << "\n" << rslt.str();
	
	if (planets != nullptr)
		delete planets;
	planets = new Array<Exoplanet*>(numberOfReadPlanets);
	if (hashTable != nullptr)
		delete hashTable;
	dbg "Creating new hash table of size "; dbg numberOfReadPlanets; dbg "\n";
	hashTable = new ExoplanetLHT(numberOfReadPlanets);
	
	AVLTreeIterator<ExosystemP> sysIt(exosystems);
	LinkedListIterator<Exoplanet> planIt;
	LinkedList<Exoplanet>* systemPlanets;
	Exoplanet* curr;
	while (sysIt.hasNext())
	{
		dbg "Adding planets to hash table and array: ";
		systemPlanets = new LinkedList<Exoplanet>(sysIt.getNext().ptr->getPlanets());
		planIt = LinkedListIterator<Exoplanet>(systemPlanets);
		while (planIt.hasNext())
		{
			curr = planIt.getNext();
			dbg curr->getFullName(); dbg ", ";
			planets->add(curr);
			hashTable->add(curr);
		}
		dbg "\n";
	}
}
コード例 #10
0
 // add items from another list
 void addAll(LinkedList<T> cc) {
     LinkedListIterator<T> it = cc.getIterator();
     while(it.hasNext())
         add(it.next());
 }