示例#1
0
// ---------------------------------------------------------------
// ConfigurePrinter
//
// Handles calling the printer addon's add_printer function.
//
// Parameters:
//    driverName - the name of the printer driver add-on
//    printerName - the name of the printer spool folder
//
// Returns:
//    B_OK if successful or errorcode otherwise.
// ---------------------------------------------------------------
status_t
Printer::ConfigurePrinter(const char* driverName,
	const char* printerName)
{
	PrintAddOnServer addOn(driverName);
	return addOn.AddPrinter(printerName);
}
示例#2
0
_String*        _CString::DecompressLZW (void)
{
    _String* theAlphabet = SelectAlpha (this->compressionType);


    if (!sLength||(!IsFlag( LZWCOMPRESSION))) {
        return nil;    //nothing to do!
    }
    _List theTable;

    _String output(storageIncrement,true), testString;
    long codeMax = 0, oldCode;

    // init the table

    for (long j = 0; j<(*theAlphabet).sLength; j++) {
        _String a((*theAlphabet)[j]);
        theTable&&(&a);
    }

    long p = 0;

    oldCode = GetNextCode(*this,p);
//  output = output&*  (_String*)theTable(oldCode);
    output <<  (_String*)theTable(oldCode);

    for (; p<sLength-1;) {
        codeMax=GetNextCode(*this,p);
        if (theTable.countitems()-1>=codeMax) {
            output << (_String*)theTable(codeMax);
//          output = output& *(_String*)theTable(codeMax);
            _String addOn((*(_String*)theTable(oldCode)));
            addOn =addOn&*((_String*)theTable(codeMax))[0];
            theTable&& &addOn;
            oldCode = codeMax;
        } else {
            testString =  *(_String*)theTable(oldCode);
            testString = testString&testString.getChar(0);
            theTable&&(&testString);
            output << &testString;
//          output = output & testString;
            oldCode = codeMax;
        }
    }
    output.Finalize();

    // debugging info
//  _String* bs = (_String*)theTable.toStr();
//  printf ("\nString Table:%s\n",bs->getStr());
//  DeleteObject(bs);

    // end debugging

    return (_String*)output.makeDynamic();
}
示例#3
0
// ---------------------------------------------------------------
// PrintSpooledJob
//
// Loads the printer add-on and calls its take_job function with
// the spool file as argument.
//
// Parameters:
//    spoolFile - the path to the spool file.
//
// Returns:
//    B_OK if successful.
// ---------------------------------------------------------------
status_t 
Printer::PrintSpooledJob(const char* spoolFile)
{
	BString driver;
	status_t result = GetDriverName(&driver);
	if (result != B_OK)
		return result;

	PrintAddOnServer addOn(driver.String());
	return addOn.TakeJob(spoolFile, SpoolDir());
}
示例#4
0
// ---------------------------------------------------------------
// GetDefaultSettings
//
// Retrieve the default configuration message from printer add-on
//
// Parameters:
//   settings, output paramter.
//
// Returns:
//    B_OK if successful or errorcode otherwise.
// ---------------------------------------------------------------
status_t 
Printer::GetDefaultSettings(BMessage& settings)
{
	BString driver;
	status_t result = GetDriverName(&driver);
	if (result != B_OK)
		return result;

	PrintAddOnServer addOn(driver.String());
	result = addOn.DefaultSettings(SpoolDir(), &settings);
	if (result == B_OK)
		AddCurrentPrinter(settings);

	return result;
}
示例#5
0
// ---------------------------------------------------------------
// ConfigurePage
//
// Handles calling the printer addon's config_page function.
//
// Parameters:
//    settings - Page settings to display. The contents of this
//               message will be replaced with the new settings
//               if the function returns success.
//
// Returns:
//    B_OK if successful or errorcode otherwise.
// ---------------------------------------------------------------
status_t 
Printer::ConfigurePage(BMessage& settings)
{
	BString driver;
	status_t result = GetDriverName(&driver);
	if (result != B_OK)
		return result;

	PrintAddOnServer addOn(driver.String());
	result = addOn.ConfigPage(SpoolDir(), &settings);
	if (result == B_OK) {
		AddCurrentPrinter(settings);
	}
	return result;
}
示例#6
0
_String*    _CString::DecompressFrequency(void)
{

    _String* theAlphabet = SelectAlpha (compressionType);

    if (!IsFlag(FREQCOMPRESSION)) {
        return nil;    // wrong compression type nothing to do
    }
    unsigned char *codeMaps = new unsigned char [(*theAlphabet).sLength];

    if (!codeMaps) {
        warnError( -108);    // no memory
    }

    unsigned int i,j,k,l,t; // temporary vars


    // read in the alphabet encoding
    i=0;
    t=0;

    for (j=0; j<(*theAlphabet).sLength; j++, i+=5, t = i/8) {
        long leftover = 8-i%8;
        unsigned char value = sData[t];
        if (leftover>=5) {
            switch (leftover) {
            case 5:
                value%=32;
                break;
            case 6:
                value=(value%64)/2;
                break;
            case 7:
                value=(value%128)/4;
                break;
            default:
                value=value/8;
            }

        } else {
            value=((unsigned char) sData[t])%realPowersOf2[leftover]*realPowersOf2[5-leftover];
            value+=((unsigned char) sData[t+1])/realPowersOf2[3+leftover];
        }
        codeMaps[value-1]=j;
    }

    if(i%8) {
        t++;    //possible rounding error
    }

    // now read in the data
    // first we must guess the correct size of the string, but to be safe we'll just set it to
    // the maximum possible value (i.e. if all the bytes compressed to 1 bit)

    _String     result (10,true);

    // k will count the actual length
    // j,l will be used for relative positions of 0's

    for (k=0,j=t*8;; ) { // go by bits
        l=j; // look for the next zero bit in the stream
        while (1) {
            for (i=8-l%8; i>0; i--) {
                if (!(sData[t]&realPowersOf2[i-1])) {
                    break;
                }
            }
            if (i) {
                l+=(8-i)-l%8;
                break;
            }
            if (t<sLength-1)    {
                t++;
            } else {
                l=0;
                break;
            }
            l=t*8;
        }
        if (!l) {
            break;
        }
        l++;
        _String addOn (theAlphabet->getChar(codeMaps[l-j-1]));
        result<<&addOn;
        if ((t=l/8)>=sLength) {
            break;
        }
        j=l;
        k++;
    }
    result.Finalize();
    delete [] codeMaps;
    return (_String*)(_String (result.getStr())).makeDynamic();

}
示例#7
0
文件: testApp.cpp 项目: kojsmn/Vise
/*
 * This is the method that updates the gameBoard if a player is caught in a vise at the end of the turn.
 * You may want to break this method up into several sub-methods.
 *
 * 1) FIRST, identify all pieces that are caught in a vise Note: If you have 0101, then
 *    both the middle 1 and middle 0 are caught in the vice. Use the "inVise" method defined above.
 * 2) NEXT, delete them all from the game (in previous example, you would get 0__1)
 * 3) LAST, find the largest connected component that contains
 *    at least 1 piece from each player. Place all other pieces back in the
 *    storehouse (that is, update pl1spares and pl2spares). If there is a tie, pick the one that has the most pieces from the player
 *    that just played.
 * 3b) If no such component exists, then select the largest
 *    connected component that contains a piece of the player who played
 *    most recently.
 * 3c) If no such component exists, then select the largest connected component.
 * 3d) Tie-breaking: If there is a tie under any of these rules, pick arbitrarily
*/ 
std::pair <int,int> countCluster(hexSpace* target){
	
//	std::cout << target->checked << " " << target->type << std::endl;
	if (target->checked == 1){
		target->checked = 1;
		std::pair <int,int> cluster (0,0);
		return cluster;
	}	
	else if ((target->type == 0)){

		target->checked = 1;
		std::pair <int,int> cluster (0,0);

		return cluster;
	}
	else if (target->checked == 0){
		std::pair <int,int> cluster (0,0);	
		target->checked = 1;
		if (target->type == 1){
			cluster.first = 1;
			cluster.second = 0;
		}
		else if (target->type == 2){
			cluster.first = 0;
			cluster.second = 1;
		}
		std::pair<int,int> addOn (0,0);
		
		addOn=countCluster(target->upleft);
		cluster.first = cluster.first + addOn.first;
		cluster.second = cluster.second + addOn.second;
		
		addOn = countCluster(target->left);
		cluster.first = cluster.first + addOn.first;
		cluster.second = cluster.second + addOn.second;

		addOn=countCluster(target->downleft);
		cluster.first = cluster.first + addOn.first;
		cluster.second = cluster.second + addOn.second;

		addOn=countCluster(target->downright);
		cluster.first = cluster.first + addOn.first;
		cluster.second = cluster.second + addOn.second;

		addOn=countCluster(target->right);
		cluster.first = cluster.first + addOn.first;
		cluster.second = cluster.second + addOn.second;

		addOn=countCluster(target->upright);
		cluster.first = cluster.first + addOn.first;
		cluster.second = cluster.second + addOn.second;
		
			return cluster;
	}
	else {
		std::pair <int,int> cluster (0,0);
		return cluster;
	}
	

}