Verify the effectiveness of this code.

This is a discussion on Verify the effectiveness of this code. within the C++ Programming forums, part of the General Programming Boards category; Ok, well here's a quick run-down of what I'm doing. I am writing a set of classes for a program ...

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    3

    Lightbulb Verify the effectiveness of this code.

    Ok, well here's a quick run-down of what I'm doing. I am writing a set of classes for a program that will interface with the TCPLink feature in Unreal Engine. Unreal doesn't have support for file i/o or saving. Another reason is want to stick to the client-server model that unreal follows. Some of my classmates and I are developing a singleplayer video game, but we may have a cloud server for scores, weapons/equipment, etc.

    Anyways I'm getting off topic. I'm in the most basic stage of creating the I/O portion of the program and I was wondering about your thoughts on the code I have so far. I want to know if it's effective and if it's efficient. I plan change the i/o operations to binary later. This class is going to be much more extensive and it's going to "do work" alongside a socket/networking class for connecting with sockets on the user's machine, and possibly some win32 api. This is an important piece to our game because it will handle passing profile and weapon data back and forth from unreal in-between loading so I have to be as cautious as possible. That's why I came here .
    Code:
    #pragma once
    #include <iostream>
    #include <fstream>
    
    class SOCKETIO {
    public:
    SOCKETIO();
    SOCKETIO(wchar_t const * pArg);
    ~SOCKETIO();
    private:
        std::ofstream * oFile;
    };

    Code:
    #include "SocketIO.h"
    
    SOCKETIO::SOCKETIO(){
    
    	try{
    		SOCKETIO::oFile = new std::ofstream;
    	}
    	catch(...){
    		std::cout<<"Error: 0002\n"<<"------"<<std::endl;
    		std::cout<<"Could not allocate memory to open file."<<std::endl;
    		std::cout<<"ErrModerate"<<std::endl;
    		std::cout<<"------"<<std::endl;
    	}
    
    	SOCKETIO::oFile->open("wepset.txt");
    	if(!SOCKETIO::oFile->is_open()){
    	std::cout<<"Error: 0001\n"<<"------"<<std::endl;
    	std::cout<<"Could not open specified file. Either the file exists and is read only, "
                    "or this program does not have permission to read/write to this directory..."<<std::endl;
    	std::cout<<"ErrMinor"<<std::endl;
    	std::cout<<"------"<<std::endl;
    	}
    }
    
    SOCKETIO::SOCKETIO(wchar_t const * pArg){
    	try{
    		SOCKETIO::oFile = new std::ofstream;
    	}
    	catch(...){
    		std::cout<<"Error: 0002\n"<<"------"<<std::endl;
    		std::cout<<"Could not allocate memory to open file."<<std::endl;
    		std::cout<<"ErrModerate"<<std::endl;
    		std::cout<<"------"<<std::endl;
    	}
    	SOCKETIO::oFile->open(pArg);
    	if(!SOCKETIO::oFile->is_open()){
    	std::cout<<"Error: 0001\n"<<"------"<<std::endl;
    	std::cout<<"Could not open specified file. Either file exists and is read only, "
                "or this program does not have permission to read/write to this directory..."<<std::endl;
    	std::cout<<"------"<<std::endl;
    	}
    }
    
    SOCKETIO::~SOCKETIO(){
    	try{
    		delete oFile;
    	}
    	catch(...){
    		std::cout<<"Error: 0003\n"<<"------"<<std::endl;
    		std::cout<<"Memory from file write could not be freed. Memory leak!"<<std::endl;
    		std::cout<<"ErrMajor"<<std::endl;
    		std::cout<<"------"<<std::endl;
    	}
    }
    Last edited by Salem; 10-11-2010 at 02:08 AM. Reason: Folding

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Proposal: Code colouring
    By Perspective in forum A Brief History of Cprogramming.com
    Replies: 28
    Last Post: 05-14-2007, 07:23 AM
  2. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 10:20 AM
  3. Preludes: verify int code
    By RyeDunn in forum C++ Programming
    Replies: 2
    Last Post: 07-03-2002, 01:54 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 05:05 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21